A pretty simple little snippet i made for a spell a while ago.
What does it do?:
This snippet will find the unit with the lowest health within a specified group. The user can determine whether to find the unit with the lowest base health, or the lowest percentage of health.
What is its uses?:
It can be useful for a few things, such as:
- Custom AI - Useful for finding weaker units to pick on; and
- Spells - Again, you can find weaker units to pick on or even help out.
The Snippet:
To use:
To use the snippet simply type:
or in GUI:
Its that simple, and it works pretty well.
To import:
To import the snippet simply copy the script into your map header, or if you have NewGen, make a new trigger, convert it to custom text and paste the script.
You can also add it to a library if you want.
Im sure theres someone who will find a use for it.
I have attached a test map with a spell that shows off how this snippet can be used.
What does it do?:
This snippet will find the unit with the lowest health within a specified group. The user can determine whether to find the unit with the lowest base health, or the lowest percentage of health.
What is its uses?:
It can be useful for a few things, such as:
- Custom AI - Useful for finding weaker units to pick on; and
- Spells - Again, you can find weaker units to pick on or even help out.
The Snippet:
JASS:
function GetUnitWithLowestHp takes group Whichgroup, boolean Percent returns unit
local unit fog = null
local unit weakest = null
local real currenthp = 0.00
local real lowesthp = 1000000.00
loop
set fog = FirstOfGroup(Whichgroup)
exitwhen fog == null
call GroupRemoveUnit(Whichgroup,fog)
if Percent then
set currenthp = GetWidgetLife(fog) / GetUnitState(fog,UNIT_STATE_MAX_LIFE)
else
set currenthp = GetWidgetLife(fog)
endif
if currenthp < lowesthp then
set lowesthp = currenthp
set weakest = fog
endif
endloop
return weakest
endfunction
To use:
To use the snippet simply type:
JASS:
set weakest = GetUnitWithLowestHp(<Your Group>,<Percent or not>)
or in GUI:
Code:
custom script: set udg_tmpunit = GetUnitWithLowestHp(udg_YourGroup,<Percent or not>)
Its that simple, and it works pretty well.
To import:
To import the snippet simply copy the script into your map header, or if you have NewGen, make a new trigger, convert it to custom text and paste the script.
You can also add it to a library if you want.
Im sure theres someone who will find a use for it.
I have attached a test map with a spell that shows off how this snippet can be used.