• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] Find lowest health

Status
Not open for further replies.
Level 5
Joined
Oct 30, 2007
Messages
91
I am making a spell, where a hero throws a spear. That spear will hit a unit within a 900 aoe owned by the enemy with the lowest health. the only problem is, how do I tell which unit has the lowest health?
 
Level 7
Joined
Jul 18, 2009
Messages
272
I'm not certain, but I don't think you can check how much health a unit has unless it is max health.

like you can check 900 max hp but you can't detect 600/900 hp
Um... you can check health AND max. health.

I'd do it like this:
1) set integer_variable = 100000
2) pick all enemy units within 900 of your unit
3) for each picked unit do
-- if life of picked unit kleiner als integer_variable:
---- set integer variable = life of picked unit
---- set target = picked unit
4) let a dummy throw your spear on the unit "target"
 
Level 11
Joined
Oct 13, 2005
Messages
233
You should use a unit variable to keep track of the unit in range with the lower health. Now, pick all units in your unit group. For the first unit, set the unit variable to that unit so it will have a value. For all other units, compare the health of the picked unit to the unit that your variable is keeping track of. If its health is lower than the unit in the variable, set the variable to the picked unit. When you're done with the "pick every unit..." action, your unit variable will have the unit with the least hp stored in it.
 
Status
Not open for further replies.
Top