library GenericUnitSpellFinish initializer Init
globals
private hashtable hash = InitHashtable()
unit genLastSpellTarget
unit genLastSpellCaster
endglobals
function TrgRegisterGenericSpellFinish takes trigger t, integer abilityId returns nothing
call SaveTriggerHandle(hash, abilityId, 0, t)
endfunction
function TrgDeregisterGenericSpellFinish takes integer abilityId returns nothing
call FlushChildHashtable(hash, abilityId)
endfunction
private function Main takes nothing returns nothing
local integer spell = GetSpellAbilityId()
local trigger t
if HaveSavedHandle(hash, spell, 0) then
set t = LoadTriggerHandle(hash, spell, 0)
else
return
endif
set genLastSpellTarget = GetSpellTargetUnit()
set genLastSpellCaster = GetTriggerUnit()
if TriggerEvaluate(t) then
call TriggerExecute(t)
endif
set t = null
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i = 0
loop
call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_CAST, null)
set i = i + 1
exitwhen i == bj_MAX_PLAYER_SLOTS
endloop
call TriggerAddAction(t, function Main)
endfunction
endlibrary
scope ToggleFoodDistribution initializer Init
globals
constant integer FOOD_ON = 'Aroa'
constant integer FOOD_OFF = 'Ara2'
constant integer CITY_MORPH_1 = 'Abrf'
endglobals
private function AddToogleOnRemove takes nothing returns nothing
local integer id = GetUnitUserData(genLastSpellCaster)
local unit u = genLastSpellCaster
call TriggerSleepAction(0.1) // Waits for morph
if town[id].autoFeed == true then
call UnitAddAbility(u, FOOD_OFF)
else
call UnitAddAbility(u, FOOD_ON)
endif
set u = null
endfunction
private function FoodOn takes nothing returns nothing
set town[GetUnitUserData(genLastSpellCaster)].autoFeed = true
call UnitAddAbility(genLastSpellCaster, FOOD_OFF)
call UnitRemoveAbility(genLastSpellCaster, FOOD_ON)
endfunction
private function FoodOff takes nothing returns nothing
set town[GetUnitUserData(genLastSpellCaster)].autoFeed = false
call UnitAddAbility(genLastSpellCaster, FOOD_ON)
call UnitRemoveAbility(genLastSpellCaster, FOOD_OFF)
endfunction
private function Init takes nothing returns nothing
local trigger t1 = CreateTrigger()
local trigger t2 = CreateTrigger()
local trigger t3 = CreateTrigger()
call TriggerAddAction(t1, function FoodOn)
call TriggerAddAction(t2, function FoodOff)
call TriggerAddAction(t3, function AddToogleOnRemove)
call TrgRegisterGenericSpellFinish(t1, FOOD_ON)
call TrgRegisterGenericSpellFinish(t2, FOOD_OFF)
call TrgRegisterGenericSpellFinish(t3, CITY_MORPH_1)
set t1 = null
set t2 = null
set t3 = null
endfunction
endscope