System Knockback System (KBS)

Kenny

Back for now.
Reaction score
202
If you have a decent computer this shouldn't lag. Anyway for a knockback system 50+ units seems a bit excessive. I have tested this with a fair few units, probably 30-40, and it was fine.

However, when near trees with like 30+ units it may get a bit laggy, due to how the trees are filtered, especially if you are using the extended function for 30+ units. On the other hand though, you can use the extended version and get rid of any special effects by doing "nothing.mdx" or something, and also put a 0.00 for the Area value (for trees) and there will be much less lag.

And there should not be any crashing or errors created by this system.
 

Kenny

Back for now.
Reaction score
202
New version update:

Version 2.01:

- No drastic changes to anything, except for the addition of two new functions, that were "requested", for lack of a better word, by like 1 or 2 people.

The new functions are:

- KBS_IsUnitSliding(Target) - Checks if a unit is sliding using KBS.

- KBS_StopUnitSliding(Target) - Stops a unit from sliding if it is using KBS.

They both work quite well in conjunction with one another.

Have Fun. :)
 

Kenny

Back for now.
Reaction score
202
New Version:

- 17th Dec - Version 2.02 released. Few major changes to how the system works, including: the parameters "Startspeed" and "Deceleration" have now been changed to "Distance" and "Duration" which i find is far easier to use.

Now it is as easy as putting in a value of say 500.00 for distance and 2.00 for duration, making it last 2 seconds and knocking the unit back 500.00 distance.

Also "Checkheight" (which checked for terrain height using Z locations) has now been replaced with "CheckPathing" which checks for pathable terrain using an item check. Original concept is from Vexorian, it has been slightly modified.

Also added an effect for when a unit hits something with Checkpathing == true, this can also be made to not show.

Unfortunately this means it is not backwards compatible with earlier versions
, but this is made up for with the easier arguments needed.

This is also worth a read:

JASS:
//***************************************************************************************
//**                                                                                   **
//**    Some points on checking for pathable terrain:                                  **
//**                                                                                   **
//**`   - The area specified for destroying trees must be at least 75.00-100.00 range  **
//**      larger than the distance for checking for pathing, which is below in the     **
//**      globals block.                                                               **
//**    - When using KBS_BeginEx() and using either 0.00 or a negative value for the   **
//**      parameter 'Area' (destroying trees) it is better to have CheckPathing as     **
//**      FALSE. This is due to the fact that setting CheckPathing to TRUE will        **
//**      override the 'Area' Parameter and stop a unit if it gets near trees.         **
//**    - Basically what this means is that you cannot get a unit to just 'bounce' off **
//**      trees anymore, it is either destroy trees or get stopped by them.            **
//**                                                                                   **
//***************************************************************************************


Let me know if I've missed anything.
 

Romek

Super Moderator
Reaction score
963
> This code seems sooooo similar to Rising Dusk~ knockback system at wc3s.
Unsurprising. They both do the same thing... :rolleyes:
 

Kenny

Back for now.
Reaction score
202
This code seems sooooo similar to Rising Dusk~ knockback system at wc3s.

Unfortunately, this is true :(. They do look alike. However, I was not aware of his system at the time i made this.

Also, some of the changes made to the system, as suggested by a few members here resemble parts of his system (the two added functions). When i was asked to add these in, i knew about his system, and didnt really want to do it, but yeah it eventually happened anyway.

Theres only so many ways you can make a knockback system anyway. But i am certainly open for ideas on how do make this more unique.
 

Viikuna

No Marlo no game.
Reaction score
265
I have one which uses Table for attaching Knockback Data to unit. ( So you can find out who knocked your unit etc. )

I dont know if many people like to use gamecache for unit attaching, but I kinda like my knockback struct.

Here it is if someone is interested:
JASS:
library KnockbackLib needs SafeFunctions, IsTerrainWalkable, Table

globals
    constant real KNOCKBACK_INTERVAL = .025
endglobals

private struct knockback

    static timer T=CreateTimer()
    static knockback array array
    static integer Total=0
    static HandleTable Knocked
    
     unit u
     unit knocker
    
     real x
     real y
     real velocity
     real friction
     real sin
     real cos
    
     static method TimerLoop takes nothing returns nothing
        local integer i=0
        local knockback a
        loop
           exitwhen i>=.Total
           set a=.array<i>
           set a.velocity=a.velocity-a.friction
           set a.x=SafeX(a.x+a.velocity*a.cos)
           set a.y=SafeY(a.y+a.velocity*a.sin)
           set a.velocity=a.velocity-a.friction
           if not IsTerrainWalkable(a.x,a.y) or a.velocity &lt;= 0.0 then
                call PauseUnit(a.u,false)
                call .Knocked.flush(a.u)
                call a.destroy()
                set .Total=.Total-1
                if .Total &gt; 0 then
                    set .array<i>=.array[.Total]
                    set i=i-1
                else
                    call PauseTimer(.T)
                endif
           else
                call SetUnitX(a.u,a.x)
                call SetUnitY(a.u,a.y)
           endif
           set i=i+1
         endloop
     endmethod
     
     static method onInit takes nothing returns nothing
         set .Knocked=HandleTable.create()
     endmethod
    
endstruct

    function Knockback takes unit u, unit knocker, real angle, real velocity, real friction returns nothing
        local knockback a=knockback.Knocked<u>
        local real x
        local real y
        local real ang
        if a != 0 then
            set a.friction=friction/2
            set a.knocker=knocker
            set x=(a.velocity*a.cos)+(velocity*Cos(angle))
            set y=(a.velocity*a.sin)+(velocity*Sin(angle))
            set a.velocity=SquareRoot(x*x+y*y)
            set ang=Atan2(y,x)
            set a.cos=Cos(ang)
            set a.sin=Sin(ang)
        else
            set a=knockback.create()
            set a.u=u
            set a.knocker=knocker
            set a.sin=Sin(angle)
            set a.cos=Cos(angle)
            set a.velocity=velocity
            set a.friction=friction/2
            set a.x=GetUnitX(a.u)
            set a.y=GetUnitY(a.u)
            call PauseUnit(a.u,true)
            set knockback.Knocked[a.u]=a
            if knockback.Total==0 then
                call TimerStart(knockback.T,KNOCKBACK_INTERVAL,true,function knockback.TimerLoop)
            endif
            set knockback.array[knockback.Total]=a
            set knockback.Total=knockback.Total+1
        endif
    endfunction

endlibrary</u></i></i>
 

Kenny

Back for now.
Reaction score
202
Minor Update, Version 2.03:

- 9th April - Version 2.03 released. Few minor changes made. Standardized the coding, making it easier to read. Updated the check pathability function from Vexorian's old version to Anitarf's newer version. Few minor changes to the coding in general, changed the two bonus functions a little bit. Nothing big, but it should be a little nicer now.

Overall, just updated it a bit to better match my standards today. It's still not perfect, but its better. And it works quite well seeing that it requires no other systems.

EDIT:

Another Minor Update, Version 2.04:

- 9th April - Version 2.04 released. Another couple of minor changes. Figured out my calculation for distance was a little off, it is now fixed. An incredibly minor change to how the effects work when wanting a custom one. And finally i added a new function.

THE NEW FUNCTION:

JASS:
call KBS_BeginCommon(Target,Distance,Duration,Angle)


Simple and easy. It is for all your basic knockback needs, requiring little effort to remember and very few parameters.

This function uses global parameters for Area, AllowMove and CheckPathing, which can be found in the library in the configurables section.

Basically if you have heaps of knockbacks in your map, and lots them are the same (as in the knock down trees, check for pathing and dont allow people to move) than this is the function for you.

Punch in the basic parameters needed and your done.

(I've kept KBS_Begin() for compatibilities sake and to allow adjustments in destroying trees if needed)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top