Dummy Leak

zepho

New Member
Reaction score
0
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 :p

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 = 'A01H'
private constant integer DUMMY_ABILITY_ID = 'A02X'
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,'Arav')
call UnitRemoveAbility(.dummy,'Arav')
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),'u000',.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,'u000',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),'u005',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. :D
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
It looks like an indexing problem. Right here:
JASS:
set .count = .count - 1
if .count > 0 then
    set .array<i> = .array[count]
    set i = i - 1
else 
endif</i>

If you have a stack of instances:
1 - 2 - 3 - 4 - 5; count = 5
And deallocate index 2:
count = 4
array[2] = array[4]
thus:
1 - 4 - 3 - 4
Which leaves out 5. To fix that, you have to set it to the last before decrementing:
JASS:
set .array<i> = .array[count]
set .count = .count - 1
set i = i - 1</i>
 

zepho

New Member
Reaction score
0
Oh I see. But I fixed it already, the timer thingy seemed to have a problem. But Ill check that one too. :) Thanks btw.
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
Nevermind, you can probably ignore my post. I just realized that you start at 0 and count is always 1 more than your highest index, so you have it right in your post. Guess I was sleepy.

Glad you got it fixed though.

P.S. You should place your functions above where you call it from (if it is feasible). Otherwise vJASS will generate extra garbage code in order to run it properly. ex: move Loop above Start. It may seem trivial, but you can sometimes end up with copies of functions (which adds a decent amount of size to the war3map.j and you will often end up with prototype triggers. vJASS doesn't automatically reorder the methods.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top