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,263
Reaction score
9,251
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,043
Reaction score
4,395
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

Me: "Who the heck would play a game with no stakes, no enemies, and all you do is raise and breed bees?"
Later after playing it. - "Holy crap, I didn't know it was 1:30. Where'd my time go?"
The site is being slow and funky again. IS SOMEONE CRAFTING POEMS?!
So yeah, @TRIDIUM @TESTOSTERONE, I wuz like, "What do they mean by borderline and boundaries?"

And then, y'all know this girl?

actress1.png

alice_bikini.png

The clothes? They're just a, um, quick edit. :kaoswt:
I've uploaded the opening cutscene from my game to my channel. It basically introduces us to the first three characters, and what their relationships are:
Cosmic Inferno: Opening dialogue
I don't want to start a panic...but everyone, check the color of your milk!
IMG_20231002_082329.jpg

Forum statistics

Threads
135,021
Messages
1,253,022
Members
177,951
Latest member
gomeisan
Top