- Joined
- Mar 8, 2009
- Messages
- 360
I made a simple spell for my tower defense. But i want to know that my trigger is ok, so i can avoid things i did wrong in this spell next time i make spell.
This is code(added some documentation for easier reading):
(it compiles and works perfectly the way i want it when i test my map)
My main question is what locals should be nulled to prevent leaking. I'm also not completely sure i properly destroyed timer and struct.
This is code(added some documentation for easier reading):
JASS:
//****************************************************************************
//*
//* Spell made by DarkWatcher
//*
//* Requires TimerUtils made by Vexorian ([url]www.wc3c.net[/url])
//*
//* Bombard Tower ability (passive)
//* Spell description:
//*
//* Excitement
//*
//* When the dwarfs inside the bombard tower kill a target, they get very
//* excited. Making them imprudent, pressing the "fire AA rocket" button.
//* This shoots a rocket in a occasional group of passing flying machines.
//* Each crashing flying machine deals 300 damage. The dwarfs don't get
//* excited when a crashing flying machine kills a unit.
//*
//****************************************************************************
scope Excitement initializer Init
globals
//Number of flying machines crashing
private constant integer MACHINES = 3
//The radius of the area where flying machines can crash(rectangular area)
private constant real AOE = 300.00
//time between start flying machine crash and crashing damage
private constant real timerTime = 1.30
//Special effect when flying machine crashes
private constant string crashEffect = "Abilities\\Spells\\Orc\\WarStomp\\WarStompCaster.mdl"
endglobals
//Killing player, position of crashing flying machine
private struct Data
real cX
real cY
player id
static method create takes player id, real x, real y returns Data
local Data data = Data.allocate()
set data.id = id
set data.cX = x
set data.cY = y
return data
endmethod
endstruct
//Damage area where flying machine crashes
private function damageArea takes nothing returns nothing
local Data place = GetTimerData(GetExpiredTimer())
local unit dummy = CreateUnit( place.id, 'h009', place.cX, place.cY, bj_UNIT_FACING)
call UnitAddAbility(dummy, 'A01E')
call IssueImmediateOrder(dummy, "thunderclap")
call DestroyEffect(AddSpecialEffect(crashEffect, place.cX, place.cY))
call place.destroy()
call ReleaseTimer(GetExpiredTimer())
set dummy = null
endfunction
//Create special effect on killer, create crashing flying machine and launch timer
private function Actions takes nothing returns nothing
local unit dummy
local real deadX = GetUnitX(GetTriggerUnit())
local real deadY = GetUnitY(GetTriggerUnit())
local real angle
local integer index = 1
local timer time
local player id = GetOwningPlayer(GetKillingUnit())
local Data place
call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\Flare\\FlareCaster.mdl", GetKillingUnit(), "head"))
loop
exitwhen index > MACHINES
set angle = GetRandomReal(0, bj_DEGTORAD*360)
set place = Data.create( GetOwningPlayer(GetKillingUnit()), (deadX + GetRandomReal(0, AOE)*Cos(angle)), (deadY + GetRandomReal(0, AOE)*Sin(angle)))
set dummy = CreateUnit( place.id, 'u004', place.cX, place.cY, bj_UNIT_FACING)
call SetUnitFlyHeight( dummy, 100.00, 0.00 ) //lower flying height so flying machine hits ground with dead animation
call KillUnit( dummy )
set time = NewTimer()
call TimerStart(time, timerTime, false, function damageArea)
call SetTimerData(time, place)
set index = index + 1
endloop
set dummy = null
set time = null
endfunction
//Check killing unit to have Excitement ability
private function Conditions takes nothing returns boolean
return GetUnitAbilityLevel(GetKillingUnit(), 'A01A') == 1
endfunction
//Initializer
private function Init takes nothing returns nothing
local trigger gg_trg_Excitement = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Excitement, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( gg_trg_Excitement, Condition( function Conditions ) )
call TriggerAddAction( gg_trg_Excitement, function Actions )
endfunction
endscope
My main question is what locals should be nulled to prevent leaking. I'm also not completely sure i properly destroyed timer and struct.
Last edited: