• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Knockback Doesn't Work @_@

Status
Not open for further replies.
Level 12
Joined
Feb 23, 2007
Messages
1,030
Solved! (Close)

JASS:
scope MeltaMaverick

private function Conditions takes nothing returns boolean
return GetUnitTypeId(GetAttacker()) == 'h004'
endfunction

private function Knockback takes nothing returns nothing
local timer q = GetExpiredTimer()
local unit u = GetHandleUnit(q,"u")
local real x = GetHandleReal(q,"x")
local real y = GetHandleReal(q,"y")
local integer c = GetHandleInt(q,"c")-1

call SetUnitPosition(u,GetUnitX(u)+x,GetUnitY(u)+y)

if c==0 then
    call PauseTimer(q)
    call FlushHandleLocals(q)
    call DestroyTimer(q)
else
    call SetHandleInt(q,"c",c)
endif

set q = null
set u = null
endfunction

private function TimerActions takes nothing returns nothing
local timer q = GetExpiredTimer()
local unit a = GetHandleUnit(q,"a")
local unit u = GetHandleUnit(q,"u")
local real x = GetUnitX(a)
local real y = GetUnitY(a)
local real f = Atan2(y-GetUnitY(u),x-GetUnitX(u))
local real x2 = x+15*Cos(f)
local real y2 = y+15*Sin(f)

call PauseTimer(q)
call FlushHandleLocals(q)
call DestroyTimer(q)
set q = CreateTimer()
call SetHandleReal(q,"x",x-x2)
call SetHandleReal(q,"y",y-y2)
call SetHandleInt(q,"c",10)
call TimerStart(q,0.03,true,function Knockback)

set q = null
set a = null
set u = null
endfunction

private function Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local unit a = GetAttacker()
local timer t = GetHandleTimer(a,"special")

call PauseTimer(t)
call FlushHandleLocals(t)
call DestroyTimer(t)
set t = CreateTimer()
call SetHandleHandle(t,"u",u)
call SetHandleHandle(t,"a",a)
call TimerStart(t,0.17,false,function TimerActions)
call SetHandleHandle(a,"special",t)

set t = null
set u = null
set a = null
endfunction

//===========================================================================
function InitTrig_MeltaMaverickFail takes nothing returns nothing
set gg_trg_MeltaMaverickFail = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_MeltaMaverickFail, EVENT_PLAYER_UNIT_ATTACKED)
call TriggerAddCondition(gg_trg_MeltaMaverickFail, Condition(function Conditions))
call TriggerAddAction(gg_trg_MeltaMaverickFail, function Actions)
endfunction

endscope

I have another trigger where whenever a Melta Maverick is issued any order or dies, it destroys the Timer attached to it. Nothing works at all and I did something extremely similar on another unit that worked fine. :cry:

I'm pretty sure the knockback itself is fine, but the timers are running or it isn't destroying them properly @_@ IDK!!!

I have run several tests with comments, and tried to debug it, but it just DOESN'T WORK!
 
Last edited:
Level 14
Joined
Nov 23, 2008
Messages
187
You just haven't stored unit being knockbacked for use in "Knockback" function.

This variant should be correct (also, it has simplier code)

JASS:
private function TimerActions takes nothing returns nothing
  local timer q = GetExpiredTimer()
  local unit  a = GetHandleUnit(q, "a")
  local unit  u = GetHandleUnit(q, "u")
  local real  f = Atan2(GetUnitY(a) - GetUnitY(u), GetUnitX(a) - GetUnitX(u))

  call PauseTimer(q)
  call FlushHandleLocals(q)
  call DestroyTimer(q)

  set q = CreateTimer()
  call SetHandleReal(q, "x", -15*Cos(f))
  call SetHandleReal(q, "y", -15*Sin(f))
  call SetHandleInt (q, "c", 10)
  call SetHandleUnit(q, "u", u)  // << storing unit for knockback
  call TimerStart(q, 0.03, true, function Knockback)

  set q = null
  set a = null
  set u = null
endfunction
 
Status
Not open for further replies.
Top