bOb666777
Stand against the ugly world domination face!
- Reaction score
- 117
It seems like it could lag if I put a few spells using this system:
In case you don't get it, what it does is whenever a unit casts the spell, it sets a global integer + 1 and stores the struct in an array, then the timer loops between all 8191 indexes of that array, running the ones that have a value. Can that be laggy?
JASS:
globals
Movespell array m
integer movespellcount = 0
endglobals
struct Movespell
unit target
unit caster
integer level
endstruct
function Trig_MoveSpell_Conditions takes nothing returns boolean
return GetSpellAbilityId() == SpellId()
endfunction
function callback takes nothing returns nothing
local Movespell data
local integer structloop = 0
loop
exitwhen structloop == 8191
if (m[structloop] != 0) then
set data = m[structloop]
//Actions here
endif
set structloop = structloop + 1
endloop
endfunction
function Trig_MoveSpell_Actions takes nothing returns nothing
local Movespell data = Movespell.create()
local unit u = GetTriggerUnit()
local unit target = GetSpellTargetUnit()
set data.level = GetUnitAbilityLevel(u, SpellId())
set data.caster = u
set data.target = target
if (movespellcount < 8191) then
set m[movespellcount] = data
set movespellcount = movespellcount + 1
else
set movespellcount = 0
loop
exitwhen m[movespellcount] != 0 or movespellcount == 8191
set movespellcount = movespellcount + 1
endloop
if (movespellcount == 8191) then
call BJDebugMsg("Too many instances running, try again later.")
else
set m[movespellcount] = data
endif
endif
set u = null
set target = null
endfunction
//===========================================================================
function InitTrig_MoveSpell takes nothing returns nothing
local trigger t = CreateTrigger( )
local timer time = CreateTimer()
call TimerStart(time, 0.02, true, function callback)
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( t, Condition( function Trig_MoveSpell_Conditions ) )
call TriggerAddAction( t, function Trig_MoveSpell_Actions )
endfunction
In case you don't get it, what it does is whenever a unit casts the spell, it sets a global integer + 1 and stores the struct in an array, then the timer loops between all 8191 indexes of that array, running the ones that have a value. Can that be laggy?