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,156
Reaction score
9,104
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,031
Reaction score
4,372
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 Posts

Latest Profile Posts

Definitely leaning on the "try to" part of the status feed rule and I really try not to sad post, but not only is my kitty Simone more or less confirmed to have IBD... but she has some pulmonary edema and a slightly enlarged heart. They say everything is early and mild and that I'm very diligent and observant about my pets but iunno...doesn't feel like a win right now.


So it turns out music is fun to make????
A lil concept for a prison level. It's intentional that the chords and sound is the same from the previous concept I posted cause it's related to a certain character... What do u think?
I was wondering if I should ask the question
"Who Is Dalph?"
But I met him pretty fast and his answer was extremely helpful. So yeah. That probably answers it.
So in hindsight, I could have made a double-post in this category instead of setting up a post on a different site and figuring out how to share and then linking...

Forum statistics

Threads
134,907
Messages
1,251,810
Members
177,728
Latest member
keilahm776
Top