- Joined
- Sep 26, 2009
- Messages
- 9,529
GUI Unit Indexer with vJass syntax has been realized with this groundbreaking tool. The idea for this came from the user, Spellbound.
Note that no changes to the GUI code were needed to make this happen, so the only thing a user would need to do is import this script and make the library a requirement to libraries who call its functions. The implication of this, I suppose, is that GUI Unit Indexer can now be used for vJass resources.
Notably different than Nestharus' API, I have included OnUnitIndex and OnUnitDeindex which are shorter to write and are not ugly. They also take a single code argument instead of a boolexpr and integer argument. The function "OnUnitDeindex" will normally fire at a random time after a unit has left the game, if you want it to fire at the instant before the unit becomes unavailable, you'll want to have the GUI Unit Event resource in your system: http://www.hiveworkshop.com/forums/spells-569/unit-event-v2-0-0-0-a-201641/
Note that no changes to the GUI code were needed to make this happen, so the only thing a user would need to do is import this script and make the library a requirement to libraries who call its functions. The implication of this, I suppose, is that GUI Unit Indexer can now be used for vJass resources.
Notably different than Nestharus' API, I have included OnUnitIndex and OnUnitDeindex which are shorter to write and are not ugly. They also take a single code argument instead of a boolexpr and integer argument. The function "OnUnitDeindex" will normally fire at a random time after a unit has left the game, if you want it to fire at the instant before the unit becomes unavailable, you'll want to have the GUI Unit Event resource in your system: http://www.hiveworkshop.com/forums/spells-569/unit-event-v2-0-0-0-a-201641/
JASS:
library UnitIndexerGUI //requires GUI Unit Indexer
globals
private trigger index = null
private trigger deindex = null
private trigger init = null
private trigger tempTrig
endglobals
private function DoTheThings takes trigger t, code c, real r returns trigger
if t == null then
set t = CreateTrigger()
call TriggerRegisterVariableEvent(t, "udg_UnitIndexEvent", EQUAL, r)
endif
call TriggerAddCondition(t, Filter(c))
set tempTrig = t
set t = null
return tempTrig
endfunction
//call RegisterUnitIndexEvent(Filter(function Blah), EVENT_UNIT_INDEXED)
//->
//call OnUnitIndex(function Blah)
function OnUnitIndex takes code c returns nothing
set index = DoTheThings(index, c, 1.)
endfunction
//call RegisterUnitIndexEvent(Filter(function Blah), EVENT_UNIT_DEINDEXED)
//->
//call OnUnitDeindex(function Blah)
function OnUnitDeindex takes code c returns nothing
set deindex = DoTheThings(deindex, c, 2.)
endfunction
private function DestroyInit takes nothing returns boolean
call DestroyTrigger(init) //will still allow consecutive triggerconditions to run.
set init = null
return false
endfunction
//GUI Unit Indexer will initialize after any vJass stuff, so you need to do your
//unit-indexer-requiring stuff after this event instead of a module/struct/library
//initializer.
function OnUnitIndexerInitialized takes code c returns nothing
if init == null then
set init = CreateTrigger()
call TriggerAddCondition(init, Filter(function DestroyInit))
call TriggerRegisterVariableEvent(init, "udg_UnitIndexEvent", EQUAL, 3.00)
endif
call TriggerAddCondition(init, Filter(c))
endfunction
function GetUnitId takes unit u returns integer
return GetUnitUserData(u)
endfunction
function GetUnitById takes integer id returns unit
return udg_UDexUnits[id]
endfunction
function GetIndexedUnit takes nothing returns unit
return udg_UDexUnits[udg_UDex]
endfunction
function GetIndexedUnitId takes nothing returns integer
return udg_UDex
endfunction
function IsUnitIndexed takes unit u returns boolean
return udg_UDexUnits[GetUnitUserData(u)] == u
endfunction
endlibrary
Last edited: