- Joined
- Oct 11, 2012
- Messages
- 711
Hi all, I am making a spell that does periodical damage to a group of units. My code is like this:
Apparently, this spell is not MUI. I have two questions:
First, regardless of efficiency, how to make it MUI?
Second, how to make it more efficient?
Thanks a lot.
JASS:
globals
unit XZGH_unit=null
hashtable hash=InitHashtable()
real counter
constant real period=1.
constant real duration=10.
endglobals
function callback takes nothing returns nothing
local group g=LoadGroupHandle(hash,GetHandleId(XZGH_unit),StringHash("group"))
local unit u
local timer t=GetExpiredTimer()
if counter<=0 then
call PauseTimer(t)
call DestroyTimer(t)
else
loop
set u=FirstOfGroup(g)
exitwhen u==null
call GroupRemoveUnit(g,u)
call UnitDamageTarget(XZGH_unit,u,100.,true,false,ATTACK_TYPE_MAGIC,DAMAGE_TYPE_MAGIC,null)
endloop
call FlushChildHashtable(hash,GetHandleId(XZGH_unit))
call DestroyGroup(g)
set counter=duration-period
endif
set g=null
set t=null
endfunction
function actions takes nothing returns boolean
local group g=CreateGroup()
local real x=GetSpellTargetX()
local real y=GetSpellTargetY()
local timer t=CreateTimer()
if GetSpellAbilityId() == 'A621' then
set XZGH_unit=GetTriggerUnit()
call GroupEnumUnitsInRange(g,x,y,800.,null)
call SaveGroupHandle(hash,GetHandleId(XZGH_unit),StringHash("group"),g)
set counter=duration
call TimerStart(t,period,true,function callback)
endif
set g=null
set t=null
return false
endfunction
function InitTrig_XZGHui takes nothing returns nothing
local trigger t=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition(t, Condition(function actions))
set t=null
endfunction
Apparently, this spell is not MUI. I have two questions:
First, regardless of efficiency, how to make it MUI?
Second, how to make it more efficient?
Thanks a lot.
Last edited: