cleeezzz
The Undead Ranger.
- Reaction score
- 268
I'm trying to remake Darthfett's GetCenterUnit, basically allowed you to get the actual unit from the event Unit comes in range to x unit.
im trying to do this with Jesus' Event system, i have the idea down, but i have no idea how to do it
im assuming you can get which event was fired and attach data to events using the system so.. heres my idea
set event = Register unit comes within 500 range of unit 1.
then somehow attach data to the event, possibly in a struct?
then in the actions, i can do...
CenterUnit = Triggering Event[unit] (of course the syntax is wrong because i dont know it)
im trying to do this with Jesus' Event system, i have the idea down, but i have no idea how to do it
im assuming you can get which event was fired and attach data to events using the system so.. heres my idea
set event = Register unit comes within 500 range of unit 1.
then somehow attach data to the event, possibly in a struct?
then in the actions, i can do...
CenterUnit = Triggering Event[unit] (of course the syntax is wrong because i dont know it)
JASS:
library UnitEntersRange
globals
private hashtable hash = InitHashtable()
endglobals
private function BOOLEXPR_TRUE takes nothing returns boolean
return true
endfunction
private struct data
trigger trig
unit center
static method create takes unit whichUnit, real range, boolexpr filter returns thistype
local thistype this = thistype.allocate()
set this.trig = CreateTrigger()
set this.center = whichUnit
call SaveInteger(hash, GetHandleId(this.trig), 0, this)
if (filter == null) then
call TriggerRegisterUnitInRange(this.trig, whichUnit, range, Filter(function BOOLEXPR_TRUE))
else
call TriggerRegisterUnitInRange(this.trig, whichUnit, range, filter)
endif
return this
endmethod
method onDestroy takes nothing returns nothing
set .center = null
call RemoveSavedInteger(hash, GetHandleId(.trig), 0)
call DestroyTrigger(.trig)
set .trig = null
endmethod
endstruct
function GetCenterUnit takes nothing returns unit
return data(LoadInteger(hash, GetHandleId(GetTriggeringTrigger()), 0)).center
endfunction
function TriggerRemoveUnitRangeEvent takes trigger t returns nothing
call data(LoadInteger(hash, GetHandleId(t), 0)).destroy()
endfunction
function TriggerRegisterUnitRangeEvent takes unit whichUnit, real range, boolexpr filter returns trigger
local data d = data.create(whichUnit, range, filter)
return d.trig
endfunction
endlibrary