$gameTroop.members()[i].gainHp(Math.abs(formula)) ?

Hey guys,

I can't quite figure this one out.
I have an actor Skill which starts a Common event. After selecting the targeted enemy, the common event is started.

Within that common event, I would like the enemy to lose HP, and the amount should be determined by the actor's formula:

Code:
$gameTroop.members()[i].gainHp(0 - Math.abs(a.atk * 4 - b.def * 2))

But if I just put it like this, it says "a is not defined".

How can I use a damage formula in a script call?
Hm...I admit I'm not super experienced in JS, but I'm not sure you can directly call damage from a script call using a formula like that. Your forumla is sound for losing HP, but the damage targets (a and b) I'm not sure can be defined directly via script calling.

What about having your skill call a common event that then calls another skill (it could be named the same thing, just with your formula as the damage)? Using whichever one of these you need:

$gameParty.members()[index].forceAction(skillId, targetIndex);
BattleManager.forceAction($gameParty.members()[index]);

$gameTroop.members()[index].forceAction(skillId, targetIndex);
BattleManager.forceAction($gameTroop.members()[index]);

That way, your common event runs, but then calls upon this to run the skill and that skill contains your damage formula.

Like I said, I'm not a superstar with JS, so this could be an awful solution (sorry!) 😅
Hm...I admit I'm not super experienced in JS, but I'm not sure you can directly call damage from a script call using a formula like that. Your forumla is sound for losing HP, but the damage targets (a and b) I'm not sure can be defined directly via script calling.

What about having your skill call a common event that then calls another skill (it could be named the same thing, just with your formula as the damage)? Using whichever one of these you need:

$gameParty.members()[index].forceAction(skillId, targetIndex);
BattleManager.forceAction($gameParty.members()[index]);

$gameTroop.members()[index].forceAction(skillId, targetIndex);
BattleManager.forceAction($gameTroop.members()[index]);

That way, your common event runs, but then calls upon this to run the skill and that skill contains your damage formula.

Like I said, I'm not a superstar with JS, so this could be an awful solution (sorry!) 😅

not bad, with a workaround it works! Thank you! :x
Glad it worked out! Maybe there is a more streamlined way to do it, but at least it's working! 🙂

Original thread: https://forums.rpgmakerweb.com/threads/gametroop-members-i-gainhp-math-abs-formula.85866/