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 access the hero stat. Let me explain. Let are 2 main ways to manipulate/ change a hero stat. First you take into account its position in the active party. This position has to be sure/ predifined.

The other way which is more likely to feet your need is to user the hero's. As explained in the plotscript dictionnary (who) can be both a number or a constant in the form hero: name. Thats why when we add a hero a the party we have 2 ways to write in poltscript 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 its name instead of its position in the party allows us to be more precise. Both has their utilities. Let's see with examples.


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

This way is more like to be usefull 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 heoes.

Let's say you have 4 heroes, and want to restore the HP and MP for all of them. 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 by changing the stat names. However, stats ( HP and MP excepted) can only be change outside of battle with plotscripts, so otherwise they are always set to maximum.

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

Using this script is a good alternative to using 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! (You 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 slot. You need to identify our hro bit his name.

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

  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.

A 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 needs to Searches 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 problems implementing this feel free to ask for help on discord or on the forum of the community.

See also[edit]