Hi,
So, i made my first "spell" which uses timer. Basically, its just a suicide spell that deals AoE damage. It uses a 0.00 second timer because otherwise the unit will die before finishing the cast and it wont start the cooldown.
The ability itself works fine, but my code seems a bit long for such a simple ability. Any suggestions? What could be improved?
Thanks
So, i made my first "spell" which uses timer. Basically, its just a suicide spell that deals AoE damage. It uses a 0.00 second timer because otherwise the unit will die before finishing the cast and it wont start the cooldown.
The ability itself works fine, but my code seems a bit long for such a simple ability. Any suggestions? What could be improved?
Thanks

JASS:
struct Suicide
unit u_pointer
integer id_pointer
endstruct
constant function DamageOutputSuicide takes integer id returns real
if id == 'A010' then
return 500.00
else
return 300.00
endif
endfunction
constant function RadiusSuicide takes integer id returns real
if id == 'A010' then
return 350.00
else
return 220.00
endif
endfunction
function Suicide_Timed takes nothing returns nothing
local timer t = GetExpiredTimer()
local Suicide data = GetTimerData(t)
local unit u = data.u_pointer
local unit l
local integer id = data.id_pointer
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local group g = CreateGroup()
local effect e
call GroupEnumUnitsInRange(g, x, y, RadiusSuicide(id), null)
loop
set l = FirstOfGroup(g)
exitwhen l == null
if (ValidTarget(l, GetOwningPlayer(u), true, false) == true) then
call UnitDamageTarget(u, l, DamageOutputSuicide(id), true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
endif
call GroupRemoveUnit(g, l)
endloop
call UnitDamageTarget(u, u, 1000.00, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
set e = AddSpecialEffect("Objects\\Spawnmodels\\Other\\NeutralBuildingExplosion\\NeutralBuildingExplosion.mdl", x, y)
call DestroyGroup(g)
call DestroyEffect(e)
call ReleaseTimer(t)
set u = null
set g = null
set e = null
set t = null
endfunction
function Trig_Suicide_Conditions takes nothing returns boolean
local Suicide data
local timer t
local integer id = GetSpellAbilityId()
if (id == 'A00R') or (id == 'A010') then
set data = Suicide.create()
set t = NewTimer()
set data.u_pointer = GetTriggerUnit()
set data.id_pointer = id
call SetTimerData(t, data)
call TimerStart(t, 0.00, false, function Suicide_Timed)
set t = null
endif
return false
endfunction
//===========================================================================
function InitTrig_Suicide takes nothing returns nothing
local integer index
set index = 0
set gg_trg_Suicide = CreateTrigger()
loop
call TriggerRegisterPlayerUnitEvent(gg_trg_Suicide, Player(index), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
set index = index + 1
exitwhen index == bj_MAX_PLAYER_SLOTS
endloop
call TriggerAddCondition(gg_trg_Suicide, Condition(function Trig_Suicide_Conditions))
endfunction