RMMZ Trying to get a specific State + Variable interaction to work correctly

HihoHarpy

Villager
Member
Joined
Aug 3, 2022
Messages
5
Reaction score
0
First Language
English
Primarily Uses
RMMZ
I'm trying to get a state to tie a enemies health to a variable so another enemy in the same troop can be transformed into it and it's HP remains the same. bonus points if someone can also help me make it so every enemy in the troop dies when a enemy who has this state currently dies.

This is my current code:

<JS On Add State>
target.hp = ($gameVariables.value(94));
</JS On Add State>

<JS On Erase State>
$gameVariables.setValue(94, target.hp);
</JS On Erase State>

<JS Post-Damage As Target>
if (target.hp <= 0 || target.isDead()) {

}
</JS Post-Apply As Target>
 

Shaz

Keeper of the Nuts
Global Mod
Joined
Mar 2, 2012
Messages
46,153
Reaction score
16,960
First Language
English
Primarily Uses
RMMV

I've moved this thread to Plugin Support. Thank you.

 

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
11,097
Reaction score
9,027
First Language
English
Primarily Uses
RMMV
target.hp = ($gameVariables.value(94));
You can't do this, hp isn't a variable that you can set. The engine really wants you to go through the gainHp() function, but you can set it directly via target._hp

<JS Post-Damage As Target>
if (target.hp <= 0 || target.isDead()) {

}
</JS Post-Apply As Target>
This wouldn't do anything even if you had code in it, because your start and end notetags don't work.

But it's pretty straightforward:
Code:
<JS Post-Damage As Target>
if (target.hp<=0 || target.isDead())
    $gameTroop.aliveMembers().forEach(enemy => enemy.gainHp(-enemy.hp));
</JS Post-Damage As Target>
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
5,028
Reaction score
4,362
First Language
EN
Primarily Uses
RMMZ
The engine really wants you to go through the gainHp() function, but you can set it directly via target._hp
That's what setHp is for, e.g.
JavaScript:
target.setHp($gameVariables.value(94));

I'm not sure if the post-damage tag will run after death, since death typically removes all other states on apply. (I'm guessing that's why the hp <= 0 check is in there?) If that does turn out to be a problem, I imagine you could add a "Resist State: Death" trait to this state, then have the state remove itself after doing its on-death stuff, e.g.

if (target.hp <= 0) { for (const ally of target.friendsUnit().aliveMembers()) { ally.addState(1); } target.removeState(123); }
(Assuming "this state" is state ID 123. If target is always an Enemy then you can just use $gameTroop like Turan suggested instead of target.friendsUnit().)
 

HihoHarpy

Villager
Member
Joined
Aug 3, 2022
Messages
5
Reaction score
0
First Language
English
Primarily Uses
RMMZ
Thanks ya'll it works perfectly now. You know in hindsight I probably shouldn't be trying to code stuff half asleep... That's how you get results like the mess I initially posted lol.
 

Latest Threads

Latest Profile Posts

The trailer for a documentary I am in a short bit of just dropped.
when you figure out someone's issue on the forums, but you aren't about that necro-posting life.
Dalph wrote on Erif's profile.
Titania has been added and she's clickable too, she redirects to your thread. I wonder how far I can go with all these blondes in the banners. It's an army already.
Pre-title animation of Rosegard :)
image.png

Forum statistics

Threads
134,855
Messages
1,251,263
Members
177,646
Latest member
madlizard
Top