AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Air/Ground Speed Boost (https://forums.alliedmods.net/showthread.php?t=277276)

Syturi0 01-05-2016 23:31

Air/Ground Speed Boost
 
I want to make a speed boost that works both ground and air.

I want it to first get the current speed of the player, and then add a X amount to it (to look like it gets "boosted").

I dont wanna use Velocity by Aim, because like the title says, this needs to work while in Air (for example in Surf)

Full example: If the player is going forward (but its not in the ground), with X current speed, when he shoots he gets +10 speed added to his current speed, whiout changing his direction, i mean, where he aims doesnt effect anything.

I have tryied some methods.
Right now this is what i have:

PHP Code:

public forward_PreThink(id)
{
    if(
pev(idpev_button) & IN_ATTACK)
    {    
        new 
Float:CurrentVelocity[3], Float:FinalVelocity[3]
        
pev(idpev_velocityCurrentVelocity)

        
FinalVelocity[2] = CurrentVelocity[2] + 10
        
        set_pev
(idpev_velocityFinalVelocity)
    }


And ofc it doesnt work correctly.

How can i fix it? Thank you.

siriusmd99 01-06-2016 19:54

Re: Air/Ground Speed Boost
 
Use this to detect if is player surfing and set velocity :click here

Else if is not surfing then set maxspeed to player.

Syturi0 01-07-2016 01:57

Re: Air/Ground Speed Boost
 
Quote:

Originally Posted by siriusmd99 (Post 2380758)
Use this to detect if is player surfing and set velocity :click here

Else if is not surfing then set maxspeed to player.

How can i set velocity? Thats what i asked.
I have tried alot of methods, but none of them work the way i want.

Syturi0 01-07-2016 03:13

Re: Air/Ground Speed Boost
 
For example, when i use
PHP Code:

set_pev(idpev_velocity2000.0

It boosts my speed ye, but it will always make my player/model go into a certain direction of the map, it doesnt go forward or anything according to where i was previosly going (its kinda hard to explain), it just always go to that direction of the map.

How can i fix that?

siriusmd99 01-07-2016 03:55

Re: Air/Ground Speed Boost
 
Get user velocity, multiply it and then set it back, like this:

PHP Code:


new Float:origin[3];
     
pev(iUserpev_velocityorigin)
     
origin[0] *= // it's x
     
origin[1] *= //it's y
     
origin[2] *= //it's z
     
set_pev(iUser,pev_velocity,origin

But i don't understand exactly how it works. I made once like that and it pushed me down on surf, so in this case you shall multiply "x" by 4 ,and z with y by 2.
Just play with z,x,y and try to modify values until you get perfect surfing boost.

klippy 01-07-2016 04:14

Re: Air/Ground Speed Boost
 
It's rather easy, just some simple vector math.

If you want to increase velocity magnitude (speed) by a relative amount (a percentage) in the current direction, you can just multiply it by a scalar value, i.e (you have to include xs.inc):
PHP Code:

new FloatfVelocity[3];

pev(idpev_velocityfVelocity);
xs_vec_mul_scalar(fVelocity1.5fVelocity); // 50% speed boost
set_pev(idpev_velocityfVelocity); 

If you want to increase velocity magnitude by an absolute amount, you have to get a unit vector in the current direction, multiply it by your desired amount, and add it to the current velocity:
PHP Code:

new FloatfVelocity[3], FloatfDirection[3];
    
pev(idpev_velocityfVelocity);
xs_vec_normalize(fVelocityfDirection); // Get unit vector that has the same direction as velocity
xs_vec_mul_scalar(fDirection100.0fDirection); // Multiply it by 100, giving us a vector with magnitude of 100
xs_vec_add(fVelocityfDirectionfVelocity); // Add these 2 together
set_pev(idpev_velocityfVelocity); 


JusTGo 01-07-2016 05:50

Re: Air/Ground Speed Boost
 
Quote:

Originally Posted by KliPPy (Post 2380841)
It's rather easy, just some simple vector math.

If you want to increase velocity magnitude (speed) by a relative amount (a percentage) in the current direction, you can just multiply it by a scalar value, i.e (you have to include xs.inc):
PHP Code:

new FloatfVelocity[3];

pev(idpev_velocityfVelocity);
xs_vec_mul_scalar(fVelocity1.5fVelocity); // 50% speed boost
set_pev(idpev_velocityfVelocity); 

If you want to increase velocity magnitude by an absolute amount, you have to get a unit vector in the current direction, multiply it by your desired amount, and add it to the current velocity:
PHP Code:

new FloatfVelocity[3], FloatfDirection[3];
    
pev(idpev_velocityfVelocity);
xs_vec_normalize(fVelocityfDirection); // Get unit vector that has the same direction as velocity
xs_vec_mul_scalar(fDirection100.0fDirection); // Multiply it by 100, giving us a vector with magnitude of 100
xs_vec_add(fVelocityfDirectionfVelocity); // Add these 2 together
set_pev(idpev_velocityfVelocity); 


how to do it with xs.inc in this case its using origin
Code:
public shovePlayer(id) {     if(!is_user_alive(id))         return PLUGIN_HANDLED         if(get_systime() - gLastShove[id] < get_pcvar_num(cCooldown))     {         client_print(id, print_chat, "[Shove Mod] Your muscles are weak from shoving the player. You must wait to do it again. (%i)", (get_pcvar_num(cCooldown) - (get_systime() - gLastShove[id])))         return PLUGIN_HANDLED     }         new Index,Body, pName[64], tName[64]     get_user_aiming(id,Index,Body,200)         if(!Index || !is_user_alive(Index))         return PLUGIN_HANDLED         new Float:size[3]     pev(id, pev_size, size)     if(size[2] < 72.0)     {         client_print(id, print_chat, "[Shove Mod] You can't shove somebody while doing that action.")         return PLUGIN_HANDLED     }         get_user_name(id, pName, 63)     get_user_name(Index, tName, 63)     new Float:velocity[3], Float:shover[3], Float:shovee[3]     pev(id, pev_origin, shover)     pev(Index, pev_origin, shovee)         for(new Count;Count < 3;Count++)     velocity[Count] = (shovee[Count] - shover[Count]) * get_pcvar_float(cShove)     set_pev(Index, pev_velocity, velocity)     client_print(id, print_chat, "[Shove Mod] You have just shoved %s!", tName)     client_print(Index, print_chat, "[Shove Mod] You have just been shoved by %s!", pName)     gLastShove[id] = get_systime()     return PLUGIN_HANDLED     }

plugin from here : https://forums.alliedmods.net/showthread.php?t=61237

klippy 01-07-2016 05:56

Re: Air/Ground Speed Boost
 
There's no reason to use xs.inc if the current code works properly, XS most likely won't give you any performance boost. Just keep it as it is.

JusTGo 01-07-2016 11:21

Re: Air/Ground Speed Boost
 
Quote:

Originally Posted by KliPPy (Post 2380864)
There's no reason to use xs.inc if the current code works properly, XS most likely won't give you any performance boost. Just keep it as it is.

but there is a chance to get a negative value if the distance is 0 which cause velocity bug.

Syturi0 01-08-2016 01:27

Re: Air/Ground Speed Boost
 
Quote:

Originally Posted by KliPPy (Post 2380841)
It's rather easy, just some simple vector math.

If you want to increase velocity magnitude (speed) by a relative amount (a percentage) in the current direction, you can just multiply it by a scalar value, i.e (you have to include xs.inc):
PHP Code:

new FloatfVelocity[3];

pev(idpev_velocityfVelocity);
xs_vec_mul_scalar(fVelocity1.5fVelocity); // 50% speed boost
set_pev(idpev_velocityfVelocity); 

If you want to increase velocity magnitude by an absolute amount, you have to get a unit vector in the current direction, multiply it by your desired amount, and add it to the current velocity:
PHP Code:

new FloatfVelocity[3], FloatfDirection[3];
    
pev(idpev_velocityfVelocity);
xs_vec_normalize(fVelocityfDirection); // Get unit vector that has the same direction as velocity
xs_vec_mul_scalar(fDirection100.0fDirection); // Multiply it by 100, giving us a vector with magnitude of 100
xs_vec_add(fVelocityfDirectionfVelocity); // Add these 2 together
set_pev(idpev_velocityfVelocity); 


Thank you, thats isactly what i wanted.

:bee::bee:


All times are GMT -4. The time now is 09:27.

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