Javascript for Setting Actor's HP in a Variable, then Subtracting...

Solution: I googled my brains out and came up with a way to solve this!
 
<HP Cost: 10>
<After Eval>
$gameVariables.setValue(18, $gameVariables.value(18) + 10)
</After Eval>
 
I was super overthinking things. Omgosh.

--------------------------------------
 
Hello guys! I have a skill in my game that uses HP as its "cost" - it's like blood magic. What I'm trying to do is get the game to keep track of how much "blood" that actor has spent in every battle - which will later determine the strength of a summon.
 
Right now I am using Yanfly's Custom Skills plugin. I've got the skill to cost 3% of the actor's HP - easy. Now what I'm trying to do is add Pre- and Post-Damage functions, but I don't know any javascript T_T
 
Here's what I want:
 
<Before Eval>
Set variable 17 to actor 3's current HP
</Before Eval>
 
<After Eval>
Set variable 18 to actor 3's current HP (this would be after she spent 3% of her HP on the skill)
Subtract variable 18 from 17 and then ADD the result to variable 19 (this would show how much HP she spent in all, in its own variable for me to use later on)
</After Eval>
 
Example:

Variable 17: HP before skill
Variable 18: HP after skill
Variable 19: Total HP spent
 

Actor 3's HP is 100
Uses blood skill that drains 3% of her HP
Actor 3's HP is now 97
100 - 97 = 3
Variable 19 holds the value "3"
 
 
Later she does the same thing, and variable 19 now holds the value "6" and so on. Then I plan on using variable 19 in a damage formula for another skill she gains later in the game.
 
I've looked at the RMMV Script Calls list but could only find how to change HP, not set it to a variable. After googling, I found this: $gameVariables.setValue(1, "text"); but i don't think that doesn't what I want, necessarily, but can certainly be a start.
 
Can anyone help me out? =]
 
Edit: After more searching I found this script that could be for the subtraction:
$gameVariables.setValue(19, $gameVariables.value(17) - $gameVariables.value(18)) maybe? Haven't tried it cause I still need to figure how to get her HP numbers.
 
$gameVariables.setValue(17, actorHP) <-- dunno how do
I don't have RMMV to test but can you try the lines 533 - 535 the


Game_BattlerBase.prototype.paySkillHpCost = function(skill) {


this._hp -= this.skillHpCost(skill);


};


because this line seems to be subtracting the hp cost to your HP..


can you try inserting setting the this.skillHpCost(skill) in a variable?


maybe like this?


Game_BattlerBase.prototype.paySkillHpCost = function(skill) {


this._hp -= this.skillHpCost(skill);


$gameVariables.setValue(1, += this.skillHpCost(skill));


};
I don't have RMMV to test but can you try the lines 533 - 535 the

Game_BattlerBase.prototype.paySkillHpCost = function(skill) {

this._hp -= this.skillHpCost(skill);

};

because this line seems to be subtracting the hp cost to your HP..

can you try inserting setting the this.skillHpCost(skill) in a variable?

maybe like this?

Game_BattlerBase.prototype.paySkillHpCost = function(skill) {

this._hp -= this.skillHpCost(skill);

$gameVariables.setValue(1, += this.skillHpCost(skill));

};
Awesome! That looks entirely relevant to what I need.

I'm at work and can't test either haha. Would this go in the <After Eval>? Or do you think it'd go as a Common Event script?

Edit: So I tried it out but the += was giving me a Syntax error. So I changed it to just +. I also changed "1" to "17." No error, but when I tested it in-game (as both a common event and also in <after eval>), the variable didn't change - it's stayed at 0.
I mean you add it directly to the script so whenever it runs through that code it'll automatically add,


not in common event, try again +=.


Look around the said line then insert


$gameVariables.setValue(n, += this.skillHpCost(skill));


n is for your variable id, ex: 17
I mean you add it directly to the script so whenever it runs through that code it'll automatically add,

not in common event, try again +=.

Look around the said line then insert

$gameVariables.setValue(n, += this.skillHpCost(skill));

n is for your variable id, ex: 17
That ended up breaking the script in that the skill no longer cost Hp D= also the variable didn't change (maybe because it didn't cost anything)
Solution: I googled my brains out and came up with a way to solve this!

<HP Cost: 10>

<After Eval>

$gameVariables.setValue(18, $gameVariables.value(18) + 10)

</After Eval>

I was super overthinking things. Omgosh.
Sorry Lorelei! all I said gone wrong. 🙁

Just got my RMMV today so I can't test it before.

I tried it, yes that works but whenever another character or enemy use

the same skill it adds to the variable also.

It's viable if your character's skill set is unique.

Sorry really~!   ;_; ;_;

Good luck on your game!

Original thread: https://forums.rpgmakerweb.com/threads/javascript-for-setting-actors-hp-in-a-variable-then-subtracting.50187/