Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library UnitInRangeOfType requires AIDS, Event, Alloc
- globals
- private key EVENT_KEY
- private key TRIGGER_KEY
- private key RANGE_KEY
- private key TYPE_KEY
- endglobals
- private struct idlist extends array
- public static integer count = 0
- private method OnDestroy takes nothing returns nothing
- set thistype.count = thistype.count - 1
- endmethod
- implement Alloc
- public integer id
- public static method create takes integer id returns thistype
- local thistype this = thistype.allocate()
- set this.id = id
- set thistype.count = thistype.count + 1
- return this
- endmethod
- endstruct
- private struct data extends array
- public static hashtable hash
- public Event e
- //! runtextmacro AIDS()
- private static method AIDS_filter takes unit u returns boolean
- local integer i = idlist.count
- local boolean b = false
- local integer id = GetUnitTypeId(u)
- loop
- exitwhen i == 0
- set b = b or ( id == idlist[i].id )
- set i = i - 1
- endloop
- return b
- endmethod
- private static method OnEvent takes nothing returns boolean
- call FireEvent(Event(LoadInteger(data.hash, LoadInteger(thistype.hash, GetHandleId(GetTriggeringTrigger()), TYPE_KEY), EVENT_KEY)))
- return false
- endmethod
- private method AIDS_onCreate takes nothing returns nothing
- local trigger t = CreateTrigger()
- local integer i = GetUnitTypeId(this.unit)
- set this.e = Event.create()
- call TriggerRegisterUnitInRange(t, this.unit, LoadReal(thistype.hash, i, RANGE_KEY), null)
- call TriggerAddCondition(t, Condition(function thistype.OnEvent))
- call SaveInteger(thistype.hash, GetHandleId(t), TYPE_KEY, i)
- endmethod
- private static method AIDS_onInit takes nothing returns nothing
- set hash = InitHashtable()
- endmethod
- endstruct
- function TriggerRegisterUnitInRangeOfType takes trigger whichTrigger, integer whichType, real range returns Event
- local Event e
- if ( HaveSavedInteger(data.hash, whichType, EVENT_KEY) ) then
- set e = LoadInteger(data.hash, whichType, EVENT_KEY)
- else
- set e = Event.create()
- call SaveInteger(data.hash, whichType, EVENT_KEY, e)
- call TriggerRegisterEvent(whichTrigger, e)
- endif
- call idlist.create(whichType)
- call SaveTriggerHandle(data.hash, whichType, TRIGGER_KEY, whichTrigger)
- call SaveReal(data.hash, whichType, RANGE_KEY, range)
- return e
- endfunction
- endlibrary
- struct asdf extends array
- private static method a takes nothing returns nothing
- call BJDebugMsg("Test")
- endmethod
- private static method onInit takes nothing returns nothing
- local trigger t = CreateTrigger()
- call CreateUnit(Player(0), 'hfoo', 0, 0, 0)
- call CreateUnit(Player(0), 'hfoo', 0, 550, 0)
- call CreateUnit(Player(0), 'hfoo', 0, -550, 0)
- call CreateUnit(Player(0), 'hkni', 550, 0, 0)
- call CreateUnit(Player(0), 'hkni', -550, 0, 0)
- call TriggerRegisterUnitInRangeOfType(t, 'hfoo', 500)
- call TriggerAddAction(t, function thistype.a)
- endmethod
- endstruct
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement