- Joined
- Feb 1, 2010
- Messages
- 16
I made this spell some days ago and I don't know if the local group in this code leaks. The main question is do local groups "destroy" themselves at the end of the function or I need to manually null them?
I would appreciate any help.
Here is the code:
I would appreciate any help.
Here is the code:
JASS:
function HolyGround_SpellID takes nothing returns integer
return 'A001'
endfunction
function HolyGround_Main takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local unit c = LoadUnitHandle(udg_HolyGround_Hash, id, 1)
local unit u
local real x = LoadReal(udg_HolyGround_Hash, id, 2)
local real y = LoadReal(udg_HolyGround_Hash, id, 3)
local integer duration = LoadInteger(udg_HolyGround_Hash, id, 4)
local integer level = GetUnitAbilityLevel(c, HolyGround_SpellID())
local real heal = 20+(level*20)
local real damage = 10+(level*10)
local group g = CreateGroup()
//==================================================================
call SaveInteger(udg_HolyGround_Hash, id, 4, duration+1)
call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Other\\Andt\\Andt.mdl", x, y))
call GroupEnumUnitsInRange(g, x, y, 600.00, null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
if not IsUnitType(u, UNIT_TYPE_STRUCTURE) and not IsUnitType(u, UNIT_TYPE_DEAD) and IsUnitAlly(u, GetOwningPlayer(c)) and not IsUnitType(u, UNIT_TYPE_MAGIC_IMMUNE) then
call SetUnitState(u, UNIT_STATE_LIFE, GetUnitState(u, UNIT_STATE_LIFE)+heal)
endif
if not IsUnitType(u, UNIT_TYPE_STRUCTURE) and not IsUnitType(u, UNIT_TYPE_DEAD) and IsUnitEnemy(u, GetOwningPlayer(c)) and not IsUnitType(u, UNIT_TYPE_MAGIC_IMMUNE) then
call UnitDamageTarget(c, u, damage, false, false, null, DAMAGE_TYPE_MAGIC, null)
endif
call GroupRemoveUnit(g, u)
endloop
if duration == 5 then
call DestroyTimer(t)
set g = null
call FlushChildHashtable(udg_HolyGround_Hash, id)
endif
endfunction
function HolyGround_Start takes nothing returns boolean
local timer t = CreateTimer()
local integer id = GetHandleId(t)
local unit c = GetTriggerUnit()
local integer duration = 1
local real x = GetSpellTargetX()
local real y = GetSpellTargetY()
//==================================================================
if GetSpellAbilityId() == HolyGround_SpellID() then
call SaveUnitHandle(udg_HolyGround_Hash, id, 1, c)
call SaveReal(udg_HolyGround_Hash, id, 2, x)
call SaveReal(udg_HolyGround_Hash, id, 3, y)
call SaveInteger(udg_HolyGround_Hash, id, 4, duration)
call TimerStart(t, 1.00, true, function HolyGround_Main)
return true
endif
return false
endfunction
//===========================================================================
function InitTrig_Holy_Ground takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Condition(function HolyGround_Start))
set udg_HolyGround_Hash = InitHashtable()
endfunction