• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Knockback system

Status
Not open for further replies.
Level 7
Joined
Aug 19, 2009
Messages
278
I was making a knockback system using index arraY..

writing the code according to me is over... but there is some error and its not executing

It starts here

This is a function that takes the unit, angle in which the knockback takes place, the speed of the knock back and the distance of the knockback

There are many value stored out of which all are not needed. But i have stored them for other uses which are unneeded here.
JASS:
function knockbackSD takes unit ku, real angle, real speed, real distance returns nothing
set udg_knockcount = udg_knockcount + 1
set udg_knockunit[udg_knockcount] = ku
set udg_knockx[udg_knockcount] = Cos(angle * bj_DEGTORAD)
set udg_knocky[udg_knockcount] = Sin(angle * bj_DEGTORAD)
set udg_knockix[udg_knockcount] = GetUnitX(ku)
set udg_knockiy[udg_knockcount] = GetUnitY(ku)
set udg_knockfx[udg_knockcount] = udg_knockix[udg_knockcount] + (Cos(angle * bj_DEGTORAD)*distance)
set udg_knockfy[udg_knockcount] = udg_knockiy[udg_knockcount] + (Sin(angle * bj_DEGTORAD)*distance)
set udg_knockangle[udg_knockcount] = angle
set udg_knockdistance[udg_knockcount] = distance
set udg_knocktimer[udg_knockcount] = ((distance/speed)*20)
endfunction

time of knockback = distance/speed
it givens in seconds. But the original counter moves every 0.05 seconds so i have to multiply a factor of 20 to it.

-------------------------------------


This is just a test spell to test the function
*Here is i get the first error.
The "2" is not printed.
It just puts the values in the main index array.
JASS:
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    local unit caster
    local unit casted
    local real angle
    set caster = GetTriggerUnit()
    set casted = GetSpellTargetUnit()
    set angle = GetUnitFacing(caster)
    call knockbackSD (caster, angle, 150, 600)
    call DisplayTextToForce( GetPlayersAll(), "2" )
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Untitled_Trigger_001, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
endfunction

-----------------------------------------------

This is the function that executes every 0.05 second and knocks back the units.
If the array has units, it checks form the knockcount then then executes.

The integer n checks all the values in the arrays one by one then executes. and exits when the its equal to the number of array units.

JASS:
local real y1
local integer n
    if (udg_knockcount > 0) then
        set n = 1
        loop
        exitwhen (n > udg_knockcount)
            set u = udg_knockunit[n]
            set x1 = GetUnitX(u) + (udg_knockx[n]*udg_knockspeed[n])
            set y1 = GetUnitY(u) + (udg_knocky[n]*udg_knockspeed[n])
            call SetUnitX(u, x1)
            call SetUnitY(u, y1)
            call DisplayTextToForce( GetPlayersAll(), "1" )
            if (udg_knocktimer[n] <= 0) then
                set udg_knockunit[n] = udg_knockunit[udg_knockcount]
                set udg_knocktimer[n] = udg_knocktimer[udg_knockcount]
                set udg_knockdistance[n] = udg_knockdistance[udg_knockcount]
                set udg_knockspeed[n] = udg_knockspeed[udg_knockcount]
                set udg_knockx[n] = udg_knockx[udg_knockcount]
                set udg_knocky[n] = udg_knocky[udg_knockcount]
                set udg_knockangle[n] = udg_knockangle[udg_knockcount]
                set udg_knockcount = udg_knockcount - 1
            endif
            set udg_knocktimer[n] = udg_knocktimer[n] - 1
            set n = n + 1
        endloop
    endif
endfunction

the knock counter has a initial value and keeps on decreasing untill its 0 and the knockback ends. After that Using the index array function the trigger cleans that position of the array.
But i have a problem here to i think.
The array wont get cleaned if n = knockcount. So is adding another condition here needed?

What will happen
 

Attachments

  • pb.w3x
    18.8 KB · Views: 54
Last edited:
Status
Not open for further replies.
Top