Mã:
scope Arrows initializer Ar
globals
private integer idSpell = 'A001'
private integer idDummy = 'h000'
endglobals
private struct data
unit hero
unit dummy
location castloc
real angle
integer tick
timer t
endstruct
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == idSpell
endfunction
private function Knockback takes nothing returns nothing
local timer t = GetExpiredTimer()
local data d = GetTimerData(t)
local group g = CreateGroup()
local unit temp
local location loc
local boolean check
if d.tick < 150 then
set loc = PolarProjectionBJ(d.castloc,50*d.tick,d.angle)
call SetUnitPositionLoc(d.dummy,loc)
call GroupEnumUnitsInRangeOfLoc(g,loc,100,null)
set temp =FirstOfGroup(g)
loop
exitwhen temp == null
if IsUnitEnemy(temp , GetOwningPlayer(d.dummy)) then
call SetUnitPositionLoc(temp,loc)
call UnitDamageTargetBJ(d.dummy,temp,10, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
call GroupRemoveUnit(g,temp)
set temp = FirstOfGroup(g)
endif
call GroupRemoveUnit(g,temp)
set temp = FirstOfGroup(g)
endloop
call DestroyGroup(g)
set temp = null
call RemoveLocation(loc)
else
call RemoveUnit(d.dummy)
call ReleaseTimer(d.t)
call d.destroy()
endif
call DestroyGroup(g)
set t = null
set d.tick = d.tick + 1
set t = null
endfunction
private function Actions takes nothing returns nothing
local data d = data.create()
local unit hero = GetSpellAbilityUnit()
local location targloc = GetSpellTargetLoc()
local location castloc = GetUnitLoc(hero)
local real angle = AngleBetweenPoints(castloc,targloc)
set d.hero = hero
set d.castloc = castloc
set d.angle = angle
set d.dummy = CreateUnitAtLoc(GetOwningPlayer(hero),idDummy,castloc,angle)
set d.tick = 1
set d.t = NewTimer()
call SetTimerData(d.t,d)
call TimerStart(d.t,0.02,true,function Knockback )
[B] call RemoveLocation(targloc)
call RemoveLocation(castloc)
set hero = null
set targloc = null
set castloc = null[/B]
endfunction
//===========================================================================
private function Ar takes nothing returns nothing
local trigger t = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( t, Condition( function Conditions ) )
call TriggerAddAction( t, function Actions )
set t=null
endfunction
endscope
Cái này chạy trên 1 System TimerUtils ...
Mình có thắc mắc ở cái chỗ in đậm này..
Bây giờ nếu mình không có nó thì Spell cast bình thường và không có vấn đề gì xảy ra , Unit Dummy có vị trí xuất phát ở castloc sẽ chạy ra từ đúng vị trí.
Nhưng nếu mình đặt cái lệnh để xóa leak thì khi cast spell , Unit Dummy lại có vị trí bắt đầu từ giữa bản đồ.. không hiểu vì sao lại như vậy nữa.. ai có thể giải thích dùm mình được không .. không xóa cái này Leak là 100% +_+
---------- Post added at 21:18 ---------- Previous post was at 21:16 ----------
call RemoveLocation(targloc)
call RemoveLocation(castloc)
set hero = null
set targloc = null
set castloc = null
hix.. in đậm mà nhìn nó chả có gì.. em Quote lại cái đoạn mà em nói tới ở trên