• 🏆 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!

Status
Not open for further replies.
Level 12
Joined
Nov 5, 2007
Messages
730
This is probably the 100th request for knockback the Hive's seen so far.Im sorry for bothering people with these things,but im horribly bad with jass,not that i didnt try to learn it,but after working with GUI for years,i cant even make the simplest script,no matter how hard i try.

If someone could give me the knocback code that works in a following trigger.

-Unit starts the effect of an ability

-Ability being cast equal to -something-

-Knocback code that knocks the target of ability for 300 range,doesnt destroy trees,works on a single target.

Ive seen some knockback scripts,but i cant even pinpoints the fields that i should change to make it look like what i want.

Any help would be appreciated.
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
let me check wc3jass .... okay I found one

Lets Begin
Open your Trigger Editor
Go to Variable Editor and
Create a Game Cache variable named "cscache"
Unit Variable named KTarget
Real Variable named KDistance
Real Variable named KDirection
Real Variable named KDuration
String Variable named KEffect
(names MUST be exact)

There is a field goes like <Your Map Name>.mdx
When you click on it you see an empty field in trigger section that you can write things in it

Copy All of this code to there
After you do that copy this code to bellow it

Usage:
  • Events
    • Unit Starts Effect of Ability
  • Conditions
    • Ability beign Cast is equal to PWNAZ0R
  • Actions
    • Set KTarget = (Target Unit of Ability Beign Cast)
    • Set KDirection = Direction Between (Triggering Unit) and (Target Unit of Ability Beign Cast)
    • Set KDuration = <time duration you want>
    • Set KDistance = <Maximum Distance you want unit to travel (300)>
    • Set KEffect = <Any Effect You want (copy some ability effect path from Object Editor)>
    • Custom script:call UnitKnockback(udg_KTarget,udg_KDistance, udg_KDirection*bj_DEGTORAD, udg_KDuration, 0.,null, udg_KEffect)
it will generate the speed by itself

Give credit to Vexorian for CSCache and Credit to Silvenon for UnitKnockback
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Well this is my knockback simple script.

Put that into your header, and then create a custom script which includes this line "call Knockback(unit whichUnit, real knockback, real angle)".

whichUnit = the unit that gets knocked.
knockback = knockback power (something between 10-20 would probably suit you).
angle = angle.

JASS:
//****************************************************************************************
//               Knock back
//  call Knockback(unit whichUnit, real knockback, real angle)
//

function knockbacktimer takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit whichUnit = GetHandleUnit(t, "whichUnit")
    local real knockback = GetHandleReal(t, "knockback")
    local real angle = GetHandleReal(t, "angle")
    local real a = angle * bj_DEGTORAD
    local real x = GetUnitX(whichUnit) + knockback * Cos(a)
    local real y = GetUnitY(whichUnit) + knockback * Sin(a)
    call SetUnitPosition(whichUnit, x, y)
    set knockback = knockback-0.3
    call SetHandleReal(t, "knockback", knockback)
    if knockback <= 0 then
        call FlushHandleLocals(t)
        call DestroyTimer(t)
    endif
    set t = null
    set whichUnit = null  
endfunction
function Knockback takes unit whichUnit, real knockback, real angle returns nothing
    local timer t = CreateTimer()
    call SetHandleHandle(t, "whichUnit", whichUnit)
    call SetHandleReal(t, "knockback", knockback)
    call SetHandleReal(t, "angle", angle)
    call TimerStart(t, 0.02, true, function knockbacktimer)
    set t = null
endfunction


Example:
  • Untitled Trigger 285.241
    • Events
      • somethingHappens
    • Conditions
    • Actions
      • Set Target = (Target unit of ability being cast)
      • Set CasterPoint = (Position of (Triggering unit))
      • Set TargetPoint = (Position of Target)
      • Set Real = (Angle from CasterPoint to TargetPoint)
      • Custom script: call Knockback(udg_Target, 15, udg_Real)
      • Custom script: call RemoveLocation(udg_CasterPoint)
      • Custom script: call RemoveLocation(udg_TargetPoint)

w00t again second :huh:
 
Last edited:
Level 12
Joined
Nov 5, 2007
Messages
730
Need_o2 i did everything like you said but when i try to save the map or test it,i get an error report just when it gets to "generating map script"

am i supposed to copy all of the codes,or everything except the green text...?
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
greens are fine...
it should work fine if you created variables :/ I'll check later gotto go
 
Level 12
Joined
Nov 5, 2007
Messages
730
None of these work for me....

I tried to do GhostWolf's knockback but its not working either....I get this message:

Line 1734:Expected a funcion name.

And it highlights one of the Set Variable triggers,if i delete it just to see what happens,it finds an another trigger.

I did it the EXACT same way but the WE acts as if i dont have the variables at all and/or i didnt spell them right in the scripts but im 100000% sure i did,with the exact same caps and all...
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
You don't have Kattana's local handle vars do you ?

Copy also this to your header, it is used a lot in JASS.

JASS:
// ===========================
function H2I takes handle h returns integer
    return h
    return 0
endfunction

// ===========================
function LocalVars takes nothing returns gamecache
    // Replace InitGameCache("jasslocalvars.w3v") with a global variable!!
    return InitGameCache("jasslocalvars.w3v")
endfunction

function SetHandleHandle takes handle subject, string name, handle value returns nothing
    if value==null then
        call FlushStoredInteger(LocalVars(),I2S(H2I(subject)),name)
    else
        call StoreInteger(LocalVars(), I2S(H2I(subject)), name, H2I(value))
    endif
endfunction

function SetHandleInt takes handle subject, string name, integer value returns nothing
    if value==0 then
        call FlushStoredInteger(LocalVars(),I2S(H2I(subject)),name)
    else
        call StoreInteger(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction

function SetHandleBoolean takes handle subject, string name, boolean value returns nothing
    if value==false then
        call FlushStoredBoolean(LocalVars(),I2S(H2I(subject)),name)
    else
        call StoreBoolean(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction

function SetHandleReal takes handle subject, string name, real value returns nothing
    if value==0 then
        call FlushStoredReal(LocalVars(), I2S(H2I(subject)), name)
    else
        call StoreReal(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction

function SetHandleString takes handle subject, string name, string value returns nothing
    if value==null then
        call FlushStoredString(LocalVars(), I2S(H2I(subject)), name)
    else
        call StoreString(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction

function GetHandleHandle takes handle subject, string name returns handle
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleInt takes handle subject, string name returns integer
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
endfunction
function GetHandleBoolean takes handle subject, string name returns boolean
    return GetStoredBoolean(LocalVars(), I2S(H2I(subject)), name)
endfunction
function GetHandleReal takes handle subject, string name returns real
    return GetStoredReal(LocalVars(), I2S(H2I(subject)), name)
endfunction
function GetHandleString takes handle subject, string name returns string
    return GetStoredString(LocalVars(), I2S(H2I(subject)), name)
endfunction

function GetHandleUnit takes handle subject, string name returns unit
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleTimer takes handle subject, string name returns timer
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleTrigger takes handle subject, string name returns trigger
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleEffect takes handle subject, string name returns effect
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleGroup takes handle subject, string name returns group
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleLightning takes handle subject, string name returns lightning
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleWidget takes handle subject, string name returns widget
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction

function FlushHandleLocals takes handle subject returns nothing
    call FlushStoredMission(LocalVars(), I2S(H2I(subject)) )
endfunction
 
Level 12
Joined
Nov 5, 2007
Messages
730
No i dont..:(

I dont even know what that is lol...

Do i have to have that to make the trigger?

Edit:nevermind,it still doesnt work.Now im getting the windows error and WE closes automatically.Im probably getting mixed up with the variables you mentioned(whichUnit,knockback,angle) and the ones i see in the trigger (Target,real)
 
Last edited:
Level 12
Joined
Nov 5, 2007
Messages
730
...Sorry,english is not my maternal language,so maybe i misunderstood the word header,but i placed it in the MyMap.w3x Custom Script code,above the other code....still buggy.

The trigger is completely identical to yours,with all the variables,although i tried with whichUnit,knockback,angle too.

The scripts are both completely copied.

Still gettin the error.
Sorry for bothering you :(

Edit:is it too much trouble if i attach the map here,and let you input the codes and scripts...?Ive been trying all day but as i said,JASS hates me.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Here I made this example map.

Type "knock" to see the example if you want.

By the way, if you want to change how drastic the slowing will be, go to this line "set knockback = knockback-0.3" and change that -0.3 to whatever you want.
The bigger the number, the faster the knockback will end.

I really should make it more user friendly and make the knock back based on total range (for example, you tell him to move to 300 range) but im tired now, lol.
 

Attachments

  • Knockback.w3x
    14 KB · Views: 120
Level 19
Joined
Sep 4, 2007
Messages
2,826
Here I made this example map.

Type "knock" to see the example if you want.

By the way, if you want to change how drastic the slowing will be, go to this line "set knockback = knockback-0.3" and change that -0.3 to whatever you want.
The bigger the number, the faster the knockback will end.

I really should make it more user friendly and make the knock back based on total range (for example, you tell him to move to 300 range) but im tired now, lol.

Omg... How can this possible trigger a knockout??? Isn't it a simple GUI trigger...???? There is only 1 trigger in this map...
  • Example
    • Events
      • Player - Player 1 (Red) types a chat message containing knock as An exact match
    • Conditions
    • Actions
      • Set Unit = Peasant 0000 <gen>
      • Custom script: call Knockback(udg_Unit,15,0)
Hm... How can you make it so all units around a unit which uses a knockout ability knock all units around away?
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
redmarine, botherd to look at the header ? :eekani:

And a "circle" knockback would require picking everyone around your unit and knockbacking them to the angle between your hero and the knocked unit.

I made this cool (but too laggy, warcraft just can't handle it with more then 1-2 casts at the same time :xxd:) of "rain of fire" that shoots fire bombs from the air to the ground and knockbacking every unit they hit.

If you want it, ask, I will need to clean the map though as it contains more work of me which I don't really want to publish, its dark secret evil stuff ! *evil laughter*.
 
Level 12
Joined
Nov 5, 2007
Messages
730
GhostWolf,countless thanks.But it seems that there still is a problem,i copied the trigger from your map.I copied the code.I made an IDENTICAL variable.The only difference is that i made Set Unit - (Target unit of ability being cast) instad of Peaseant 0019 or whatever it was.

I still get the error.Its almost funny.

Anyways,+ rep for you,youve really wasted a lot of ur time in trying to help me with this.

Edit:Says i already repped you.Well ill note this and rep you in a week :)
 
Level 19
Joined
Sep 4, 2007
Messages
2,826
redmarine, botherd to look at the header ? :eekani:

And a "circle" knockback would require picking everyone around your unit and knockbacking them to the angle between your hero and the knocked unit.

I made this cool (but too laggy, warcraft just can't handle it with more then 1-2 casts at the same time :xxd:) of "rain of fire" that shoots fire bombs from the air to the ground and knockbacking every unit they hit.

If you want it, ask, I will need to clean the map though as it contains more work of me which I don't really want to publish, its dark secret evil stuff ! *evil laughter*.

So... What if it is only for like 1-11 units? Will it be laggy?

BTW: Japut3h, nice avatar lol... Made me laugh.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
GhostWolf,countless thanks.But it seems that there still is a problem,i copied the trigger from your map.I copied the code.I made an IDENTICAL variable.The only difference is that i made Set Unit - (Target unit of ability being cast) instad of Peaseant 0019 or whatever it was.

I still get the error.Its almost funny.

That is really weird, on what line it says the error is ? (and what is the error ?)


So... What if it is only for like 1-11 units? Will it be laggy?


If its say a one-shot meteor or something like that, of course it won't be laggy.
You need to see my spell to get why its laggy *evil laughter*.
It shoots 20xAbilityLevel fire bombs at about 2 seconds and they all come down and knockback everybody around at a diffrence of some random very small number of seconds (more like 0.1) in between them, thats why it lags :p

I DO need to check it out and fix some stuff though, because it lags also if there is no one around it, thus I can only know that it creates groups and stuff even if nobody is around, but it doesn't really matter for you lol.

In conclusion, a one-shot thingy or something like that won't lag, even a few of them at some delay in between them won't lag. If you make a lot at the same time though... god be with you ! :D
 
Level 12
Joined
Nov 5, 2007
Messages
730
Heh i saw this pic and just had to share it with everyone... :)

But lets not get off topic,or the evil mods will close the thread :grin:

Edit:
The error says Line 1947:Expected a function name
and highlights "call Knockback(udg_Unit,15,0)"
 
Level 12
Joined
Nov 5, 2007
Messages
730
It is Unit.Even though its just four letters i checked them over and over again to try and see if something is misplaced but it looks fine.

This is what was happening all the time.Its weird.Ill re-paste the code but i doubt that thats the problem.

Edit:Ok i checked,when selecting the code instead of "select all" option i had to be a smartass and i checked it by highlighting.I missed out a tiny part of the code,ima check if thats it now.

Edit 2:Works.Apparently i didnt copy the whole code.Thanks a LOT!!!!!

BTW i think you should put the map of yours under the spells section,theres a whole bunch of people needing knockback spells.This could solve a lot of problems :grin:
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Edit 2:Works.Apparently i didnt copy the whole code.Thanks a LOT!!!!!

Gratz :)

BTW i think you should put the map of yours under the spells section,theres a whole bunch of people needing knockback spells.This could solve a lot of problems :grin:

Nah I bet there are lots of better knockbacks (this is the simplest there is probably) out there waiting to devour any nooby knockbacks trying to take their place :gg:
 
Level 19
Joined
Sep 4, 2007
Messages
2,826
That is really weird, on what line it says the error is ? (and what is the error ?)





If its say a one-shot meteor or something like that, of course it won't be laggy.
You need to see my spell to get why its laggy *evil laughter*.
It shoots 20xAbilityLevel fire bombs at about 2 seconds and they all come down and knockback everybody around at a diffrence of some random very small number of seconds (more like 0.1) in between them, thats why it lags :p

I DO need to check it out and fix some stuff though, because it lags also if there is no one around it, thus I can only know that it creates groups and stuff even if nobody is around, but it doesn't really matter for you lol.

In conclusion, a one-shot thingy or something like that won't lag, even a few of them at some delay in between them won't lag. If you make a lot at the same time though... god be with you ! :D

It is for a minimap with only 12 players that got 1 unit each. Could I see the map of yours? Perhaps you could fraps it? It would be cool.
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
Sorry sorry sorry
you know the 2 scripts I gave you the link
swap their positions (cscache should be before Silvenon's knockback)

that should solve it
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
No no no! Don't link people to that Knockback code from wc3jass, that thing is years old. Especially don't link people to outdated CSCache, there is a latest version of CasterSystem (with CSCache and CSSafety) on wc3campaigns.net

Btw, the latest version of my code is on THIS SITE, and you know that.......or do you? Anyways, the version on wc3jass probably doesn't even work right.
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
I know its old but I couldnt find its Handlevars version :/
there is a vjass one but I think he will refuse the vjass version
 
Status
Not open for further replies.
Top