Basic hp/mp scan script

Joined
Mar 4, 2016
Messages
2
Reaction score
0
First Language
English
Primarily Uses
I've been having a really tough time with a basic enemy HP and MP "scan" script.  I've tried Yanfly Engine Ace - Enemy Target Info, but it's actually way too fancy for what I want.  I just want to have an actor use a skill that shows whatever enemy he/she targets' current HP and MP.  I think I'm close. 


Right now, I've got a skill that adds a state to the target called "Revealed".  The index of the state is '026' in my game. 


The skill also calls a common event which has a script that sets two game variables, which I then display in a battle text window.  Here's the common event:


Untitled.png


The script text I have (which is also in the image) is:


$game_troop.members.any? { |m| m.state?(26)$game_variables[5] = m.name$game_variables[6] = m.hp$game_variables[7] = m.mp}


I'm not very good with Ruby, but my understanding is that this script is supposed to check to see if *any* enemy in a troop has the state 'revealed' (index 26) applied to it, and then set my game variables with that target's name, and current hp and mp.  The problem is though that no matter which enemy in a troop larger than one that I target, it always only returns enemy A's hp and mp.


Can someone point out what stupid thing I may be doing here?


Thank you!!!
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
The logic in your script call is wrong.  The first line is meant to return true or false based on whether or not ANY member has the state.  But the code within the block sets the variables whether the state is applied or not.  The fact that the variables are set is probably returning true after the first member is tested.


You need to rethink your logic.  What if several members have the state?  Which one should the variable be set to?


Try something like this - this will set the variables to the first enemy that has the state, and ignore the rest:


Script: mbrs = $game_troop.members.select { |m| m.state?(26) }
if mbrs.size > 0
$game_variables[5] = mbrs[0].name
$game_variables[6] = mbrs[0].hp
$game_variables[7] = mbrs[0].mp
end


You should set those variables to blank or 0 before the script call, so that if NO members have that state, they will not contain anything.


Note - I haven't tested this code, so you might end up with some syntax errors.


Also, if you're only interested in the living enemies and want to ignore those that have already been defeated, use alive_members instead of members.
 
Last edited by a moderator:
Joined
Mar 4, 2016
Messages
2
Reaction score
0
First Language
English
Primarily Uses
Wow, thank you!  That is what I needed.  There's not much information out there that I could find that explains how the logic of iterating through battle troops works. 


This works perfectly!!
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,860
Messages
1,017,040
Members
137,569
Latest member
Shtelsky
Top