Setting Variable to Enemy HP based on Enemy Index variable?

zXManyRegretsXz

Game Enthusiast
Member
Joined
Jan 11, 2022
Messages
22
Reaction score
45
First Language
English
Primarily Uses
RMMZ
Hi, I'm trying to do something that requires I get the index of the enemy I last targeted with an actor, and then that specific enemy's health. Unfortunately, Control Variable doesn't let me use a specific variable as the enemy's index, so I've taken to using script calls. The script calls I tried to use, however, didn't work and just gave me an error:
1653382277514.png
Can anyone help me? I'd rather not use conditional branches to check the variable I set the enemy index to and set a variable accordingly, but I will if that's the only option. Forgive me for that, I just find it a bit unnecessary to do.
 

Kaymon145

Veteran
Veteran
Joined
Apr 22, 2022
Messages
34
Reaction score
17
First Language
English
Primarily Uses
RMMV
I actually asked a fairly similar question on the MV board a few days ago... Not sure how different the code is between MZ and MV but I was trying to get the agility of the current target, the code that ended up working for me was
$gameTroop.smoothTarget(BattleManager._action._targetIndex).agi
Again I'm not sure how different MZ is but that ended up working for me, maybe something simalar could be done to get HP instead?
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
3,660
Reaction score
2,753
First Language
EN
Primarily Uses
RMMZ
The error says you tried hp(), but hp is not a function, it's a value. Try this:

$gameTroop.members()[$gameTemp.lastActionData(5)].hp
$gameTemp.lastActionData is new to MZ, it's just a script version for the various "Last" options under Control Variables -> Game Data. You could use a variable instead if you want, e.g.

$gameTroop.members()[$gameVariables.value(123)].hp

The Last Target Enemy Index value is updated immediately after an action's damage & effects are applied to a target. So if this script call doesn't work for you, it might be a timing problem. In that case, you may want to specify exactly where you're trying to use this, e.g.
  • In the damage formula (use b.index() for current target index);
  • In a follow-up common event (should be OK);
  • In a troop event (if so, what conditions and when/how are they triggered?);
  • In a notetag from a plugin (if so, which tag/plugin?);
  • Somewhere else?
 

zXManyRegretsXz

Game Enthusiast
Member
Joined
Jan 11, 2022
Messages
22
Reaction score
45
First Language
English
Primarily Uses
RMMZ
The error says you tried hp(), but hp is not a function, it's a value. Try this:

$gameTroop.members()[$gameTemp.lastActionData(5)].hp

$gameTemp.lastActionData is new to MZ, it's just a script version for the various "Last" options under Control Variables -> Game Data. You could use a variable instead if you want, e.g.

$gameTroop.members()[$gameVariables.value(123)].hp


The Last Target Enemy Index value is updated immediately after an action's damage & effects are applied to a target. So if this script call doesn't work for you, it might be a timing problem. In that case, you may want to specify exactly where you're trying to use this, e.g.
  • In the damage formula (use b.index() for current target index);
  • In a follow-up common event (should be OK);
  • In a troop event (if so, what conditions and when/how are they triggered?);
  • In a notetag from a plugin (if so, which tag/plugin?);
  • Somewhere else?
God, I am dumb. That was the issue, the little () after .hp. Of course, there were lots of other issues after that, but I managed to solve them myself (despite them being debatably more difficult). After a few extra things it should be ready, thanks!
 

Latest Threads

Latest Profile Posts

Thunderstorm approaching: *rumble rumble*

Me: "Hmph... so.. you've come..."

And ONLY me: (adapts fighting stance) "...now show me your TRUE POWER!!!"

*Thunderstorm fizzles out. Sunshine and rainbows.*

Seriously, ONLY ME: "No! Come back! I.. I didn't mean..."
The black rose maiden! :kaopride:
vmTLAk8.jpg

Character: Aki Izayoi from Yugioh 5Ds.
Took some trial and error, but I managed to create "visuals" for underground dig path regions.
Couldn't sleep at all so I started working on the topmost deck. I've had to make several deviations from the Imperator/Berengaria's deck-plans to accommodate MV's movement, but 100% accuracy was never my intention.
Still no name for the poor ship...:kaodes:
Screenshot-2022-06-25-053308.png

Forum statistics

Threads
123,034
Messages
1,153,593
Members
161,381
Latest member
hvrhrt
Top