How to get enemy value in script?

Hey all

I am working on a custom HUD for my battles using SumRdDde Hud Maker. I am using the YEP Absorption Barrier plugin to give my enemies shields. I can use the script call below to get the current value of their shield:

Code:
battler.barrierPoints()

But it doesn't work - I think I need to define what "battler" is. Can someone help? With my hero I do this:

Code:
var battler = $gameActors.actor(1);
var cur_shield = battler.barrierPoints());

I want to get the enemies shield though. Is it something like:

Code:
var battler = $gameEnemy.actor(1);
var cur_shield = battler.barrierPoints());

Also have no idea how to do this for multiple enemies and also how to place the shield on the HUD for multiple enemies... since the HUD maker wouldn't know how many enemies are in play.

Any ideas on both?

Update: I can get my enemies barrier like this:
Code:
$gameTroop.members()[0].barrierPoints()
More problems exist - see below
Try this:

Code:
var cur_shield = [];
for(var i = 0; i < $gameTroop.troop().length; i++)
{
   var battler = $gameTroop.troop()[i];
   cur_shield.push(battler.barrierPoints());
}

This should give you the barrierPoints of all the enemies in the Troop.
Try this:

Code:
var cur_shield = [];
for(var i = 0; i < $gameTroop.troop().length; i++)
{
   var battler = $gameTroop.troop()[i];
   cur_shield.push(battler.barrierPoints());
}

This should give you the barrierPoints of all the enemies in the Troop.

Thanks
Unfortunately I can't get that one to work. Doesn't "$gameTroop" get the value from the database troop settings? But I need the value from the enemy object itself? I thought I read somewhere that they are two different things...

I tried changing this to:

Code:
$gameTroop.troop(1).barrierPoints();

To try and manually just get the barrier points from the first enemy in the battle but that didn't work either. (Neither did $gameTroop.troop(0).barrierPoints(); )
Thanks
Unfortunately I can't get that one to work. Doesn't "$gameTroop" get the value from the database troop settings? But I need the value from the enemy object itself? I thought I read somewhere that they are two different things...

I tried changing this to:

Code:
$gameTroop.troop(1).barrierPoints();

To try and manually just get the barrier points from the first enemy in the battle but that didn't work either. (Neither did $gameTroop.troop(0).barrierPoints(); )

You're right, $gameTroops gives you ALL of the existing troops. To get the specific one you're fighting you would need "$game_troop".

Let's try again:

Code:
var cur_shield = [];
for(var i = 0; i < $game_troop.members.length; i++)
{
   var battler =  $game_troop.members[i];
   cur_shield.push(battler.barrierPoints());
}

EDIT: Ignore all of this, that's stuff for Ruby Language -_-" Sorry about that.

EDIT2: Ok try this one:

Code:
var cur_shield = [];
for(var i = 0; i < $gameTroop.members().length; i++)
{
   var battler = $gameTroop.members()[i];
   cur_shield.push(battler.barrierPoints());
}
I've made progress

I can use the following to get my enemies barrier points

Code:
$gameTroop.members()[0].barrierPoints()

The problem I have, with creating a gauge, is that I also need their "max" barrier.

So far I've tried a ton of things. Including setting up a ton of variables (501, 502, 503 etc) that store the enemies max barrier. So I tried this:

Code:
$gameVariables.value($gameTroop.members()[0]._enemyId + 500)

But I get an error...

"Failed to execute "createLinearGradient" on "CanvasRenderingContext2D: The provided double value is non-finite

So its back to the drawing board.
I've made progress

I can use the following to get my enemies barrier points

Code:
$gameTroop.members()[0].barrierPoints()

The problem I have, with creating a gauge, is that I also need their "max" barrier.

So far I've tried a ton of things. Including setting up a ton of variables (501, 502, 503 etc) that store the enemies max barrier. So I tried this:

Code:
$gameVariables.value($gameTroop.members()[0]._enemyId + 500)

But I get an error...

"Failed to execute "createLinearGradient" on "CanvasRenderingContext2D: The provided double value is non-finite

So its back to the drawing board.
If you want to create an array with the maximum barrier points every enemy can have, you should use $gameSystem:

Code:
$gameSystem.enemyMaxBarrier = $gameSystem.enemyMaxBarrier || ["enemyMax1", "enemyMax2", "enemyMax3", etc...]

The "||" in between means that if the game has already declared this variable once, it will not refill it with all your values. You replace "enemyMax1" and so on with the max barrier points of every enemy. Then, when you want to get the Max Barrier Points of an enemy:

Code:
var id = "the id of the enemy you want";
var enemyMaxPoints = $gameSystem.enemyMaxBarrier[id-1];

Tell me if it works!
Thanks for this. I'll give it a try.

Looks like a more elegant way that using game variables.

Where should I put this code though? Do I need to make a custom plugin? (Never done that before)
Thanks for this. I'll give it a try.

Looks like a more elegant way that using game variables.

Where should I put this code though? Do I need to make a custom plugin? (Never done that before)
The $gameSystem variable you could put it in an event at the start of the game. Like, if the game as a scripted dialogue and/or fight at the beginning, you could call the script there.
Great! Seems to work the same as using my variables, so thats good.
I guess I just need to decide if I want them stored in game variables, for manipulating in the editor / events etc. Or whether to use the the $gameSystem variable for a script based approach. Either way I'm assigning the values manually to a variable right.

Thanks a lot for your help
Great! Seems to work the same as using my variables, so thats good.
I guess I just need to decide if I want them stored in game variables, for manipulating in the editor / events etc. Or whether to use the the $gameSystem variable for a script based approach. Either way I'm assigning the values manually to a variable right.

Thanks a lot for your help
No problem! ^^
You can use and manipulate $gameSystem in events and such, so you should be golden.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-get-enemy-value-in-script.121093/