- Joined
- Apr 23, 2011
- Messages
- 460
How do I make a method inside a struct run when an event other than onInit occurs?
TriggerAddCondition
or TriggerAddAction
.call TriggerAddCondition(trigger, Condition(function thistype.method))
call TriggerAddAction(trigger, function thistype.method)
call TriggerAddCondition(trigger, Condition(function struct.method))
call TriggerAddAction(trigger, function struct.method)
struct Jump extends array
private static integer spell = 'Aroc'
private static rect area = gg_rct_GiveSpell
private static method GiveSpell takes nothing returns nothing
local unit u = GetEnumUnit()
local location loc = Location(GetRectCenterX(gg_rct_ResendSpell),GetRectCenterY(gg_rct_ResendSpell))
call UnitAddAbility(u, spell)
call SetUnitPositionLoc(u, loc)
set loc = null
set u = null
endmethod
private static method CheckUnit takes nothing returns nothing
local group g = CreateGroup()
call GroupEnumUnitsInRect(g, area, null)
call ForGroup(g, function thistype.GiveSpell)
call DestroyGroup(g)
set g = null
endmethod
static method Main takes nothing returns nothing
call .CheckUnit()
endmethod
endstruct
struct Jump extends array
private static integer spell = 'Aroc'
private static rect area = null
private static method GiveSpell takes nothing returns nothing
local unit u = GetEnumUnit()
local location loc = Location(GetRectCenterX(gg_rct_ResendSpell),GetRectCenterY(gg_rct_ResendSpell))
call UnitAddAbility(u, spell)
call SetUnitPositionLoc(u, loc)
set loc = null
set u = null
endmethod
private static method CheckUnit takes nothing returns nothing
local group g = CreateGroup()
call DestroyTimer(GetExpiredTimer())
set thistype.area = gg_rct_GiveSpell
call GroupEnumUnitsInRect(g, area, null)
call ForGroup(g, function thistype.GiveSpell)
call DestroyGroup(g)
set g = null
endmethod
private static method onInit takes nothing returns nothing
call TimerStart(CreateTimer(), 0, false, function thistype.CheckUnit)
// by running a 0 second timer you ensure that the region has been
// created... otherwise it may return null as DSG said
endmethod
endstruct
function CheckUnitCond takes unit u returns boolean
local integer typeUnit = 'hfoo'
local region r = CreateRegion()
call RegionAddRect(r, gg_rct_GiveSpell)
if GetUnitTypeId(u) == typeUnit and IsUnitInRegion(r, u) == true then
return true
else
return false
endif
endfunction
function DoSpellGive takes nothing returns nothing
local unit u = GetEnumUnit()
if CheckUnitCond(u) == true then
call Jump.Main()
endif
set u = null
endfunction
function Main takes nothing returns nothing
local group g = CreateGroup()
call GroupEnumUnitsInRect(g, gg_rct_GiveSpell, null)
call ForGroup(g, function DoSpellGive)
call DestroyGroup(g)
set g = null
endfunction
function InitTrig_Run_Jump takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterTimerEvent(t, 1., true)
call TriggerAddAction(t, function Main)
set t = null
endfunction