Trying to make an Inn where price is equal to how much HP is lost.

I am trying to make an Inn where the price is equal to how much HP is lost, I found a script on another forum but I'm having some trouble understanding how to use it. Any help would be appreciated.
[ISPOILER]
rpg maker.png
[/ISPOILER]
You could do this easily without a script, here's an alternate approach that seems to work in a quick test:

inn_cost.png


You'd just add additional variables for each party member and give them the same treatment as above for a larger party.

Edit: I added an 'Inn_Cost = 0' to the top of it, so you get a fresh result each time it's run.
I'm sure the solution @akoniti has provided will work for you. You might have issues if you don't restore health to actors when they leave the party ie. you'll be charged to heal actors who aren't in the party any more if they leave the party damaged. You could get around this with a conditional branch checking that they're in the party before doing the control variable steps though, so it's workable. If you are working with a small roster of actors I would stick with this solution as it's far more readable.

However, to provide some clarity on why the script isn't working the way you intend, I see two immediate issues:

1. The script you are using sets variable 5 to hold the total inn cost, but you are trying to use variable 1. If you change the last line of your script to be:
Code:
$gameVariables.setValue(1, totalAmount); //note the 5 has been changed to 1
That will solve that issue.

2. You are using a control variable command to set to the value of script. This won't work the way you expect it to, so you should remove this command.
I agree with @Silva, especially since the original script seems to me more dynamic by taking into account the specific party members at a the current time.

But another point of improvement needs to be made to the event instructions. In the if-else statement, you test the same variable twice (totalInnPrice >= totalInnPrice). You should instead test with the amount of gold available to the party, i.e. partyGold >= totalInnPrice.

To do this, either you assign the amount of party gold in a new variable and compare it to your variable 1...
Spoiler
Assign new variable:
1630013693067.png

Set if condition:
1630013738858.png

or you can perform the condition with the following script:
Code:
$gameParty.gold() >= $gameVariables.value(1)

Hope this can help.
Thanks all for your help, i think i figured it out with a combimation of @Silva and @r66r suggestions. @akoniti your idel i will keep in mind.
Hello again.

About your request, it is not difficult to create a working plugin for this, checking the group members to use as a parameter is easy.
I already simulated the test and it worked.
JavaScript:
var tmpcost=0;
var actorid;
for(i=1;i<$gameParty._actors.length;i++){
    actorid=$gameParty._actors[i];
    tmpcost += $gameActors._data[actorid].mhp - $gameActors._data[actorid]._hp;
}

It wouldn't be better to do it with a percentage, because if a character's HP is too high it would be impossible for the player to have the money to recover at the INN.

Original thread: https://forums.rpgmakerweb.com/threads/trying-to-make-an-inn-where-price-is-equal-to-how-much-hp-is-lost.139898/