Added bunnyhop protection.

This commit is contained in:
Greyscale 2009-05-12 04:56:03 +02:00
parent 8aa9b7dcc7
commit 8f9a66e366

View File

@ -10,6 +10,11 @@
* ============================================================================ * ============================================================================
*/ */
/**
* The maximum forward velocity client can have for any additional push to be applied.
*/
#define JUMPBOOST_FORWARD_VEL_MAX 275.0
/** /**
* Client is jumping. * Client is jumping.
* *
@ -25,11 +30,22 @@ JumpBoostOnClientJump(client)
new Float:vecVelocity[3]; new Float:vecVelocity[3];
ToolsClientVelocity(client, vecVelocity, false); ToolsClientVelocity(client, vecVelocity, false);
// Apply jump values. // Protect against bunnyhopping.
new Float:magnitude = SquareRoot(Pow(vecVelocity[0], 2.0) + Pow(vecVelocity[1], 2.0));
if (magnitude >= JUMPBOOST_FORWARD_VEL_MAX)
{
// Set distance multiplier to 0.
distance = 0.0;
}
// Apply forward jump boost.
vecVelocity[0] *= distance; vecVelocity[0] *= distance;
vecVelocity[1] *= distance; vecVelocity[1] *= distance;
// Apply vertical jump boost.
vecVelocity[2] += height; vecVelocity[2] += height;
// Apply velocity.
JumpBoostSetClientVelocity(client, vecVelocity); JumpBoostSetClientVelocity(client, vecVelocity);
} }