Hey I have some spell here. What it does is it fires an arcing axe missile to a point then when it lands, it explodes dealing damage and some slow stuff. My problem is when I fire this spell consecutively, the other missiles are stuck in the air and when I launch another one, the entire trigger doesn't work at all. All it does is create a dummy unit. Please help me
I think I have a problem with cleaning the dummy units when the trigger ends.
EDIT: I knew what caused me an error. The PauseTimer(.time) should have been placed in the else function. Thanks btw.
JASS:
scope DemolitionAxe initializer DemolitionAxe_Init // Replace scopename by name of trigger
globals
private constant real TIMEOUT = 0.03125
private constant integer SPELL_ABILITY_ID = 039;A01H039;
private constant integer DUMMY_ABILITY_ID = 039;A02X039;
private constant real SPEED = 800.
private constant real DAMAGE = 50.
private constant real RADIUS = 345. // AOE
private constant string MODEL = "Abilities\\Weapons\\RexxarMissile\\RexxarMissile.mdl"
private constant string EFFECT = "abilities\\weapons\\DemolisherMissile\\DemolisherMissile.mdl"
private constant string D_ATTACH_POINT = "chest"
private constant string T_ATTACH_POINT = "origin"
endglobals
private struct data
// Moving
unit caster
unit dummy
unit dummy2
effect e
//Math
real x
real y
real tx
real ty
real ox
real oy
real sin
real cos
real dist
real odist
real tdist
real v
real height
real angle
real damage
group damaged
static integer count=0
static group g = CreateGroup()
static timer time = CreateTimer()
static filterfunc filter
static data temp
static data array array
static method Start takes unit caster , unit dummy , location cast_loc returns data
local data this = data.allocate()
// Maths
local real x = GetUnitX(dummy)
local real y = GetUnitY(dummy)
local real tx = GetLocationX(cast_loc)
local real ty = GetLocationY(cast_loc)
local real dx = tx-x
local real dy = ty-y
local real angle = Atan2(dy,dx)
set .caster = caster
set .dummy = dummy
set .dummy2 = dummy2
set .cos = Cos(angle)
set .sin = Sin(angle)
set .dist = SquareRoot(dx*dx+dy*dy)
set .ox = GetUnitX(caster)
set .oy = GetUnitY(caster)
set .x = x
set .y = y
set .tx = tx
set .ty = ty
set .angle = angle
set .v = SPEED*TIMEOUT
set .height = 0.
set .odist = SquareRoot((.tx-.ox)*(.tx-.ox)+(.ty-.oy)*(.ty-.oy))
call RemoveLocation(cast_loc)
// Damage Formula
set .damage = DAMAGE+125.*GetUnitAbilityLevel(caster,SPELL_ABILITY_ID)
call SetUnitFlyHeight(.dummy,.height,0.)
set .e = AddSpecialEffectTarget(MODEL,.dummy,D_ATTACH_POINT)
call RemoveLocation(cast_loc)
call UnitAddAbility(.dummy,039;Arav039;)
call UnitRemoveAbility(.dummy,039;Arav039;)
call SetUnitScale(.dummy,2.5,2.5,2.5)
// Groups
if .damaged == null then
set .damaged = CreateGroup()
else
call GroupClear(.damaged)
call GroupClear(.g)
endif
// Timer
if .count == 0 then
call TimerStart(time,TIMEOUT,true,function data.Loop)
endif
set .array[.count] = this
set .count = .count + 1
// Return
return this
endmethod
private static method Loop takes nothing returns nothing
local integer i = 0
local data this
loop
exitwhen i>=.count
set this=.array
// Set X&Y
set .x = .x + (.v * .cos)
set .y = .y + (.v * .sin)
set .dist = SquareRoot((.tx-GetUnitX(.dummy))*(.tx-GetUnitX(.dummy))+(.ty-GetUnitY(.dummy))*(.ty-GetUnitY(.dummy))) - .v
set .tdist = SquareRoot((GetUnitX(.dummy)-.ox)*(GetUnitX(.dummy)-.ox)+(GetUnitY(.dummy)-.oy)*(GetUnitY(.dummy)-.oy)) - .v
// Move
call SetUnitX(.dummy,.x)
call SetUnitY(.dummy,.y)
if .height<=.odist/8 then
set .height = 5. + (.tdist/(.odist/2)) * (.odist/8)
endif
if .height>.odist/8 then
set .height = (.dist/(.odist/2)) * (.odist/8)
endif
call SetUnitFlyHeight(.dummy,.height,0.)
set .temp=this
if .dist<=0. then
// Resetting Values and Destroy Struct
call PauseTimer(.time)
call SetUnitFlyHeight(.dummy,0.,0.)
set dummy2 = CreateUnit(GetOwningPlayer(.caster),039;u000039;,.x,.y,.angle)
call UnitAddAbility(.dummy2,DUMMY_ABILITY_ID)
call SetUnitAbilityLevel(.dummy2,DUMMY_ABILITY_ID,GetUnitAbilityLevel(.caster,SPELL_ABILITY_ID))
call IssueImmediateOrder(.dummy2,"thunderclap")
call GroupEnumUnitsInRange(.g,.x,.y,RADIUS,.filter)
call RemoveUnit(.dummy)
call DestroyEffect(.e)
call SetUnitScale(.dummy2,2.,2.,1.)
call DestroyEffect(AddSpecialEffectTarget(EFFECT,.dummy2,D_ATTACH_POINT))
call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Orc\\WarStomp\\WarStompCaster.mdl",.dummy2,"origin"))
call UnitApplyTimedLife(.dummy2,039;u000039;,1.)
set .e=null
call .destroy()
set .count=.count-1
if .count>0 then
set .array=.array[.count]
set i=i-1
else
endif
endif
set i=i+1
endloop
endmethod
private static method Damage takes nothing returns boolean
local unit temp = GetFilterUnit()
if not IsUnitType(temp,UNIT_TYPE_STRUCTURE) and IsUnitEnemy(temp, GetOwningPlayer(.temp.caster)) and GetWidgetLife(temp)>=.405 and not IsUnitInGroup(temp,.temp.damaged) then
call GroupAddUnit(.temp.damaged,temp)
call UnitDamageTarget(.temp.caster,temp,.temp.damage,false,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_UNIVERSAL,null)
endif
set temp=null
return false
endmethod
private static method onInit takes nothing returns nothing
set .filter = Filter(function data.Damage)
endmethod
endstruct
function DemolitionAxe_Actions takes nothing returns nothing
local data dat = data.create()
local unit caster = GetTriggerUnit()
local location cast_loc = GetSpellTargetLoc()
local real x = GetUnitX(caster)
local real y = GetUnitY(caster)
local real dx = GetLocationX(cast_loc)-x
local real dy = GetLocationY(cast_loc)-y
local real angle = bj_RADTODEG*Atan2(dy,dx)
local unit dummy = CreateUnit(GetOwningPlayer(caster),039;u005039;,x,y,angle)
call data.Start(caster,dummy,cast_loc)
set caster=null
set dummy=null
set cast_loc=null
endfunction
private function DemolitionAxe_Init takes nothing returns nothing
local trigger t = CreateTrigger()
call GT_RegisterStartsEffectEvent(t,SPELL_ABILITY_ID)
call TriggerAddAction(t, function DemolitionAxe_Actions)
set t = null
endfunction
endscope
I think I have a problem with cleaning the dummy units when the trigger ends.
EDIT: I knew what caused me an error. The PauseTimer(.time) should have been placed in the else function. Thanks btw.