...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 == null) SetFailState("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 client, int 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(client, m_vecViewAngles);
GetAngleVectors(m_vecViewAngles, vecForward, vecRight, NULL_VECTOR);
// clear z-axis
vecForward[2] = 0.0;
vecRight[2] = 0.0;
// Scale vector length to 1.0 (unit vector )?
NormalizeVector(vecForward, vecForward);
NormalizeVector(vecRight, vecRight);
// Set base speed value
float m_flMaxSpeed = 240.0;
GetPlayerMaxSpeed(client, m_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(client, NULL_VECTOR, NULL_VECTOR, vecWishDirection);
}
// Different situations when player max speed is capped
//
void GetPlayerMaxSpeed(int client, float &speed)
{
//float speed; = BaseClass::GetPlayerMaxSpeed();
if(HasEntProp(client, Prop_Send, "m_flMaxSpeed"))
{
speed = GetEntPropFloat(client, Prop_Send, "m_flMaxspeed");
if(speed > sv_maxspeed.FloatValue)
{
speed = sv_maxspeed.FloatValue;
}
}
if(HasEntProp(client, Prop_Send, "m_hCarriedHostage") && GetEntPropEnt(client, Prop_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(client, Prop_Send, "m_bHasHeavyArmor") && GetEntProp(client, Prop_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 );
}
}
}
}
*/
__________________