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,957
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
10,959
Reaction score
8,833
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,013
Reaction score
4,338
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

Just sorted out all the advent resources... there might be minor changes, but I'd say, I'm done.
Check out the music I've been listening to while animating:
Well, for anyone who cares, Simone has been eating her prescription food for a few weeks and I’m cautiously optimistic it’s helping her quite a bit. She still hasn’t put on any weight but she’s not getting sick every day (has even gone a week between sick days).

IMG_0254.jpeg
Steam acount got hacked and fully taken over now i gotta save up for rpg maker mv again.... :kaoangry:
Anyway heres a screenshot i made before it happend! hope yall like grrrr
image.png
When you're watching a stream with four adult, apparently native English speakers. One has never heard the word "wheedle" and the other three can't readily define it for him. :rolleyes:

Forum statistics

Threads
134,693
Messages
1,249,785
Members
177,440
Latest member
anzod
Top