View Single Post
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 09-02-2020 , 06:35   Re: DoubleJump problems
Reply With Quote #2

...I tried mimic code from TF2, AirDash()


This work behind sm_test command.
- There is no jump limits or ground entity check. You can spam.
- I made simple, check which buttons are pressed and send player to that direction.
- Angle is taken from player body, not eyes, like in original code.
- Tested only in CSGO. In other games right and left buttons can be different.

Here is one more snippet
[SNIPPET] Detecting button presses (and releases)


PHP Code:

ConVar sv_maxspeed
;
ConVar sv_cs_player_speed_has_hostage;
ConVar mp_heavyassaultsuit_speed;
//ConVar mp_shield_speed_deployed;
//ConVar mp_shield_speed_holstered;



#include <sdktools>

public void OnPluginStart()
{
    
sv_maxspeed FindConVar("sv_maxspeed");
    if(
sv_maxspeed == nullSetFailState("Game has no ConVar 'sv_maxspeed' ");
    
    
sv_cs_player_speed_has_hostage FindConVar("sv_cs_player_speed_has_hostage");
    
mp_heavyassaultsuit_speed FindConVar("mp_heavyassaultsuit_speed");
    
//mp_shield_speed_deployed = FindConVar("mp_shield_speed_deployed");
    //mp_shield_speed_holstered = FindConVar("mp_shield_speed_holstered");

    
RegConsoleCmd("sm_test"test);
}

public 
Action test(int clientint args)
{
    
TFGameMovement_AirDash(client);

    return 
Plugin_Handled;
}




// snip TF2 Scout AirDash()
void TFGameMovement_AirDash(int client)
{

    
float flJumpMod 1.0;
    
    
/*
        to do: code for JumpMod
    */



    // TF2 Scout Air Dash jump up boost velocity
    
float flDashZ 268.3281572999747 flJumpMod;
    

    
// Calculate x, y angle, direction of player body in world, in vectors
    
float m_vecViewAngles[3], vecForward[3], vecRight[3];

    
GetClientAbsAngles(clientm_vecViewAngles);
    
GetAngleVectors(m_vecViewAnglesvecForwardvecRightNULL_VECTOR);

    
// clear z-axis
    
vecForward[2] = 0.0;
    
vecRight[2] = 0.0;


    
// Scale vector length to 1.0 (unit vector )?
    
NormalizeVector(vecForwardvecForward);
    
NormalizeVector(vecRightvecRight);


    
// Set base speed value
    
float m_flMaxSpeed 240.0;

    
GetPlayerMaxSpeed(clientm_flMaxSpeed); // <-- remove this if you don't want edit speed


    // Into this next code, I don't understand how flForwardMove & flSideMove get value in original code.
    // So I made this simple way... check buttons pressed -> set velocity in that direction

    
int buttons GetClientButtons(client);

    
// player pressing both buttons
    
if(buttons IN_FORWARD && buttons IN_BACK)
    {
        
buttons &= ~IN_FORWARD & ~IN_BACK;
    }
    
    
// player pressing both buttons
    
if(buttons IN_MOVERIGHT && buttons IN_MOVELEFT)
    {
        
buttons &= ~IN_MOVERIGHT & ~IN_MOVELEFT;
    }


    
float flForwardMove =     buttons IN_FORWARD    m_flMaxSpeed:(buttons IN_BACK        ? -1.0 m_flMaxSpeed:0.0);
    
float flSideMove =         buttons IN_MOVERIGHT    m_flMaxSpeed:(buttons IN_MOVELEFT    ? -1.0 m_flMaxSpeed:0.0);





    
// "Find the direction, velocity in the x,y plane." - original comment in Valve code
    
float vecWishDirection[3];
    
vecWishDirection[0] = ( vecForward[0] * flForwardMove ) + ( vecRight[0] * flSideMove );
    
vecWishDirection[1] = ( vecForward[1] * flForwardMove ) + ( vecRight[1] * flSideMove );
    
vecWishDirection[2] = flDashZ;

    

    
// update player vecVelocity[]
    
TeleportEntity(clientNULL_VECTORNULL_VECTORvecWishDirection);
}



// Different situations when player max speed is capped
// 
void GetPlayerMaxSpeed(int clientfloat &speed)
{


    
//float speed; = BaseClass::GetPlayerMaxSpeed();

    
if(HasEntProp(clientProp_Send"m_flMaxSpeed"))
    {
        
speed GetEntPropFloat(clientProp_Send"m_flMaxspeed");
        
        if(
speed sv_maxspeed.FloatValue)
        {
            
speed sv_maxspeed.FloatValue;
        }
    }



    if(
HasEntProp(clientProp_Send"m_hCarriedHostage") && GetEntPropEnt(clientProp_Send"m_hCarriedHostage") != -1)
    {
        if(
sv_cs_player_speed_has_hostage != null && speed sv_cs_player_speed_has_hostage.FloatValue)
        {
            
speed sv_cs_player_speed_has_hostage.FloatValue;
        }
    }

    if(
HasEntProp(clientProp_Send"m_bHasHeavyArmor") && GetEntProp(clientProp_Send"m_bHasHeavyArmor"))
    {
        if(
mp_heavyassaultsuit_speed != null && speed mp_heavyassaultsuit_speed.FloatValue)
        {
            
speed mp_heavyassaultsuit_speed.FloatValue;
        }
    }
    
    
// to do: weapon max speed
}


/*

// piece of original code

    speed = MIN( CS_PLAYER_SPEED_RUN, speed );
    
    if ( IsVIP() == true )  // VIP is slow due to the armour he's wearing
    {
        speed = CS_PLAYER_SPEED_VIP;
    }
    else if ( m_hCarriedHostage != NULL )
    {
        speed = CS_PLAYER_SPEED_HAS_HOSTAGE;
    }
    else
    {
        CWeaponCSBase *pWeapon = dynamic_cast<CWeaponCSBase*>( GetActiveWeapon() );

        if ( pWeapon )
        {
            if ( HasShield() && IsShieldDrawn() )
            {
                speed = MIN( CS_PLAYER_SPEED_SHIELD, speed );    
            }
            else
            {
                speed = MIN( pWeapon->GetMaxSpeed(), speed );
            }
        }
    }
}
*/ 
__________________
Do not Private Message @me

Last edited by Bacardi; 09-02-2020 at 08:15. Reason: -1 to -1.0
Bacardi is offline