HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Help me With Knockback

01-02-2007, 06:50 PM#1
Joker
Collapse JASS:
function Trig_Blasting_Arrow_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A00U'
endfunction

function Trig_Blasting_Arrow_Actions takes nothing returns nothing
    local unit a = GetSpellAbilityUnit()
    local real ax = GetUnitX(a)
    local real ay = GetUnitY(a)
    local unit b = GetSpellTargetUnit()
    local real bx = GetUnitX(b)
    local real by = GetUnitY(b)
    local real c = GetUnitAbilityLevel(a, 'A00U')
    call TriggerSleepAction( SquareRoot( (ax - bx) * (by - ay) ) / 1000.00 )
    loop
        exitwhen GetUnitX(b) == bx + (c * 1.5 * 100) and GetUnitY(b) == (by + (c * 1.5 * 100) )
        call SetUnitPosition( b, bx + 5, by + 5 )
        call TriggerSleepAction( 0.05 )
    endloop
    set a = null
    set b = null
endfunction

//===========================================================================
function InitTrig_Blasting_Arrow takes nothing returns nothing
    set gg_trg_Blasting_Arrow = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Blasting_Arrow, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Blasting_Arrow, Condition( function Trig_Blasting_Arrow_Conditions ) )
    call TriggerAddAction( gg_trg_Blasting_Arrow, function Trig_Blasting_Arrow_Actions )
endfunction
my 1st attempt of knockback and failed horribly. its just a storm bold with a kockback Someone help :(
01-02-2007, 07:18 PM#2
Fireeye
Well, i see 2 things what isn't that good.
1. you use a wait in a loop
2. You set the Unit Position +5 that means you will always get an angle of 45°
How to solve
1. use a timer instead of a loop with waits
2. Get the angle and then add Sin(angle)*5 to the x and Cos(Angle)*5 to the y value
01-02-2007, 07:30 PM#3
Ammorth
I would also change the exitwhen, as that requires exact amounts and its safer to use > or <.
01-02-2007, 08:43 PM#4
Joker
How would i use a timer in a loop?
01-02-2007, 08:54 PM#5
oNdizZ
Quote:
Originally Posted by Fireeye
Well, i see 2 things what isn't that good.
1. you use a wait in a loop
2. You set the Unit Position +5 that means you will always get an angle of 45°
How to solve
1. use a timer instead of a loop with waits
2. Get the angle and then add Sin(angle)*5 to the x and Cos(Angle)*5 to the y value

You mixed them up. Cos goes to X and Sin goes to Y. Dont forget that Cos() and Sin() both returns the real value in radians. Either you use CosBJ() and SinBJ() or you multiply the angle inside the Sin() and Cos() function by bj_DEGTORAD:

Cos(angle * bj_DEGTORAD)
or
CosBJ(angle)

edit:

Quote:
Originally Posted by Joker
How would i use a timer in a loop?

See this tutorial
01-02-2007, 10:20 PM#6
Joker
um...i tried to follow the tut, but...im hopeless
Collapse JASS:
function Trig_Blasting_Arrow_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A00U'
endfunction

function Knockback_Ba takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local real d = GetUnitFacing(GetSpellAbilityUnit())
    local unit b = GetSpellTargetUnit()
    call SetUnitPosition( GetSpellTargetUnit(), GetUnitX(b) + Sin(d)*5, GetUnitY(b) + Cos(d)*5 )
    call DestroyTimer(t)
    set b = null
endfunction

function Trig_Blasting_Arrow_Actions takes nothing returns nothing
    local unit a = GetSpellAbilityUnit()
    local real ax = GetUnitX(a)
    local real ay = GetUnitY(a)
    local unit b = GetSpellTargetUnit()
    local real bx = GetUnitX(b)
    local real by = GetUnitY(b)
    local real c = GetUnitAbilityLevel(a, 'A00U')
    local real d = GetUnitFacing(a)
    local real r = 0
    local timer t = CreateTimer()
    call TriggerSleepAction( SquareRoot( (ax - bx) * (by - ay) ) / 1000.00 )
    loop
        exitwhen r == bx + (c * 1.5 * 100) and r == by + (c * 1.5 * 100)
        call TimerStart( t, 0.05, false, function Knockback_Ba )
        set r = r + 5
    endloop
    set t = null
    set a = null
    set b = null
endfunction

//===========================================================================
function InitTrig_Blasting_Arrow takes nothing returns nothing
    set gg_trg_Blasting_Arrow = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Blasting_Arrow, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Blasting_Arrow, Condition( function Trig_Blasting_Arrow_Conditions ) )
    call TriggerAddAction( gg_trg_Blasting_Arrow, function Trig_Blasting_Arrow_Actions )
endfunction
it does nothing now
01-02-2007, 10:36 PM#7
wyrmlord
Here is a knockback function I used in one of my maps (modified to make it more understandable):
Collapse JASS:
function KnockbackEffect takes nothing returns nothing
 local timer t = GetExpiredTimer()
 local real distance = GetHandleReal(t, "distance")
 local real angle = GetHandleReal(t, "angle")
 local unit u = GetHandleUnit(t, "unit")
 local real x = GetUnitX(u) + distance * Cos(angle * bj_DEGTORAD)
 local real y = GetUnitY(u) + distance * Sin(angle * bj_DEGTORAD)
    if TimerGetElapsed(t) <= GetHandleReal(t, "overtime") then
        call PauseUnit(u, true)
        call SetUnitPosition(u, x, y)
    else
        call PauseUnit(u, false)
        call PauseTimer(t)
        call FlushHandleIndex(t)
        call DestroyTimer(t)
    endif
 set t = null
 set u = null
endfunction

function KnockbackUnit takes unit u, real angle, real distance, real overtime, real rate returns nothing
 local timer t = CreateTimer()
    call SetHandleHandle(t, "unit", u)
    call SetHandleReal(t, "distance", distance /(overtime/rate))
    call SetHandleReal(t, "overtime", overtime)
    call SetHandleReal(t, "angle", angle)
    call TimerStart(t, rate, true, function KnockbackEffect)
 set t = null
endfunction
If you aren't familiar with Kattana's handle variables, I suggest you search for them. While they may be slower than tables and such, they're probably the easiest to understand.
01-02-2007, 10:48 PM#8
oNdizZ
you might want to tell him that he needs those handlefuncs too, and where to get them.
i can't tell him, since i've never used them.
01-02-2007, 11:37 PM#9
Joker
It says undifined function
Collapse JASS:
FlushHandleIndex
after i copied the variable thing
01-02-2007, 11:39 PM#10
wyrmlord
You would need need to replace that with whatever its equivalent is in the handle variables. I just changed the code from using a system I made to Kattana's so it'd be easier to copy.
01-02-2007, 11:50 PM#11
Joker
Ok, i found it. New question. Whats the overtime? also, im having some trouble understanding this, the tut in WC3Jass is very vague
01-04-2007, 03:57 PM#12
Joker
Ok well i give up on the Kattana's handle variables. Can someone help me with knockback in just reg jass?
01-04-2007, 04:00 PM#13
Rising_Dusk
That depends if you want it multi-instanceable or not.
If you want MUI, then you're going to need some kind of cache use.
Otherwise you can use global variables.

Really it's just negative acceleration.
You just need to somehow get the angle, distance settings, and which unit over to the timer callback.
That's virtually it.
01-04-2007, 04:25 PM#14
Joker
Well...ive tried that but where would you use a global?
Collapse JASS:
function Trig_Blasting_Arrow_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A00U'
endfunction

function Knockback_Ba takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local real d = GetUnitFacing(GetSpellAbilityUnit())
    local unit b = GetSpellTargetUnit()
    call SetUnitPosition( GetSpellTargetUnit(), GetUnitX(b) + Sin(d)*5, GetUnitY(b) + Cos(d)*5 )
    call DestroyTimer(t)
    set b = null
endfunction

function Trig_Blasting_Arrow_Actions takes nothing returns nothing
    local unit a = GetSpellAbilityUnit()
    local real ax = GetUnitX(a)
    local real ay = GetUnitY(a)
    local unit b = GetSpellTargetUnit()
    local real bx = GetUnitX(b)
    local real by = GetUnitY(b)
    local real c = GetUnitAbilityLevel(a, 'A00U')
    local real d = GetUnitFacing(a)
    local real r = 0
    local timer t = CreateTimer()
    call TriggerSleepAction( SquareRoot( (ax - bx) * (by - ay) ) / 1000.00 )
    loop
        exitwhen r == bx + (c * 1.5 * 100) and r == by + (c * 1.5 * 100)
        call TimerStart( t, 0.05, false, function Knockback_Ba )
        set r = r + 5
    endloop
    set t = null
    set a = null
    set b = null
endfunction

//===========================================================================
function InitTrig_Blasting_Arrow takes nothing returns nothing
    set gg_trg_Blasting_Arrow = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Blasting_Arrow, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Blasting_Arrow, Condition( function Trig_Blasting_Arrow_Conditions ) )
    call TriggerAddAction( gg_trg_Blasting_Arrow, function Trig_Blasting_Arrow_Actions )
endfunction
i posted this above, but idk what to do with it now.
01-05-2007, 10:32 PM#15
Joker
help?