Minor Wounds Healing System

So basically i have like a small church with with a nun in the center of the room and i want to set up an event so that the player is given the choice to heal a small amount of hp for free but only if the player has a party member with some damage. If the players party members all have full hp then they cant heal any hp. This is what i have so far but im having trouble figuring out the hp part.
Any help would be appreciated thanks.

eMmEhuZ.png
Unfortunately, there is no built-in way to determine whether a character's HP is at 100%.
It's possible with Event Commands, but quite a hassle, to be honest.

It's simpler and more convenient to use a script instead.
Conditional Branch -> Script -> Enter following code:
Code:
$gameParty._actors.some(function(item) { return $gameActors._data[item].hp < $gameActors._data[item].mhp });

Basically, the code looks if there are any party members whose HP is below MHP (maximum HP).
So if the condition is met, someone needs healing. Else, there's nothing to heal.

This should be far more convenient than creating another Loop, saving the character's MHP inside a new variable, subtracting the character's HP from the MHP, breaking the loop if the variable is not 0, then - outside of the loop - checking if the variable is 0 (nothing to heal) or not.


PS:
You might want to prevent the player from spamming the free minor heal.
Alternatively, you could tweak the code to determine just how wounded your party is and only make the free heal available if the party has 90% or more HP.
I think I would make it like this:

1) Make three variables: One is for Max HP and the second is for Current HP and the third you can call Healing Check. Make an Max HP and Current HP variable for each actor. Now have the Max HP variable check and store the current Max HP for an actor. You'll need to do this with each actor and their variable. You'll need to do the same with the Current Variable, but you use HP instead of Max HP. You can find all this in the variable menu in Game Data.

2) Now you make an conditional branch for each Max HP variable in have it check whether or not the actor's Current HP variable is the same as the Max HP variable. If Current HP is lower then Max HP then you will add 1 to the Healing Check.

3)Now make another conditional branch with whatever you need to do the healing, but this time have it check whether the Healing Check variable is over 1. If it is then the actors get a minor heal, if not then no heal. Make sure to set the Healing Check variable back to 0 and your good to go.

Although personally I would do it off a percentage check of Max HP so players couldn't abuse it, but that would require more math and steps.
Or you can do this:
After Minor Heal, make a switch called check HP, and make sure it's turned on.
After that make a script call box with this in it:
for(i = 0; i < $gameParty.size(); i++){
if($gameParty.members().hp < $gameParty.members().mhp){
$gameSwitches.setValue(x, false);
}
}

Where x is the switch id.
Under the script call, do a conditional branch, that checks if the switch is off.
If it's off do another script call with this:

for(i = 0; i < $gameParty.size(); i++){
if($gameParty.members().hp < $gameParty.members().mhp){
var gainHp = Y;
$gameParty.members().gainHp(gainHp);
}
}

Where Y is the amount of HP you want to heal.
Unfortunately, there is no built-in way to determine whether a character's HP is at 100%.
It's possible with Event Commands, but quite a hassle, to be honest.

It's simpler and more convenient to use a script instead.
Conditional Branch -> Script -> Enter following code:
Code:
$gameParty._actors.some(function(item) { return $gameActors._data[item].hp < $gameActors._data[item].mhp });

Basically, the code looks if there are any party members whose HP is below MHP (maximum HP).
So if the condition is met, someone needs healing. Else, there's nothing to heal.

This should be far more convenient than creating another Loop, saving the character's MHP inside a new variable, subtracting the character's HP from the MHP, breaking the loop if the variable is not 0, then - outside of the loop - checking if the variable is 0 (nothing to heal) or not.


PS:
You might want to prevent the player from spamming the free minor heal.
Alternatively, you could tweak the code to determine just how wounded your party is and only make the free heal available if the party has 90% or more HP.

So how would i tweak the code im sorry im completely new to JS so idk how to go about tweaking it lol
So how would i tweak the code im sorry im completely new to JS so idk how to go about tweaking it lol
Assuming you want to check for 90% HP, here's the code:
Code:
$gameParty._actors.some(function(item) { return $gameActors._data[item].hp < 0.9 * $gameActors._data[item].mhp });

If you need a different percentage, replace the "0.9" part with a number of your choosing.
Remember:
Percent is literally "divided by 100".​
So 1% is 0.01, 10% is 0.1, 50% is 0.5, and 100% is 1.


Now, in case you're interested in understanding how the code works, here's an explanation for each part of it.
For the sake of future visitors, my explanation is geared towards programming beginners in general. Please don't feel offended by it.
Spoiler
Code:
$gameParty
This is a default object made for RPG Maker. It's not easy to explain what an object is exactly, but it's easier to imagine objects as being "variables".
This particular variable holds information relating to the party, such as current party members, inventory, money, and possibly even more.


Code:
_actors
This object is a "property" of the $gameParty object. "Property" is just a fancy way to describe an object that belongs to another object. You can easily tell that _actors is a property of $gameParty, because the two are separated by a dot (.)
The _actors object is an array (arrays are like a list of objects) that contains the IDs of the actors currently in your party.
To retrieve data from an array, you can write
Code:
_actors[0]
which retrieves the first item in _actors. Keep in mind that this only works if _actors has a variable in the first place (otherwise you get an error). Also note that the first object of an array is numbered 0, the second object is numbered 1, and so on.


Code:
some()
This is a function that belongs to arrays. Unlike objects, functions actually do something. They require arguments which they put within round brackets (). If the function doesn't need any arguments, then the brackets may remain empty. If you don't use the brackets, the function will be treated like an object (in which case it won't do anything). This is useful if you want to save a function into a variable for later use.
Functions can also return a result. For instance "something.add(5)" probably adds 5 to whatever number is saved in "something" and returns the result of the addition. This can be used like this: "HP = HP.add(5)", which means we're adding 5 to our current HP, then overwriting our current HP with the new value. Not all functions return a result, but many do.

The "some" function is a standard function in JavaScript. Other programming languages may have something similar but named differently (for instance C# calls it "Any"), or they might not have an equivalent at all.
This particular function tells us if there are some/any objects in our array, that satisfy a given condition. The condition in this case is a function that returns true or false (condition met, or not).


Code:
function(item) { ... }
Here we are about to define a new function. Our function will require an argument (we call it "item") and will return either true or false, depending on whether our condition is met or not.
The "some" function will call our function for each item in _actors (and provide our function with said item as argument) until our function returns true. If there is an item for which our function returns true, "some" will also return true. If there are no more items left and "some" still didn't receive true, it will return false instead.
As you probably remember, $gameParty._actors only contains the IDs of our actors, so each "item" will be an ID.


Code:
return
This is a JavaScript command that will return whatever is evaluated on its right. In our case, its right is going to be either true or false.


Code:
$gameActors._data[item].hp < 0.9 * $gameActors._data[item].mhp
And finally, here is our condition: HP must be smaller than 0.9 MHP (90% of maximum HP).
Let's break it down a little more.


Code:
$gameActors
Like with $gameParty, this is an RPG Maker object. It contains all actors defined in the Database.
Unlike $gameParty._actors, which only contains the ID of the actors in our party, $gameActors contains the actual actors.


Code:
_data
Property of $gameActors. This array is where our actors are actually held. Conveniently, the IDs found in $gameParty._actors coincide with the index of $gameActors._data, which is why we can retrieve our actor with $gameActors._data[item].
Remember that "item" in our case holds the ID of one of our party member.


Code:
hp
Property of actor, it represents the current HP of that actor.


Code:
mhp
Also a property of actor, it represents the maximum amount of HP that actor can have. Comparing this value to the current HP tells us if the actor is wounded or not.
Assuming you want to check for 90% HP, here's the code:
Code:
$gameParty._actors.some(function(item) { return $gameActors._data[item].hp < 0.9 * $gameActors._data[item].mhp });

If you need a different percentage, replace the "0.9" part with a number of your choosing.
Remember:
Percent is literally "divided by 100".​
So 1% is 0.01, 10% is 0.1, 50% is 0.5, and 100% is 1.


Now, in case you're interested in understanding how the code works, here's an explanation for each part of it.
For the sake of future visitors, my explanation is geared towards programming beginners in general. Please don't feel offended by it.
Spoiler
Code:
$gameParty
This is a default object made for RPG Maker. It's not easy to explain what an object is exactly, but it's easier to imagine objects as being "variables".
This particular variable holds information relating to the party, such as current party members, inventory, money, and possibly even more.


Code:
_actors
This object is a "property" of the $gameParty object. "Property" is just a fancy way to describe an object that belongs to another object. You can easily tell that _actors is a property of $gameParty, because the two are separated by a dot (.)
The _actors object is an array (arrays are like a list of objects) that contains the IDs of the actors currently in your party.
To retrieve data from an array, you can write
Code:
_actors[0]
which retrieves the first item in _actors. Keep in mind that this only works if _actors has a variable in the first place (otherwise you get an error). Also note that the first object of an array is numbered 0, the second object is numbered 1, and so on.


Code:
some()
This is a function that belongs to arrays. Unlike objects, functions actually do something. They require arguments which they put within round brackets (). If the function doesn't need any arguments, then the brackets may remain empty. If you don't use the brackets, the function will be treated like an object (in which case it won't do anything). This is useful if you want to save a function into a variable for later use.
Functions can also return a result. For instance "something.add(5)" probably adds 5 to whatever number is saved in "something" and returns the result of the addition. This can be used like this: "HP = HP.add(5)", which means we're adding 5 to our current HP, then overwriting our current HP with the new value. Not all functions return a result, but many do.

The "some" function is a standard function in JavaScript. Other programming languages may have something similar but named differently (for instance C# calls it "Any"), or they might not have an equivalent at all.
This particular function tells us if there are some/any objects in our array, that satisfy a given condition. The condition in this case is a function that returns true or false (condition met, or not).


Code:
function(item) { ... }
Here we are about to define a new function. Our function will require an argument (we call it "item") and will return either true or false, depending on whether our condition is met or not.
The "some" function will call our function for each item in _actors (and provide our function with said item as argument) until our function returns true. If there is an item for which our function returns true, "some" will also return true. If there are no more items left and "some" still didn't receive true, it will return false instead.
As you probably remember, $gameParty._actors only contains the IDs of our actors, so each "item" will be an ID.


Code:
return
This is a JavaScript command that will return whatever is evaluated on its right. In our case, its right is going to be either true or false.


Code:
$gameActors._data[item].hp < 0.9 * $gameActors._data[item].mhp
And finally, here is our condition: HP must be smaller than 0.9 MHP (90% of maximum HP).
Let's break it down a little more.


Code:
$gameActors
Like with $gameParty, this is an RPG Maker object. It contains all actors defined in the Database.
Unlike $gameParty._actors, which only contains the ID of the actors in our party, $gameActors contains the actual actors.


Code:
_data
Property of $gameActors. This array is where our actors are actually held. Conveniently, the IDs found in $gameParty._actors coincide with the index of $gameActors._data, which is why we can retrieve our actor with $gameActors._data[item].
Remember that "item" in our case holds the ID of one of our party member.


Code:
hp
Property of actor, it represents the current HP of that actor.


Code:
mhp
Also a property of actor, it represents the maximum amount of HP that actor can have. Comparing this value to the current HP tells us if the actor is wounded or not.
Ok i think im understanding it now what i ended up doing is modifying it further so that after the code checks IF the hp is < 90% then the player gets a free 10% heal Else the Nun says I'm sorry you have too few wounds i think i got it but there's no way to fully check until the game has monsters to drop the hp down to get the heal

Code:
{$gameActors._data[item].hp < $gameActors._data[item].hp = $gameActors._data[item].mhp * 0.1;}

Original thread: https://forums.rpgmakerweb.com/threads/minor-wounds-healing-system.92863/