- Joined
- Dec 15, 2011
- Messages
- 1,423
I am still fairly new to JASS and I don't know much about checking all the leaks of an ability so I need help. Here is my code for a spell
So I have two questions:
Test map attached. +rep for helpers. Thanks in advance.
P/S: It also would be great if you could point out anything that is wrong with my other spells but that is optional.
EDIT: Fixed some of the minor coding bugs in the posted code. Test map is also updated.
JASS:
function Trig_Frost_Shard_Conditions takes nothing returns boolean
return ( GetSpellAbilityId() == 'A005' )
endfunction
function Frost_Shard_Effect_Periodic takes nothing returns nothing
local timer t = GetExpiredTimer()
local unit target = LoadUnitHandleBJ(0, GetHandleIdBJ(t), udg_Hashtable)
local unit dummy = LoadUnitHandleBJ(1, GetHandleIdBJ(t), udg_Hashtable)
local unit caster = LoadUnitHandleBJ(2, GetHandleIdBJ(t), udg_Hashtable)
local location l1 = GetUnitLoc (target)
local location l = GetUnitLoc (dummy)
local location l2
local real angle
if (DistanceBetweenPoints(l, l1) <= 30) then
if IsUnitAliveBJ(target) == true then
call KillUnit (dummy)
call UnitDamageTarget(caster, target, 500, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_FIRE, null)
call RemoveLocation (l1)
call RemoveLocation (l)
set l = null
set l1= null
call PauseTimer (t)
call DestroyTimer (t)
set t = null
set caster = null
set target = null
set dummy = null
else
call KillUnit (dummy)
call RemoveLocation (l1)
call RemoveLocation (l)
set l = null
set l1= null
call PauseTimer (t)
call DestroyTimer (t)
set t = null
set caster = null
set target = null
set dummy = null
endif
else
set angle = AngleBetweenPoints(l, l1)
set l2 = PolarProjectionBJ (l, 20, angle)
call SetUnitPositionLocFacingBJ(dummy, l2, angle)
call RemoveLocation (l2)
set l2 = null
endif
set target = null
set caster = null
set dummy = null
endfunction
function Frost_Shard_Effect takes unit caster, unit u, location l returns nothing
local unit dummy
local timer t = CreateTimer ()
local real angle
set angle = AngleBetweenPoints (GetUnitLoc (caster), GetUnitLoc(u))
set dummy = CreateUnitAtLoc(GetOwningPlayer(caster), 'h003', l, angle)
call SaveUnitHandleBJ(u, 0, GetHandleIdBJ(t), udg_Hashtable)
call SaveUnitHandleBJ(dummy, 1, GetHandleIdBJ(t), udg_Hashtable)
call SaveUnitHandleBJ(caster, 2, GetHandleIdBJ(t), udg_Hashtable)
call TimerStart (t, 0.02, true, function Frost_Shard_Effect_Periodic)
set l = null
set dummy = null
set caster = null
set u = null
set t = null
endfunction
function Frost_Shard_Explode takes unit caster, location l returns nothing
local timer t = GetExpiredTimer()
local group g
local unit u
set g = GetUnitsInRangeOfLocAll(1000.00, l)
loop
set u = FirstOfGroup (g)
exitwhen u == null
if IsUnitEnemy(u, GetOwningPlayer(caster)) == true and IsUnitAliveBJ(u) == true then
call Frost_Shard_Effect (caster, u, l)
endif
call GroupRemoveUnitSimple (u, g)
endloop
call DestroyGroup(g)
set g = null
set caster = null
endfunction
function Frost_Shard_Periodic takes nothing returns nothing
local trigger trig = GetTriggeringTrigger ()
local unit caster = LoadUnitHandleBJ(0, GetHandleIdBJ(trig), udg_Hashtable)
local unit target = LoadUnitHandleBJ(1, GetHandleId(trig), udg_Hashtable)
local unit dummy = LoadUnitHandleBJ(2, GetHandleId(trig), udg_Hashtable)
local location l = GetUnitLoc (dummy)
local location l1 = GetUnitLoc (target)
local location l2
local real angle
local triggeraction tga = LoadTriggerActionHandleBJ (3, GetHandleIdBJ (trig), udg_Hashtable)
if(GetTriggerEventId()==EVENT_UNIT_DEATH)then
if(GetDyingUnit() == target)then
call KillUnit (dummy)
call RemoveLocation (l)
call RemoveLocation (l1)
set l = null
set l1 = null
set caster = null
set target = null
set dummy = null
call DisableTrigger (trig)
call TriggerRemoveAction (trig, tga)
call DestroyTrigger (trig)
set tga = null
set trig = null
endif
else
if (DistanceBetweenPoints(l, l1) <= 30) then
call KillUnit (dummy)
call UnitDamageTarget(caster, target, 1000, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_FIRE, null)
if IsUnitAliveBJ (target) == false then
call Frost_Shard_Explode(caster, l1)
else
endif
call RemoveLocation (l)
call RemoveLocation (l1)
set caster = null
set target = null
set dummy = null
set l = null
set l1 = null
call DisableTrigger (trig)
call TriggerRemoveAction (trig, tga)
call DestroyTrigger (trig)
set tga = null
set trig = null
else
set angle = AngleBetweenPoints(l, l1)
set l2 = PolarProjectionBJ (l, 24, angle)
call SetUnitPositionLocFacingBJ(dummy, l2, angle)
call RemoveLocation (l2)
set l2 = null
endif
endif
endfunction
function Trig_Frost_Shard_Actions takes nothing returns nothing
local unit caster = GetTriggerUnit()
local unit target = GetSpellTargetUnit()
local unit dummy
local trigger trig = CreateTrigger ()
local location l = GetUnitLoc(caster)
local real angle
set angle = AngleBetweenPoints (GetUnitLoc (caster), GetUnitLoc(target))
set dummy = CreateUnitAtLoc(GetOwningPlayer(caster), 'h002', l, angle)
call TriggerRegisterTimerEventPeriodic(trig, 0.02)
call TriggerRegisterUnitEvent(trig, target, EVENT_UNIT_DEATH)
call SaveTriggerActionHandleBJ( TriggerAddAction( trig, function Frost_Shard_Periodic ), 3, GetHandleIdBJ (trig), udg_Hashtable)
call SaveUnitHandleBJ( caster, 0, GetHandleIdBJ(trig), udg_Hashtable )
call SaveUnitHandleBJ( target, 1, GetHandleIdBJ(trig), udg_Hashtable )
call SaveUnitHandleBJ( dummy, 2, GetHandleIdBJ(trig), udg_Hashtable )
call RemoveLocation (l)
set l = null
set caster = null
set target = null
set dummy = null
set trig = null
endfunction
//===========================================================================
function InitTrig_Frost_Shard takes nothing returns nothing
set gg_trg_Frost_Shard = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Frost_Shard, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_Frost_Shard, Condition( function Trig_Frost_Shard_Conditions ) )
call TriggerAddAction( gg_trg_Frost_Shard, function Trig_Frost_Shard_Actions )
endfunction
So I have two questions:
- Does this skill leak? And if it leaks, where?
- Do I need to clear the hashtable or will the values (except for locations and unit groups) be recycled?
Test map attached. +rep for helpers. Thanks in advance.
P/S: It also would be great if you could point out anything that is wrong with my other spells but that is optional.
EDIT: Fixed some of the minor coding bugs in the posted code. Test map is also updated.
Last edited: