TriggerHappy
...
- Reaction score
- 341
Alright, I took another shot at this.
Basically it's a framework that runs all spells off of the same trigger and event reducing the handle count.
Is it efficient and useful?
Example;
Basically it's a framework that runs all spells off of the same trigger and event reducing the handle count.
Is it efficient and useful?
JASS:
library SpellRegister initializer onInit
globals
private constant trigger TRIGGER = CreateTrigger()
private hashtable HASH = InitHashtable()
endglobals
struct spell
conditionfunc action
static method create takes integer spellid, code func returns spell
local spell s = spell.allocate()
if func != null then
set s.action = Condition(func)
endif
call SaveInteger(HASH, spellid, 0, s)
return s
endmethod
endstruct
private function DoStuff takes nothing returns nothing
local spell s
local integer id = GetSpellAbilityId()
if HaveSavedInteger(HASH, id, 0) then
set s = LoadInteger(HASH, id, 0)
if s.action != null then
call TriggerAddCondition(TRIGGER, s.action)
call TriggerEvaluate(TRIGGER)
call TriggerClearConditions(TRIGGER)
endif
endif
endfunction
private function onInit takes nothing returns nothing
call TriggerRegisterAnyUnitEventBJ(TRIGGER, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddAction(TRIGGER, function DoStuff)
endfunction
endlibrary
Example;
JASS:
scope Spell initializer onInit
private function Actions takes nothing returns nothing
call BJDebugMsg(GetObjectName(GetSpellAbilityId()))
endfunction
private function onInit takes nothing returns nothing
call spell.create(039;AHds039;, function Actions)
call spell.create(039;AHtc039;, function Actions)
endfunction
endscope