Improved jump boost settings. See details.

Made a CVAR for setting maximum horizontal speed when bunny hop prevention is enabled.
Made a CVAR for switching between reset modes when maximum speed is reached. Either full reset, or setting to max speed allowed.
This commit is contained in:
richard 2009-05-31 00:13:24 +02:00
parent f23bba58c6
commit db866c6f43
2 changed files with 43 additions and 11 deletions

View File

@ -114,6 +114,8 @@ enum CvarsList
Handle:CVAR_RESPAWN_TEAM_ZOMBIE,
Handle:CVAR_RESPAWN_TEAM_ZOMBIE_WORLD,
Handle:CVAR_JUMPBOOST_BUNNYHOP_PROTECT,
Handle:CVAR_JUMPBOOST_BUNNYHOP_MAX,
Handle:CVAR_JUMPBOOST_BUNNYHOP_RESET,
Handle:CVAR_VOL,
Handle:CVAR_VOL_UPDATE_INTERVAL,
Handle:CVAR_VOL_TRIGGER_INTERVAL,
@ -424,6 +426,8 @@ CvarsCreate()
// Jump Boost (module)
// ===========================
g_hCvarsList[CVAR_JUMPBOOST_BUNNYHOP_PROTECT] = CreateConVar("zr_jumpboost_bunnyhop_protect", "1", "Prevent players from using forward jump boost multipliers to bunny hop.");
g_hCvarsList[CVAR_JUMPBOOST_BUNNYHOP_MAX] = CreateConVar("zr_jumpboost_bunnyhop_max", "275", "The maximum horizontal velocity a player can have for any additional push to be applied, when bunny hop prevention is enabled.");
g_hCvarsList[CVAR_JUMPBOOST_BUNNYHOP_RESET] = CreateConVar("zr_jumpboost_bunnyhop_reset", "1", "Specifies whether the speed should be reset, or limited to maximum when the limit is reached.");
// ===========================

View File

@ -10,11 +10,6 @@
* ============================================================================
*/
/**
* The maximum forward velocity client can have for any additional push to be applied.
*/
#define JUMPBOOST_FORWARD_VEL_MAX 275.0
/**
* Client is jumping.
*
@ -22,30 +17,63 @@
*/
JumpBoostOnClientJump(client)
{
new Float:vecVelocity[3];
new Float:vecBuffer[3];
new Float:magnitude;
// Get class jump multipliers.
new Float:distance = ClassGetJumpDistance(client);
new Float:height = ClassGetJumpHeight(client);
// Do not apply jump boost if class jump boost multiplier is 1.0.
if (height == 1.0)
if (height == 1.0 && distance == 1.0)
{
return;
}
// Get client's current velocity.
new Float:vecVelocity[3];
ToolsClientVelocity(client, vecVelocity, false);
// Protect against bunnyhopping, if cvar is enabled.
// Get bunny hop setting.
new bool:bunnyhopprotect = GetConVarBool(g_hCvarsList[CVAR_JUMPBOOST_BUNNYHOP_PROTECT]);
// Check if bunny hop protection is enabled.
if (bunnyhopprotect)
{
new Float:magnitude = SquareRoot(Pow(vecVelocity[0], 2.0) + Pow(vecVelocity[1], 2.0));
if (magnitude >= JUMPBOOST_FORWARD_VEL_MAX)
// Get jump boost settings.
new bool:bunnyhopreset = GetConVarBool(g_hCvarsList[CVAR_JUMPBOOST_BUNNYHOP_RESET]);
new Float:bunnyhopmax = GetConVarFloat(g_hCvarsList[CVAR_JUMPBOOST_BUNNYHOP_MAX]);
// Get movement distance.
magnitude = SquareRoot(Pow(vecVelocity[0], 2.0) + Pow(vecVelocity[1], 2.0));
// Check if maximum speed is reached and reset setting is set.
if ((magnitude > bunnyhopmax) && bunnyhopreset)
{
// Set distance multiplier to 0.
// Reset horizontal velocity.
distance = 0.0;
}
// Check if maximum speed is reached and reset setting is disabled.
else if ((magnitude > bunnyhopmax) && !bunnyhopreset)
{
// Set horizontal velocity to maximum allowed.
// Copy to buffer.
vecBuffer[0] = vecVelocity[0];
vecBuffer[1] = vecVelocity[1];
vecBuffer[2] = 1.0; // Dummy value.
// Normalize buffer vector to make it a unit vector.
NormalizeVector(vecBuffer, vecBuffer);
// Restore horizontal axis in buffer to velocity vector.
vecVelocity[0] = vecBuffer[0];
vecVelocity[1] = vecBuffer[1];
// Set distance to maximum speed.
distance = bunnyhopmax;
}
}
// Apply forward jump boost.