Raised This Month: $ Target: $400
 0% 

HE knockback plugin, mathematics help...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ThantiK
Senior Member
Join Date: Mar 2004
Location: Orlando, FL
Old 10-05-2004 , 14:54   HE knockback plugin, mathematics help...
Reply With Quote #1

Code:
/* AMX Mod script. * Special thanks goes to JGHG for MOST of the code! */ #include <amxmodx> #include <amxmisc> #include <engine> #define SPEED 800.0 public plugin_init() {     register_plugin("HE Knockback", "1.0", "ThantiK")     register_event("Damage", "hedamage_event", "b", "2!0", "4!0", "5!0", "6!0") } public hedamage_event(id) {     new MAXPLAYERS     MAXPLAYERS = get_maxplayers()     new inflictor = entity_get_edict(id, EV_ENT_dmg_inflictor)     if (inflictor <= MAXPLAYERS)         return PLUGIN_CONTINUE     new classname2[8]     entity_get_string(inflictor, EV_SZ_classname, classname2, 7)     if (!equal(classname2, "grenade"))         return PLUGIN_CONTINUE     new bangorigin[3]     bangorigin[0] = read_data(4)     bangorigin[1] = read_data(5)     bangorigin[2] = read_data(6)     new Float:upVector[3]     upVector[0] = float(bangorigin[0])     upVector[1] = float(bangorigin[1])     upVector[2] = float(bangorigin[2])     entity_set_vector(id, EV_VEC_velocity, upVector);     client_print(0, print_chat, "%d got hit by %d which is a %s, from %d, %d, %d", id, inflictor, classname2, bangorigin[0], bangorigin[1], bangorigin[2])     server_print("%d got hit by %d which is a %s, from %d, %d, %d", id, inflictor, classname2, bangorigin[0], bangorigin[1], bangorigin[2])     return PLUGIN_CONTINUE }

This was my idea back in the AMX mod days when it "couldn't be done"...now I've made it...but the calculation is messed up. Seems HE's only send you 1 direction based on where you are on the map. Would anyone mind taking a look at this and telling me what kind of calculation I gotta do to send the user in the correct direction?...and possibly even set up a variable on how strong the effect is?
__________________
AMXX -- You want control? You got it.
tkwired.com cs 1.6 -- tkwired.com:27016
ThantiK is offline
Send a message via AIM to ThantiK Send a message via MSN to ThantiK
Ryan
Senior Member
Join Date: May 2004
Location: NH, USA
Old 10-05-2004 , 21:41  
Reply With Quote #2

if you're having problems catching the grenade id in the damage event, one alternative you could use is the TE_EXPLOSION tempent. Grenades (and their explosion origins) are easily catchable with the SVC_TEMPENTITY event (event "23"), and if you have an origin of the explosion, you can get distance and a vector velocity to send the player(s) to.

here's some code to help you along..

Code:
public plugin_init() {     register_event( "23", "on_Explosion", "a","1=3","6=25" );     return PLUGIN_CONTINUE; } public on_Explosion() {     // GRENADE EXPLOSION     // read_data(1) = 3     (TE_EXPLOSION)     // read_data(6) = 25    (scale in 0.1's)     new Float:ExplosionOrigin[3];     read_data( 2, ExplosionOrigin[0] );     read_data( 3, ExplosionOrigin[1] );     read_data( 4, ExplosionOrigin[2] );     // .. continue from here ..     return PLUGIN_CONTINUE; }

now you would need to check if the player(s) were damaged first, so it might be a good idea to store this origin in a global var and wait until the damage event before actually moving the players.

and speaking of which, here's a couple stocks i wrote that will help you in determining the velocity (kickback) to give the player(s) damaged.

Code:
// Gets velocity of an entity (ent) away from origin with speed (fSpeed) stock get_velocity_from_origin( ent, Float:fOrigin[3], Float:fSpeed, Float:fVelocity[3] ) {     new Float:fEntOrigin[3];     entity_get_vector( ent, EV_VEC_origin, fEntOrigin );     // Velocity = Distance / Time     new Float:fDistance[3];     fDistance[0] = fEntOrigin[0] - fOrigin[0];     fDistance[1] = fEntOrigin[1] - fOrigin[1];     fDistance[2] = fEntOrigin[2] - fOrigin[2];     new Float:fTime = ( vector_distance( fEntOrigin,fOrigin ) / fSpeed );     fVelocity[0] = fDistance[0] / fTime;     fVelocity[1] = fDistance[1] / fTime;     fVelocity[2] = fDistance[2] / fTime;     return ( fVelocity[0] && fVelocity[1] && fVelocity[2] ); } // Sets velocity of an entity (ent) away from origin with speed (speed) stock set_velocity_from_origin( ent, Float:fOrigin[3], Float:fSpeed ) {     new Float:fVelocity[3];     get_velocity_from_origin( ent, fOrigin, fSpeed, fVelocity )     entity_set_vector( ent, EV_VEC_velocity, fVelocity );     return ( 1 ); }

you would really only need to use the set_velocity_from_origin() function, so let me outline the parameters a bit..

1) ent - this is the player entity that you are pushing (kicking back)
2) fOrigin - this is the origin of the grenade explosion
3) fSpeed - this is how fast you want to push the player backwards (linear). this is required to get the vector speed (velocity) that will be used to force the player back. one way to get this is to make some kind of calculation as to how far the player is from the grenade explosion, the closer (or higher damage taken), the more speed given, etc...

for example, if you wanted the player to move 5 velocity per point of damage, it's as simple as doing 5 * iDamage.

etc etc.

i can't wait to see this plugin in action
__________________
Warcraft 3: Expansion
Homepage | Downloads | Forums
Ryan is offline
Send a message via AIM to Ryan
ThantiK
Senior Member
Join Date: Mar 2004
Location: Orlando, FL
Old 10-06-2004 , 01:42  
Reply With Quote #3

the plugin works fine man. Appropriately checks damage, everything.

My problem is, the coords it gives when it damages a player, doesn't send them in the OPPOSITE direction that I need them to. -- I think what I need to do, is take gren origin minus player origin, and send them in to THAT vector...or find the difference of the gren and player origin and add it onto the player origin. Not sure yet.

Basically, we'll be able to conc jump in CS =D

THANKS for the help tho, I'll be working on it tomarrow morning when my girlfriend calls
__________________
AMXX -- You want control? You got it.
tkwired.com cs 1.6 -- tkwired.com:27016
ThantiK is offline
Send a message via AIM to ThantiK Send a message via MSN to ThantiK
Ryan
Senior Member
Join Date: May 2004
Location: NH, USA
Old 10-06-2004 , 04:53  
Reply With Quote #4

if you didnt even read the 2nd half of my post, then you missed the major point of it..

i gave you a couple stocks you can use to send the player away from the grenade.. you're having a problem with them going in the opposite direction? these will push them in the correct direction..

even if you dont need to use the stock for face value, all the coding you need is in there to project the player away from something.
__________________
Warcraft 3: Expansion
Homepage | Downloads | Forums
Ryan is offline
Send a message via AIM to Ryan
ThantiK
Senior Member
Join Date: Mar 2004
Location: Orlando, FL
Old 10-06-2004 , 11:15  
Reply With Quote #5

Yea, I noticed that after I posted.

Thanks for the stocks. VERY HELPFUL...
__________________
AMXX -- You want control? You got it.
tkwired.com cs 1.6 -- tkwired.com:27016
ThantiK is offline
Send a message via AIM to ThantiK Send a message via MSN to ThantiK
ThantiK
Senior Member
Join Date: Mar 2004
Location: Orlando, FL
Old 10-06-2004 , 12:32  
Reply With Quote #6

RELEASED

http://forums.alliedmods.net/showthread.php?t=6559
__________________
AMXX -- You want control? You got it.
tkwired.com cs 1.6 -- tkwired.com:27016
ThantiK is offline
Send a message via AIM to ThantiK Send a message via MSN to ThantiK
Ryan
Senior Member
Join Date: May 2004
Location: NH, USA
Old 10-06-2004 , 17:53  
Reply With Quote #7

woot !
__________________
Warcraft 3: Expansion
Homepage | Downloads | Forums
Ryan is offline
Send a message via AIM to Ryan
ThantiK
Senior Member
Join Date: Mar 2004
Location: Orlando, FL
Old 10-06-2004 , 18:34  
Reply With Quote #8

The cool thing is you can set it to a negative number he_push to like -30, and it acts like a gravity 'nade...I found it quite fun.
__________________
AMXX -- You want control? You got it.
tkwired.com cs 1.6 -- tkwired.com:27016
ThantiK is offline
Send a message via AIM to ThantiK Send a message via MSN to ThantiK
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:18.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode