| 08-14-2008, 04:06 PM | #1 | ||||||||||||||||||||
Often I need to weed out units from groups, with a specific highest/lowest property. Such as highest health, lowest health etc. Examples:
So I thought what would be really neat is 1 simple group function to handle it all: JASS:function GroupGetSpecial takes group g, string property, boolean b returns unit The boolean is simply, true = highest, false = lowest. The properties could be: Table:
So anyways a quick simple function I whipped up, for my Soul Drain ability for Spell Olypmics, it simply returns unit with lowest health JASS:function GroupGetLowestHealth takes group g returns unit local unit d = null local unit lowestunit = null local real lowesthealth = 0 local real health = 0 local group f = CreateGroup() call GroupAddGroup(g, f) loop set d = FirstOfGroup(f) exitwhen d == null set health = GetWidgetLife(d) if lowestunit == null then set lowestunit = d set lowesthealth = health elseif health < lowesthealth then set lowestunit = d set lowesthealth = health endif call GroupRemoveUnit(f, d) endloop call DestroyGroup(f) return lowestunit endfunction So anyways, how do you think the best way of doing this would be? It takes the property, then alters the condition to the appropriate one? JASS:set health = GetWidgetLife(d) JASS:set health = GetUnitState(d, UNIT_STATE_MAX_LIFE) set health = GetUnitState(d, UNIT_STATE_MAX_MANA) Thx for any help, I think this could be very useful to alot of ppl. |
| 08-14-2008, 04:26 PM | #2 |
Well, I have an idea and am coding it right now, but I need a better sounding name than GroupGetSpecial. GroupGetExtremeUnit perhaps? naw... |
| 08-14-2008, 04:43 PM | #3 |
GroupGetSpecificUnit ? |
| 08-14-2008, 04:44 PM | #4 |
Hmm... no, I'll just go with GroupGetHighest and GroupGetLowest. Edit: I'll throw in GroupGetNearest for good measure. |
| 08-14-2008, 05:25 PM | #5 |
Ok, I coded the first version, here it is. Suggestions on other properties I can implement are welcome. |
