- Joined
- Jul 28, 2008
- Messages
- 211
I was following a tutorial on how to make a knockback, and I did it but it isn't working. I didn't do all of it the way I wanted cuz I wanted to follow the tutorial. Made a mistake somewhere, and I'm tired and sleepy so I don't have time to check it today. Could someone check it and tell me where I'm wrong?
I don't want to Copy & Paste it from the tutorial, cuz I wouldn't learn anything then.
Thanks in advance!
I don't want to Copy & Paste it from the tutorial, cuz I wouldn't learn anything then.
Thanks in advance!

JASS:
scope Knockback initializer Init
globals
item It = CreateItem('ciri', 0, 0)
endglobals
////////////////////Vexorian's Check Pathability////////////////////
function CheckPathabilityTrickGet takes nothing returns nothing
set bj_rescueChangeColorUnit = bj_rescueChangeColorUnit or (GetEnumItem()!=bj_itemRandomCurrentPick)
endfunction
function CheckPathabilityTrick takes real x, real y returns boolean
local integer i = 30
local real X
local real Y
local rect r
call SetItemPosition(It, x, y)
set X = GetItemX(It) - x
set Y = GetItemY(It) - y
if X * X + Y * Y <= 100 then
return true
endif
set r = Rect(x - i, y - i, x + i, y + i)
set bj_rescueChangeColorUnit = false
call EnumItemsInRect(r, null, function CheckPathabilityTrickGet)
call RemoveRect(r)
set r = null
return bj_rescueChangeColorUnit
endfunction
function CheckPathability takes real x, real y returns boolean
local boolean b = CheckPathabilityTrick(x,y)
call SetItemVisible(It,false)
return b
endfunction
///////////////////////////////////////////////////////////////////
private struct Knockback
unit target
real d1
real d2
real sin
real cos
real r
string efect
endstruct
function Knockback_TreeFilter takes nothing returns boolean
local integer d = GetDestructableTypeId(GetFilterDestructable())
return d == 'ATtr' or d == 'BTtw' or d == 'KTtw' or d == 'YTft' or d == 'JTct' or d == 'YTst' or d == 'YTct' or d == 'YTwt' or d == 'JTwt' or d == 'JTwt' or d == 'FTtw' or d == 'CTtr' or d == 'ITtw' or d == 'NTtw' or d == 'OTtw' or d == 'ZTtw' or d == 'WTst' or d == 'LTlt' or d == 'GTsh' or d == 'Xtlt' or d == 'WTtw' or d == 'Attc' or d == 'BTtc' or d == 'CTtc' or d == 'ITtc' or d == 'NTtc' or d == 'ZTtc'
endfunction
function Knockback_KillTree takes nothing returns nothing
call KillDestructable(GetEnumDestructable())
endfunction
globals
timer Timer = CreateTimer()
boolexpr filter
Knockback array ar
integer Total = 0
constant real Interval = 0.04
endglobals
private function Loop takes nothing returns nothing
local Knockback knock
local integer i = 0
local real x
local real y
local rect r
loop
exitwhen i >= Total
set knock = ar[i]
set x = GetUnitX(knock.target) + knock.d1 * knock.cos
set y = GetUnitY(knock.target) + knock.d1 * knock.sin
if knock.r != 0 then
set r = Rect(x - knock.r, y - knock.r, x + knock.r, y + knock.r)
call EnumDestructablesInRect(r, filter, function Knockback_KillTree)
call RemoveRect(r)
endif
if CheckPathability(x, y) then
call SetUnitX(knock.target, x)
call SetUnitY(knock.target, y)
call DestroyEffect(AddSpecialEffect(knock.efect, x, y))
endif
set knock.d1 = knock.d1 - knock.d2
if knock.d1 <= 0 or not CheckPathability(x, y) then
set ar[i] = ar[Total - 1]
set Total = Total - 1
call PauseUnit(knock.target, false)
call knock.destroy()
endif
set i = i + 1
endloop
if Total == 0 then
call PauseTimer(Timer)
endif
endfunction
function KnockbackUnit takes unit target, real distance, real angle, real duration, real radius, string efect returns nothing
local Knockback kd = Knockback.create()
local integer q = R2I(duration / Interval)
set kd.target = target
set kd.d1 = 2 * distance / (q + 1)
set kd.d2 = kd.d1 / q
set kd.cos = Cos(angle * bj_DEGTORAD)
set kd.sin = Sin(angle * bj_DEGTORAD)
set kd.r = radius
set kd.efect = efect
call PauseUnit(target, true)
if Total == 0 then
call TimerStart(Timer, Interval, true, function Loop)
endif
set ar[Total] = kd
set Total = Total + 1
endfunction
private function Init takes nothing returns nothing
set filter = Filter(function Knockback_TreeFilter)
endfunction
endscope