How do I restore my hero's stats during a plotscript?

From OHRRPGCE-Wiki
Jump to navigation Jump to search

Well that's rather easy! We need to use the set hero stat command in combination with the get hero stat command.

You first need to choose how you are going to make your script which access the hero stat. Let me explain. Let are 2 main ways to manipulate/ change a hero stat. To choose the right one, you need to take into account the hero's position in the active party. This position has to be sure/ predefined, or not.

The other way which is more likely to feet your need is to use the hero's constant (= His place in the edit hero menu under custom). As explained in the plotscript dictionary (who) can be both a number or a constant in the form hero: name. Thats why when we add a hero a to the party we have 2 ways to write in plotscript language . Let's see with an example: let's say that we want to add an hero named Pop into a party. Pop occupied slot 4 in the edit menu under custom and his constant in the file is hero: pop

 add hero (4)

or

 add hero (hero: pop)


In the first case, we're using the number corresponding to the slot and in the second the name created in the hsi file exporting constants. Both ways work.

Accessing a hero stats by its name instead of its position in the party allows us to be more precise. Both ways have their utilities. Let's see with examples.


Restore stat by using position in the active party as trigger[edit]

This way is more likely to be useful when you make your own Inn because: that exactly what a INN does: regardless of their names just using party position set hero stat and get hero stat restore the heroes.

Let's say you have 4 heroes, and you want to restore the HP and MP for all of them. Then, you'll put in your plotscript the following lines:

  set hero stat(0,stat:hp, get hero stat(0,stat:hp,maximum stat), current stat)
  set hero stat(0,stat:mp, get hero stat(0,stat:mp,maximum stat), current stat)
  
  set hero stat(1,stat:hp, get hero stat(1,stat:hp,maximum stat), current stat)
  set hero stat(1,stat:mp, get hero stat(1,stat:mp,maximum stat), current stat)   

  set hero stat(2,stat:hp, get hero stat(2,stat:hp,maximum stat), current stat)
  set hero stat(2,stat:mp, get hero stat(2,stat:mp,maximum stat), current stat)  

  set hero stat(3,stat:hp, get hero stat(3,stat:hp,maximum stat), current stat)
  set hero stat(3,stat:mp, get hero stat(3,stat:mp,maximum stat), current stat)   

Please note that the stat names may vary on your RPG file. Check in your hsi file for stat names. If you don't have the hsi file for your game, open in custom and go to Script Management, then select 'export names for scripts'.

Also, you can restore absolutely all your stats this way.However, the other stats can only be change outside of battle with plotscripts. Otherwise they are always set to maximum.

You can also include an if (check tag()) command if you want to restore your stats only in certain situations.

Using this script is a good alternative to making an inn that costs $0 dollars for things like sleeping in a bed, or talking to a friend who can heal you for free.

Feel also free to use these code to create very special inns! (Like an Inn you would pay with items for example)


Restore stat by using a heroe's name as trigger[edit]

Now let's imagine we are in a different situation. We have 3 hero let's say it's a Harry Potter game. So we have 3 heroes Harry, Hermione and Ron. Harry has been attacked and Ron and Hermione joins the party to help him. You have 3 three heroes. You want to heal Harry. You can use position as a basic for trigger because Hermione and Ron can occupy any of the 4 slots. You need to identify Harry by his name.

So to restore Harry's stats we'll have something like this


  #restore Harry Hp & Mp
  set hero stat(find hero (hero:Harry),stat:hp, get hero stat(find hero (hero: Harry), stat:hp,maximum stat), current stat)
  set hero stat(find hero (hero:Harry),stat:mp, get hero stat(find hero (hero: Harry),stat:mp,maximum stat), current stat)

This way we don't have to care about position. If Hermione was in party slot 1 and Ron in party slot 2 and Harry added in party slot 0 the script will work. If Hermione was in party slot 0 and Ron in party slot 1 and Harry added in party slot 3 the script will work.

Another very important thing to remember when we work with names is that we absolutely need to include the find hero command. If we just write

  set hero stat(hero:Harry,stat:hp, get hero stat(hero: Harry, stat:hp,maximum stat), current stat)
  set hero stat(hero:Harry,stat:mp, get hero stat(hero: Harry, stat:mp,maximum stat), current stat)

It won't work. Why? Because hspeak.exe needs to search through your (battle) party to see if the specified hero is there. Find hero does just that. So you need to include it in your code to make it work. As always if you have problems implementing this feel free to ask for help on discord or on the forum of the community.

See also[edit]