Troop Conditions (Scripting)

Hi! I'm currently creating a condition in the Troop Event by Scripting


For every 1% HP lost, gain +4% stats

Here is my code, I don't know where I went wrong or If I'm missing something

var e = $gameTroop.members()[0];

var lostHP_percent = 1-e.hpRate();

var bonusStats = (lostHP_percent * 0.04);



e.atk*=(1+bonusStats);

e.mat*=(1+bonusStats);

e.agi*=(1+bonusStats);

e.luk*=(1+bonusStats);


1712705060716.png


The "Attack" skill is has a formula, with 0 variance, set to "a.atk + a.mat"
The enemy has 200 atk and 200 mat so at 100% hp, it deals 400 damage


However, even when the HP is reduced, the 400 damage is constant throughout.
The references to parameters - e.atk, e.mat, etc. - are not actual properties you can set values to. They're actually getter functions.

You need to use e.addParam() -e.g. e.addParam(2, bonusStats) to increase atk.
I see, however, using addParam may result to calculation inconsistencies should the enemy restore their HP

Is there a a function , rather than addParam, that is probably similar to setParam? Something that would just directly set the given parameter? I tried skimming the script call list, I'm just not certain if there is such elegant function
The references to parameters - e.atk, e.mat, etc. - are not actual properties you can set values to. They're actually getter functions.

You need to use e.addParam() -e.g. e.addParam(2, bonusStats) to increase atk.
I see, however, using addParam may result to calculation inconsistencies should the enemy restore their HP
I don't see the risk of inconsistency - just do the same math backwards.

Is there a a function , rather than addParam, that is probably similar to setParam?
No, the parameters are set by you in the Enemies tab of the database.

If it helps your calculations be more accurate, you can always reference the original values with e.paramBase() which gives the values you entered. So e.paramBase(2) is the original value of atk.

Original thread: https://forums.rpgmakerweb.com/threads/troop-conditions-scripting.167615/