Post new topic    
Metal Slime
Send private message
Spells based on items equipped 
 PostSun May 03, 2020 9:36 am
Send private message Reply with quote
Has anyone tried linking individual skills to items equipped? i'm looking to only allow each hero a max 4 skills/attacks based on equipment. eg, you "equip" a fireball item on a hero to allow them to use it in battle, and cant't see the spell if the item isn't equipped.

What would a script to add/remove skills in this manner look like?

Regards
vvight.wordpress.com
Slime Knight
Send private message
 
 PostSun May 03, 2020 10:34 am
Send private message Reply with quote
Use an on-close script for your menu. In this script, you have to input two long lists: One with all the "learnable" spells and one with the equipment-to-spell-relations.

Code:
plotscript,close,begin
# Use it as "On-close script" under "Edit Menus" in Custom. Beware that the commands
#"forget spell" and "teach spell" take the spell number plus 1 as argument.
# So in this example, the spells #36 and #216 are used.
# These spells have to be in the heros spell list as "Learned from an item".
variable (a)
variable (b)
# Erase the whole list of temporary spells for all heros
for (a,0,3,1) do(
  forget spell (a,36 + 1)
  forget spell (a,216 + 1)
)
# Add spells back, if the right item is equipped
for (a,0,3,1) do (     # Loops through all heros in active party
  for (b,1,5,1) do (   # Loop for all equipment slots
    # Item #11 learns spell #36
    if (check equipment (a,b) == 11) then (teach spell (a,36 + 1)) 
    # Item #201 learns spell #216
    if (check equipment (a,b) == 201) then (teach spell (a,216 + 1))
  )
)
end


Although there is one mistake, when using this as the main menus on-close script. It doesn't update the spell lists immediately. So if you change your equipment and have a direct look at the spell list, it's still the old configuration (you would have to close the main menu first).
If the equipment menu would be defined as it's own menu with this as the on-close script, it should work.
Chemical Slime
Send private message
 
 PostSun May 03, 2020 8:30 pm
Send private message Reply with quote
you can already make commands appear conditionally based on a tag in the heroes main battle menu. its really cool! probably
i miss my wife
Metal Slime
Send private message
 
 PostMon May 04, 2020 12:11 am
Send private message Reply with quote
Thanks Bird! I'll look into that script. Might be a bit of work ahead.

Swordplay: I considered that, but then only one hero needs the item equipped for the spell to be usable for all heroes.
vvight.wordpress.com
Metal Slime
Send private message
 
 PostFri May 08, 2020 2:51 am
Send private message Reply with quote
Code:
plotscript,close,begin
# Use it as "On-close script" under "Edit Menus" in Custom. Beware that the commands
#"forget spell" and "teach spell" take the spell number plus 1 as argument.
# So in this example, the spells #36 and #216 are used.
# These spells have to be in the heros spell list as "Learned from an item".
variable (a) #hero num
variable (b) #spell num
variable (c) #equip slot
variable (d) #item num

# Erase the whole list of temporary spells for all heros
for (a, 0, 3, 1) do(
   for (b, 0, 150, 1) do(
      forget spell (a, b + 1)
   )
)

# Add spells back, if the right item is equipped
for (a, 0, 3, 1) do (     # Loops through all heros in active party
   for (c, 1, 5, 1) do (   # Loop for all equipment slots
      for (d, 0, 150, 1) do(
         # Item #d learns spell #b+1
         if (check equipment (a, c) == d) then (teach spell (a, b + 1))
      )
   )
)
end


How does this look? I plan to have items & spells 0-150 reserved for the equippable spells, with the item number and spell number matching up for ease of use.
vvight.wordpress.com
Slime Knight
Send private message
 
 PostFri May 08, 2020 7:47 am
Send private message Reply with quote
Maybe we have to use "hero by slot (a)" instead of "a" to pick the four heros in the active party, but only for the commands "teach spell" and "forget spell", not for "check equipment". I just looked at my scripts and that did work at least.

My computer would get performance issues there, because the triple-for-do has to check 4 x 5 x 150 cases, which results in 3000 cases! Sometimes, these big scripts makes the engine say, that a script is stuck in an infinite loop.

I used the very unelegant way of dividing the script into more parts, which were split by a "wait (1)" to give the old age computer at least some hope, that it is actually finishing something. In that case, 4 x 300 different cases were too much to handle at once. But that was with the 2013 engine.
Code:
variable (a)
variable (b)
for (a,0,3,1) do (
  for (b,0,120,1) do (teach spell (hero by slot (a),b))
  wait (1)
  for (b,121,240,1) do (teach spell (hero by slot (a),b))
  wait (1)
  for (b,241,300,1) do (teach spell (hero by slot (a),b))
  wait (1)
  give experience (a,30)   
)


Does someone else know, if that route is still required with everything up-to-date?
Metal King Slime
Send private message
 
 PostFri May 08, 2020 3:31 pm
Send private message Reply with quote
There is a bug in the script: it does "teach spell (a, b + 1)" but b is not set! I fixed that below.

Hmm. Calling "check equipment" 3000 times is trivial, even on a very old computer. But Bird is right that "teach spell" is a slow command, since it reads (all!) hero data from disk every time. That's something I want to stop doing at some point, along with the many other places where hero data is read from disk. But at least starting from Fufluns loading hero data should be faster than before (however it also got much slower at some point after 2013 when we changed the hero file format).

But that script can be modified so there is no worry about speed, by replacing those two "for" loops with one that only calls teachspell as necessary:

Code:
for (a, 0, 3, 1) do (     # Loops through all heros in active party
   for (b, 0, 150, 1) do(  # Loop through spells/items
      variable (have item)
      have item := false
      for (c, 1, 5, 1) do (   # Loop through all equipment slots
         if (check equipment (a, c) == b) then (have item := true)
      )
      if (have item) then (
         if (knows spell (a, b + 1) == false) then (teach spell (a, b + 1))  # Avoid calling "teach spell"
      ) else (forget spell (a, b + 1))
   )
)
Metal Slime
Send private message
 
 PostFri May 08, 2020 11:36 pm
Send private message Reply with quote
That's way better, thanks TMC
vvight.wordpress.com
Slime Knight
Send private message
 
 PostMon May 11, 2020 12:12 pm
Send private message Reply with quote
TMC wrote:
But at least starting from Fufluns loading hero data should be faster than before (however it also got much slower at some point after 2013 when we changed the hero file format).


I just tested it and can confirm, what you wrote. 250 repeated cases of "get item" or 50 repeated cases of "add hero" for example were a problem too huge for the old engine of 2013, but in the current one it only makes the screen freeze for less than a second. No script hang-ups. Good job there!
Metal King Slime
Send private message
 
 PostTue May 12, 2020 3:00 am
Send private message Reply with quote
You might see "add hero" get slower if you upgrade the .rpg using Custom. game.exe now actually use far more work loading the hero data than before, but won't close and reopen the data files every time you call "get item" or "add hero", so Windows itself is doing much less work, and that's probably what matter most (unless you use Mac or Linux, which are designed for fast re-opening of files).
Metal Slime
Send private message
 
 PostTue May 12, 2020 10:32 pm
Send private message Reply with quote
All working wonderfully!
Now I need a way to run the on close script when the equip menu is closed (or some kind of fancy workaround). Perhaps special script "Menu Action"? Leads me to ask whether on close scripts could be implemented for special screens?

Also, would there be any other places I'd want this script called? eg. add/remove/swap hero, load game, after battle, map autorun.

Cheers.
vvight.wordpress.com
Slime Knight
Send private message
 
 PostWed May 13, 2020 7:55 am
Send private message Reply with quote
Let's change the plan. We don't use that big script as a close on menu script. I renamed everything here.

Code:
plotscript,menuopens,arg,begin
# This script has to be used for the menu as "Run Script" and has to be
# passed an argument, which can be done at "Extra Data", depending
# on, which menu should be opened by this script here.
if (arg == 1) then (equip menu)
if (arg == 2) then (team menu)
temporary spells checking
main menu
end

script,temporary spells checking,begin
# Beware that the commands "forget spell" and "teach spell" take
# the spell number plus 1 as argument. These spells have to be
# in the heros spell list as "Learned from an item".
variable (a) #hero num
variable (b) #spell num
variable (c) #equip slot
variable (d) #item num

# Erase the whole list of temporary spells for all heros
for (a, 0, 3, 1) do(
   for (b, 0, 150, 1) do(
      forget spell (a, b + 1)
   )
)

# Add spells back, if the right item is equipped
for (a, 0, 3, 1) do (     # Loops through all heros in active party
   for (c, 1, 5, 1) do (   # Loop for all equipment slots
      for (d, 0, 150, 1) do(
         # Item #d learns spell #b+1
         if (check equipment (a, c) == d) then (teach spell (a, b + 1))
      )
   )
)
end


Use Run script "menuopens" instead of the equip menu and the team menu for example. Put "Extra data 0" to 1 or 2, as this is the argument that you pass to that script. Look at the script: If the argument is 1, it opens the equip menu. If it is 2, it opens the team menu. Of course there could be more options added here.
Use the bitset "Close menu when activated", as this removes the main menu from the screen. But you surely want the main menu back, when you close the equip or the team menu, right? Therefore the script activates the main menu once again after that. I'd use the bitset "Remember selection when reopening" for the main menu, because it keeps track of what you have chosen last time.
Display posts from previous: