Hi...
I tried to make a knockback system using the concept of index arrays..
It works good as much as i know... Any one could check any faults in it or anything
This contains the declaration of global variables and the function that stores the data in the array which is to be checked my a loop and run on the timer
There are a lot of varaibles here which are unused.. I have kept them so that i might use them sometime in future.
knockbackSD means it will take speed and distance. There will be cases where it will take a time and speed so i have kept that for future.
There is a timer with a loop in it. The timer runs every 0.05 second. And the loop runs until all the data in the array is not checked. knockcount makes sure that no data more than what is required is checked.
I tried to make a knockback system using the concept of index arrays..
It works good as much as i know... Any one could check any faults in it or anything
This contains the declaration of global variables and the function that stores the data in the array which is to be checked my a loop and run on the timer
JASS:
globals
integer knockcount = 0
real array knocktimer
real array knockx
real array knocky
real array knockix
real array knockiy
real array knockfx
real array knockfy
unit array knockunit
real array knockspeed
real array knockdistance
real array knockangle
endglobals
library knockback
function knockbackSD takes unit ku, real angle, real speed, real distance returns nothing
set knockcount = knockcount + 1
set knockunit[knockcount] = ku
set knockx[knockcount] = Cos(angle * bj_DEGTORAD)
set knocky[knockcount] = Sin(angle * bj_DEGTORAD)
set knockix[knockcount] = GetUnitX(ku)
set knockiy[knockcount] = GetUnitY(ku)
set knockfx[knockcount] = knockix[knockcount] + (Cos(angle * bj_DEGTORAD)*distance)
set knockfy[knockcount] = knockiy[knockcount] + (Sin(angle * bj_DEGTORAD)*distance)
set knockangle[knockcount] = angle
set knockdistance[knockcount] = distance
set knockspeed[knockcount] = speed/20
set knocktimer[knockcount] = ((distance/speed)*20)
endfunction
endlibrary
There are a lot of varaibles here which are unused.. I have kept them so that i might use them sometime in future.
knockbackSD means it will take speed and distance. There will be cases where it will take a time and speed so i have kept that for future.
JASS:
function Trig_KnockbackPeriodic_Actions takes nothing returns nothing
local unit u
local real x1
local real y1
local integer n
if (knockcount > 0) then
set n = 1
loop
exitwhen (n > knockcount)
set u = knockunit[n]
set x1 = GetUnitX(u)
set y1 = GetUnitY(u)
set x1 = x1 + (knockx[n]*knockspeed[n])
set y1 = y1 + (knocky[n]*knockspeed[n])
call SetUnitX(u, x1)
call SetUnitY(u, y1)
if (knocktimer[n] <= 0) then
set knockunit[n] = knockunit[knockcount]
set knocktimer[n] = knocktimer[knockcount]
set knockdistance[n] = knockdistance[knockcount]
set knockspeed[n] = knockspeed[knockcount]
set knockx[n] = knockx[knockcount]
set knocky[n] = knocky[knockcount]
set knockangle[n] = knockangle[knockcount]
set knockix[n] = knockix[knockcount]
set knockiy[n] = knockiy[knockcount]
set knockfx[n] = knockfx[knockcount]
set knockfy[n] = knockfy[knockcount]
set knockcount = knockcount  1
endif
set knocktimer[n] = knocktimer[n]  1
set n = n + 1
endloop
endif
endfunction
//===========================================================================
function InitTrig_KnockbackPeriodic takes nothing returns nothing
set gg_trg_KnockbackPeriodic = CreateTrigger( )
call TriggerRegisterTimerEventPeriodic( gg_trg_KnockbackPeriodic, 0.05 )
call TriggerAddAction( gg_trg_KnockbackPeriodic, function Trig_KnockbackPeriodic_Actions )
endfunction
There is a timer with a loop in it. The timer runs every 0.05 second. And the loop runs until all the data in the array is not checked. knockcount makes sure that no data more than what is required is checked.
Attachments

19.2 KB Views: 213