- Joined
- Oct 11, 2012
- Messages
- 711
Hi all. I am learning allocate and deallocate... Since I cannot find a decent tutorial, I need help from you guys. Thanks.
JASS:
struct TESTER
static unit FOOTMAN = null
static timer t
static boolean b = false
private static TESTER data
static method onCollide takes Missile new, unit justHit returns boolean
if IsUnitEnemy(justHit, GetOwningPlayer(new.source)) then
call UnitDamageTarget(new.source, justHit, 10., true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_DEMOLITION, null)
//call DestroyEffect(AddSpecialEffectTarget(TERTIARY_COLLIDEFX, justHit, TERTIARY_ATTACHPOINT))
endif
return false
endmethod
implement MissileStruct
static method onExpire takes nothing returns nothing
local thistype this=thistype(TESTER.data)
local real x = GetUnitX(FOOTMAN)
local real y = GetUnitY(FOOTMAN)
local real a = GetRandomReal(-bj_PI,bj_PI)
local Missile new
if GetUnitState(FOOTMAN,UNIT_STATE_LIFE)>0.405 then
set new= Missile.create(x,y,65,x+1000*Cos(a),y+1000*Sin(a),0)
set new.speed=10
set new.model="Abilities\\Weapons\\VengeanceMissile\\VengeanceMissile.mdl"
set new.height=100
set new.source=FOOTMAN
set new.collision=80
call launch(new)
else
call PauseTimer(TESTER.t)
call this.deallocate() //deallocating here
set TESTER.t=null
set TESTER.data=null
endif
endmethod
static method esc takes nothing returns boolean
local thistype this=thistype.allocate() //allocating here
if b then
call PauseTimer(TESTER.t)
call this.deallocate() //deallocating here
set TESTER.t=null
set TESTER.data=null
else
set TESTER.t=CreateTimer()
set TESTER.data=this
call TimerStart(t,0.05,true,function thistype.onExpire)
endif
set b = not b
return false
endmethod
static method onInit takes nothing returns nothing
local trigger trig=CreateTrigger()
call TriggerRegisterPlayerEvent(trig,Player(0),EVENT_PLAYER_END_CINEMATIC)
call TriggerAddCondition(trig,Condition(function thistype.esc))
set FOOTMAN=CreateUnit(Player(0),'hfoo',0,0,270)
endmethod
endstruct