AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to give a player a velocity to left / right (https://forums.alliedmods.net/showthread.php?t=120438)

cs1.7 03-04-2010 21:01

How to give a player a velocity to left / right
 
Hi,

how can you give a player a certain velocity towards his left side or towards his right side?

This velocity would have to last for let's say only 0.1 seconds.



O
<-----V to left------ -|- -----V to right----->
/\

wrecked_ 03-04-2010 21:07

Re: How to give a player a velocity to left / right
 
https://forums.alliedmods.net/showth...hlight=vectors

cs1.7 03-04-2010 23:56

Re: How to give a player a velocity to left / right
 
Thanks,

the link was really good.


I'm trying to get the forward movement to work before i try with the sides but it aint easy. :)




PHP Code:

public Forward_move_function(id)
{
    static 
Float:fVelocity[3];
    
pev(idpev_anglesfVelocity)

    static 
Float:client_origin[3];
    
pev(idpev_originclient_origin);
   
    new 
Float:velocity[3];

    
velocity[0] = fVelocity[0] + 600;
    
velocity[1] = fVelocity[1] + 600;
    
velocity[2] = fVelocity[2] + 600;


Is it maybe because i have to define the above function in Prethink?

ConnorMcLeod 03-05-2010 01:47

Re: How to give a player a velocity to left / right
 
Not tested, basically same code as velocity_by_aim

PHP Code:

enum {
    
Move_Left,
    
Move_Right,
}

SideMove(idFloat:fSpeedFloat:vRetValue[3], iDirection)
{
    new 
Float:fVecAngles[3], Float:fVecVright[3], Float:fVecVelocity[3]
    
pev(idpev_anglesfVecAngles)
    
engfunc(EngFunc_MakeVectorsfVecAngles)
    
global_get(glb_v_rightfVecVright)
    
pev(idpev_velocityfVecVelocity)

    if( 
iDirection == Move_Left )
    {
        
fVecAngles[0] = -fVecAngles[0]
        
fVecAngles[1] = -fVecAngles[1]
    }

    
fVecVelocity[0] = fVecAngles[0] * fSpeed
    fVecVelocity
[1] = fVecAngles[1] * fSpeed
    fVecVelocity
[2] = fSpeed

    set_pev
(idpev_velocityfVecVelocity)



cs1.7 03-07-2010 13:32

Re: How to give a player a velocity to left / right
 
Thanks ConnorMcLeod,

i tested it but i am not sure if it works or not. I just pasted it in a .sma and compiled it. I couldn't really notice any speeds.



I tried it this way but for some reason, you cannot jump while the below velocity code is in action. Why!? :cry:

Can you please correct this code? The current velocity code will disable players jumping ability. Currently you do get a short burst but you cannot jump, although you have pressed the jump button. :cry:

What i want is a "Dodge" jump. Like when you are under fire, you press e.g. D+JUMP and you get a boost jump to the side to get out of the trouble zone.

Thanks. :)

PHP Code:

new bool:fboost[MAX_PLAYERS+1]
new 
bool:bboost[MAX_PLAYERS+1]
new 
bool:rboost[MAX_PLAYERS+1]
new 
bool:lboost[MAX_PLAYERS+1]



public 
client_PreThink(id)
{
    if(!
is_user_alive(id)) return;
    
    new 
button pev(idpev_button);
    
    if((
button IN_JUMP) && (button IN_FORWARD) && pev(id,pev_flags)&FL_ONGROUND && !is_user_bot(id))
    {
    
fboost[id] = true
    set_task 
(0.3"boost_end"id)
    }
    
    if((
button IN_JUMP) && (button IN_BACK) && pev(id,pev_flags)&FL_ONGROUND && !is_user_bot(id))
    {
    
bboost[id] = true
    set_task 
(0.3"boost_end"id)
    }
    
    if((
button IN_JUMP) && (button IN_MOVERIGHT) && pev(id,pev_flags)&FL_ONGROUND && !is_user_bot(id))
    {
    
rboost[id] = true
    set_task 
(0.3"boost_end"id)
    }
    
    if((
button IN_JUMP) && (button IN_MOVELEFT) && pev(id,pev_flags)&FL_ONGROUND && !is_user_bot(id))
    {
    
lboost[id] = true
    set_task 
(0.3"boost_end"id)
    }
      
    new 
Float:maxspeed 600.0;

    static 
Float:aim_velocity[3];
    
velocity_by_aim(idfloatround(maxspeed), aim_velocity);
    
    static 
Float:client_origin[3];
    
pev(idpev_originclient_origin);
    
    new 
Float:velocity[3];
    
    if (
fboost[id])
    {
        
velocity[0] += aim_velocity[0];
        
velocity[1] += aim_velocity[1];
        
velocity[2] += aim_velocity[2];
        
set_pev(idpev_velocityvelocity);
    }
    if (
bboost[id])
    {
        
velocity[0] -= aim_velocity[0];
        
velocity[1] -= aim_velocity[1];
        
velocity[2] -= aim_velocity[2];
        
set_pev(idpev_velocityvelocity);
    }
    if (
rboost[id])
    {
        
velocity[0] += aim_velocity[1];
        
velocity[1] -= aim_velocity[0];
        
set_pev(idpev_velocityvelocity);
    }
    if (
lboost[id])
    {
        
velocity[0] -= aim_velocity[1];
        
velocity[1] += aim_velocity[0];
        
set_pev(idpev_velocityvelocity);
    }
}

public 
boost_end(id)
{
    
fboost[id] = false
    bboost
[id] = false
    rboost
[id] = false
    lboost
[id] = false




All times are GMT -4. The time now is 08:45.

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