- Joined
- Apr 27, 2011
- Messages
- 272
Im currently updating the system again...
Just a simple knockback system that has a special extension that adds an "OnKnockBack" pseudo-event which is a great help for making spells.
KnockBackUtils:
KnockBackUtilsEx:
Sample usage of the extension:
Just a simple knockback system that has a special extension that adds an "OnKnockBack" pseudo-event which is a great help for making spells.
KnockBackUtils:
JASS:
library KnockBackUtils //optional KnockBackUtilsEx
//===========================================================================
// KnockBackUtils Module by Alain.Mark
//
// -Info-
// -Just another simple knockback code.
//
// -API-
// -function KnockBackUnit takes unit whichUnit, real distance, real speed, real angle returns integer
//
//===========================================================================
//=======================================================================
// configurables
//=======================================================================
globals
private constant timer KNOCKBACK_UTILS_TIMER=CreateTimer()
private constant real KNOCKBACK_UTILS_TIMER_TICK=0.025
endglobals
//===========================================================================
//
//===========================================================================
globals
private integer o
private real ux
private real uy
private real uz
endglobals
//===========================================================================
globals
private integer n=-1
endglobals
//===========================================================================
globals
private unit array uQ
private real array dQ
private real array vQ
private real array aQ
private real array vxQ
private real array vyQ
//! runtextmacro optional KnockBackUtilsEx_Globals()
endglobals
//===========================================================================
globals
private real MIN_X
private real MIN_Y
private real MAX_X
private real MAX_Y
endglobals
//===========================================================================
private function Pathable takes real x, real y returns boolean
return IsTerrainPathable(x,y,PATHING_TYPE_WALKABILITY) and x>MIN_X and y>MIN_Y and x<MAX_X and x<MAX_Y
endfunction
//===========================================================================
private function OnLoop takes nothing returns nothing
set o=n
loop
exitwhen o<0
if(dQ[o]>0.00)then
set ux=GetUnitX(uQ[o])+vxQ[o]
set uy=GetUnitY(uQ[o])+vyQ[o]
if(Pathable(ux,uy))then
call SetUnitX(uQ[o],ux)
call SetUnitY(uQ[o],uy)
set dQ[o]=dQ[o]-vQ[o]
else
set dQ[o]=0.00
endif
//! runtextmacro optional KnockBackUtilsEx_FireCode()
else
call SetUnitPathing(uQ[o],false)
set uQ[o]=uQ[n]
set dQ[o]=dQ[n]
set vQ[o]=vQ[n]
set aQ[o]=aQ[n]
set vxQ[o]=vxQ[n]
set vyQ[o]=vyQ[n]
//! runtextmacro optional KnockBackUtilsEx_QueueSwap()
set n=n-1
if(n<0)then
call TimerStart(KNOCKBACK_UTILS_TIMER,0.00,true,null)
endif
endif
set o=o-1
endloop
endfunction
//===========================================================================
function KnockBackUnit takes unit u, real d, real v, real a returns integer
set n=n+1
set uQ[n]=u
set dQ[n]=d
set vQ[n]=v*KNOCKBACK_UTILS_TIMER_TICK
set aQ[n]=a
set vxQ[n]=(v*KNOCKBACK_UTILS_TIMER_TICK)*Cos(a*0.01745)
set vyQ[n]=(v*KNOCKBACK_UTILS_TIMER_TICK)*Sin(a*0.01745)
//! runtextmacro optional KnockBackUtilsEx_execQToFalse()
call SetUnitPathing(u,false)
if(n==0)then
call TimerStart(KNOCKBACK_UTILS_TIMER,KNOCKBACK_UTILS_TIMER_TICK,true,function OnLoop)
endif
return n
endfunction
//===========================================================================
//! runtextmacro optional KnockBackUtilsEx_Plugins()
//===========================================================================
private module m
private static method onInit takes nothing returns nothing
set MIN_X=GetCameraBoundMinX()
set MIN_Y=GetCameraBoundMinY()
set MAX_X=GetCameraBoundMaxX()
set MAX_Y=GetCameraBoundMaxY()
endmethod
endmodule
private struct s
implement m
endstruct
//===========================================================================
endlibrary
KnockBackUtilsEx:
JASS:
library KnockBackUtilsEx
//===========================================================================
// KnockBackUtilsEx by Alain.Mark
//
// -Info-
// -This extension module will add more functionalities to KnockBackUtils.
//
// -API- (added to KnockBackUtils)
// -function OnKnockBackAction takes integer whichInstance, code c returns nothing
// -function GetKnockBackInstance takes nothing returns integer
// -function GetKnockBackUnit takes nothing returns nothing
//
//===========================================================================
//! textmacro KnockBackUtilsEx_Globals
private trigger array trgQ
private boolean array execQ
//! endtextmacro
//===========================================================================
//! textmacro KnockBackUtilsEx_FireCode
if(execQ[o])then
call TriggerExecute(trgQ[o])
endif
//! endtextmacro
//===========================================================================
//! textmacro KnockBackUtilsEx_QueueSwap
set trgQ[o]=trgQ[n]
set execQ[o]=execQ[n]
//! endtextmacro
//===========================================================================
//! textmacro KnockBackUtilsEx_execQToFalse
set execQ[n]=false
//! endtextmacro
//===========================================================================
//! textmacro KnockBackUtilsEx_Plugins
function OnKnockBack takes integer i, code c returns nothing
if(trgQ[i]==null)then
set trgQ[i]=CreateTrigger()
else
call TriggerClearActions(trgQ[i])
endif
set execQ[i]=true
call TriggerAddAction(trgQ[i],c)
endfunction
function GetKnockBackInstance takes nothing returns integer
return o
endfunction
function GetKnockBackUnit takes nothing returns unit
return uQ[o]
endfunction
//! endtextmacro
//===========================================================================
endlibrary
Sample usage of the extension:
JASS:
private function SomeCode takes nothing returns nothing
local integer i=GetKnockBackInstance()
call BJDebugMsg(someString[i]) // removes the requirement of unit indexing. (in this situation only)
endfunction
private function SomeFunctionName returns nothing
...
local integer knockback_instance=KnockBackUnit(someUnit,dist,speed,angle)
// this is the purpose why the "KnockBackUnit" function returns an integer because
// you can utilize it for making spells and stuff once coupled with "OnKnockBackAction":
set someString[knockback_instance]="Hello World!!! :D"
call OnKnockBack(knockback_instance,function SomeCode)
// "SomeCode" will be executed while "someUnit" is being knockbacked
endfunction
Last edited: