AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   A virtual sphere to eject player. (https://forums.alliedmods.net/showthread.php?t=49538)

Salepate 01-06-2007 16:23

A virtual sphere to eject player.
 
At first, I'm glad to be validated on this forum, I hope I won't act as fool and will respect every rules written, and I'll try to be understood as well I can do.
I lack english a bit but it should be ok.

To start and introduce you to what I want to mean, I will explain what my plugin is supposed to do and what it does...
Perhaps, some of you have tested a Natural-Selection Plugin, which change the colt into an explosive colt. Where it shoots, an explosion appear, and if you're in the area, you will be propelled in the air according a mathematical process which follow vectors rules.

I wanted to create a similar one on counter-strike, but actually, I have done everything wrong, even though my plugin is working, Vectors rules are just messed up.

I have made a little scheme
[IMG]http://img58.**************/img58/2008/boomshotxy3.png[/IMG]
It should help you to understand what I am saying.

I'll share you my code too (it should be indented well)
Code:
Code:
#define MAX_SPHERE_RADIUS 140 #define MIN_SPHERE_RADIUS 10 #define INCREASE_POWER 3.4 #define ORIGIN_POWER 514.0 /* *    The Origin power is just used to get an idea, even if it won't work under MIN_SPHERE_RADIUS * * */ public explosion_jump(id,level,cid) {     new wepid,temp1,temp2;     wepid = get_user_weapon(id,temp1,temp2); // checking if the attacker's using an usp.     if ( !cmd_access(id, level, cid, 1) || !(pev(id, pev_button) & IN_ATTACK) || wepid != 16  || read_data(3) < 1)         return PLUGIN_HANDLED;     new origin_player[3], origin_bullet[3], pl_bullet_distance;     new power;     new Float:velocity[3], Float:explosion_velocity;     get_user_origin(id, origin_player, 0);     get_user_origin(id, origin_bullet, 3);     pl_bullet_distance = get_distance(origin_player, origin_bullet);     if ( pl_bullet_distance > MAX_SPHERE_RADIUS || pl_bullet_distance < MIN_SPHERE_RADIUS)         return PLUGIN_HANDLED;     power = origin_player[0] - origin_bullet[0];     // a mathematical function to decrease ejection power.     explosion_velocity = ORIGIN_POWER + ( (power < 0 ) ? float(power) : (-1.0 * float(power)) ) * INCREASE_POWER ;     // initializing velocity with power set     for (new i = 0; i < 3 ; i++)         velocity[i] = explosion_velocity * ((origin_player[i] < origin_bullet[i]) ? -1.0 : 1.0);     set_pev(id,pev_velocity, velocity);     return PLUGIN_HANDLED; } public plugin_init() {     register_plugin("Power Jump","0.01","Salepate");     register_event("CurWeapon","explosion_jump","be","1=1"); }

Of course, I removed useless parts.
I think to make it works as I want, I have to create a vector with
"targeted position as the origin" (on the scheme)
"Player's position as the direction" (still on the scheme)

But I don't have any idea how to proceed.

I would be glad of having any help,

Thanks

Salepate.

AndraX2000 01-06-2007 19:00

Re: A virtual sphere to eject player.
 
If you only want to make the player who fired the shot fly, this may work.

velocity_by_aim ( iIndex, iVelocity, Float:vRetValue[3] )

iIndex is of course the player index, iVelocity is the multiplier for the velocity.

for you power adjustment try:
iVelocity = (pl_bullet_distance - MAX_SPHERE_RADIUS) * ORIGIN_POWER

Note that this will give you a negative value (which should send you flying backward).

AndraX2000 01-06-2007 20:41

Re: A virtual sphere to eject player.
 
Code:
#define MAX_SPHERE_RADIUS 200 #define MIN_SPHERE_RADIUS 0 #define ORIGIN_POWER 10 public explosion_jump(id,level,cid) {     new wepid,temp1,temp2;     wepid = get_user_weapon(id,temp1,temp2); // checking if the attacker's using an usp.     if ( !cmd_access(id, level, cid, 1) || !(pev(id, pev_button) & IN_ATTACK) || wepid != 16  || read_data(3) < 1)         return PLUGIN_HANDLED;     new origin_player[3], origin_bullet[3];     new power, pl_bullet_distance;     new Float:velocity[3];     get_user_origin(id, origin_player, 0);     get_user_origin(id, origin_bullet, 3);     pl_bullet_distance = get_distance(origin_player, origin_bullet);     if ( pl_bullet_distance > MAX_SPHERE_RADIUS || pl_bullet_distance < MIN_SPHERE_RADIUS)         return PLUGIN_HANDLED;     power = -1 * ORIGIN_POWER * ( MAX_SPHERE_RADIUS - pl_bullet_distance );     velocity_by_aim ( id, power, velocity )     set_pev(id,pev_velocity, velocity);     return PLUGIN_HANDLED; } public plugin_init() {     register_plugin("Power Jump","0.01","Salepate");     register_event("CurWeapon","explosion_jump","be","1=1"); }

This worked pretty nice. The power calculation is a bit linear, so you end up flying pretty high if you shoot right near your feet. You could take the square root of the stuff in parenthesis and that may give it a more natural feeling drop-off.

Salepate 01-07-2007 04:08

Re: A virtual sphere to eject player.
 
Hello, it will help me a lot, so many thanks it's exactly what I was searching for.

Good day.

Salepate 01-07-2007 06:18

Re: A virtual sphere to eject player.
 
Is there a way to simulate an aim. Because If I'm not aiming the position where the explosion fires, I won't be propelled from the explosion, but from my aim. (if you know what I mean).

AndraX2000 01-07-2007 11:46

Re: A virtual sphere to eject player.
 
Code:
#define MAX_SPHERE_RADIUS 200 #define MIN_SPHERE_RADIUS 0 #define ORIGIN_POWER 100 public explosion_jump(id,level,cid) {     new wepid,temp1,temp2;     wepid = get_user_weapon(id,temp1,temp2); // checking if the attacker's using an usp.     if ( !cmd_access(id, level, cid, 1) || !(pev(id, pev_button) & IN_ATTACK) || wepid != 16  || read_data(3) < 1)         return PLUGIN_HANDLED;     new origin_player[3], origin_bullet[3], Float:displacement[3];     new Float:power, Float:length;     new Float:velocity[3], Float:normalized_velocity[3];     get_user_origin(id, origin_player, 0);     get_user_origin(id, origin_bullet, 3);     displacement[0] = float(origin_player[0] - origin_bullet[0]);     displacement[1] = float(origin_player[1] - origin_bullet[1]);     displacement[2] = float(origin_player[2] - origin_bullet[2]);     length = vector_length(displacement);     if ( length > MAX_SPHERE_RADIUS || length < MIN_SPHERE_RADIUS)         return PLUGIN_HANDLED;     power = ORIGIN_POWER * floatsqroot( MAX_SPHERE_RADIUS - length );     normalized_velocity[0] = displacement[0] / length;     normalized_velocity[1] = displacement[1] / length;     normalized_velocity[2] = displacement[2] / length;     velocity[0] = normalized_velocity[0] * power;     velocity[1] = normalized_velocity[1] * power;     velocity[2] = normalized_velocity[2] * power;     set_pev(id,pev_velocity, velocity);     return PLUGIN_HANDLED; }

OK, so this is what you want to do mathwise.
1. Find the displacement between the player and the explosion. For the example the explosion location (origin_bullet) is where the bullet hits based on aim (user_get_origin mode 3). Where the bullet really hits is a bit more complicated but there is a tutorial in the forums about finding that.
2. Find the length of the displacement vector. There is a native function for that.
3. Normalize the displacement vector. You will use this as your normalized velocity. The normalized vector is a vector that points in the same direction, but has a length of 1.
4. Multiply the normalized vector by your power scalar to get the velocity vector.

Then you just plug in the velocity to set_pev.

Please note that PM made some functions for doing all the math in the example. They are located scripting/includes/XS.inc. I did it the long way so that you can see how the math works. For further reading try this great vector math introduction.

Salepate 01-07-2007 14:56

Re: A virtual sphere to eject player.
 
Okay thanks, I ported the code for making effective the explosion against all present players, and it perfectly works.

The last thing which doesn't work is the blast circle effect, and the explosion is not appearing as well, only some sparks show theirselves.

I at first, supposed that the blast circle was burried in the ground, but when shooting on someone in the air, it didn't appear.

I'll try to fix it myself, and to keep you informed on my plugin's state

Edit: nevermind, I've though about it during school,
Code:
public precache()
here is my problem, thanks anyway and sorry for asking foolish question.


All times are GMT -4. The time now is 22:19.

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