- Joined
- Apr 6, 2008
- Messages
- 760
hi peps i've had some problems the last few days and it seems like i cannot solves this bug by myself. ok here's the problem when i cast the spell one time and it works perfectly but when i cast it a few times (3-4) it creates aditional dummy units at random locations when they are moving in or out :/. anyone know why?
JASS:
scope Spell initializer Init
globals
private constant integer Abil_id = 'A000'
private constant integer Dum_id = 'h000'
private constant integer NumberOfOrbs = 6
private constant real distance = 500.
private constant real time = 2.
endglobals
private struct Data
unit c
unit array dum[NumberOfOrbs]
real angle = 0
real dist = distance
real movedist
real time = time
real incrangle
real Maxdist = distance
integer Nr = NumberOfOrbs
timer t
method onDestroy takes nothing returns nothing
local integer a = 0
loop
exitwhen a > .Nr
call RemoveUnit(.dum[a])
set a = a + 1
endloop
call DestroyTimer(.t)
endmethod
endstruct
private function filter takes nothing returns boolean
local Data dat = GetTimerStructA(GetExpiredTimer())
local unit f = GetFilterUnit()
local boolean ok = GetWidgetLife(f) > .405 and IsUnitEnemy(f,GetOwningPlayer(dat.c)) and not IsUnitType(f,UNIT_TYPE_MAGIC_IMMUNE) and not IsUnitType(f,UNIT_TYPE_STRUCTURE)
set f = null
return ok
endfunction
private function out takes nothing returns nothing
local Data dat = GetTimerStructA(GetExpiredTimer())
local integer a = 0
local real x = GetUnitX(dat.c)
local real y = GetUnitY(dat.c)
local real angle = 0
set dat.dist = dat.dist + dat.movedist
set dat.angle = dat.angle + 10
set angle = dat.angle
if dat.dist < dat.Maxdist then
loop
exitwhen a > dat.Nr
call SetUnitX(dat.dum[a],x+dat.dist*Cos(angle*3.14159/180))
call SetUnitY(dat.dum[a],y+dat.dist*Sin(angle*3.14159/180))
set a = a + 1
set angle = angle + dat.incrangle
endloop
else
call PauseTimer(dat.t)
call dat.destroy()
endif
endfunction
private function In takes nothing returns nothing
local Data dat = GetTimerStructA(GetExpiredTimer())
local integer a = 0
local real x = GetUnitX(dat.c)
local real y = GetUnitY(dat.c)
local real angle = 0
set dat.dist = dat.dist - dat.movedist
set dat.angle = dat.angle + 10
set angle = dat.angle
if dat.dist > 0 then
loop
exitwhen a > dat.Nr
call SetUnitX(dat.dum[a],x+dat.dist*Cos(angle*3.14159/180))
call SetUnitY(dat.dum[a],y+dat.dist*Sin(angle*3.14159/180))
set a = a + 1
set angle = angle + dat.incrangle
endloop
else
call PauseTimer(dat.t)
call TimerStart(dat.t,.035,true,function out)
endif
endfunction
private function Actions takes nothing returns nothing
local Data dat = Data.create()
local integer a = 0
local player s = GetOwningPlayer(GetTriggerUnit())
local real x
local real y
local real angle = 0
set dat.c = GetTriggerUnit()
set x = GetUnitX(dat.c)
set y = GetUnitY(dat.c)
set dat.incrangle = 360/dat.Nr
set dat.t = CreateTimer()
set dat.time = time
set dat.Maxdist = distance
set dat.movedist = (dat.Maxdist/dat.time)/(1./.035)
loop
exitwhen a > dat.Nr
set dat.dum[a] = CreateUnit(s,Dum_id,x+dat.Maxdist*Cos(angle*3.14159/180),y+dat.Maxdist*Sin(angle*3.14159/180),0.)
set a = a + 1
set angle = angle + dat.incrangle
endloop
call SetTimerStructA(dat.t,dat)
call TimerStart(dat.t,.035,true,function In)
endfunction
private function conds takes nothing returns boolean
return GetSpellAbilityId()==Abil_id
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddAction(t,function Actions)
call TriggerAddCondition(t,Filter(function conds))
endfunction
endscope
Last edited: