From 8f9a66e366a7e43c7c572bc0c6418d952e9b6f91 Mon Sep 17 00:00:00 2001 From: Greyscale Date: Tue, 12 May 2009 04:56:03 +0200 Subject: [PATCH] Added bunnyhop protection. --- src/zr/jumpboost.inc | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/zr/jumpboost.inc b/src/zr/jumpboost.inc index 5ac4cbf..c958add 100644 --- a/src/zr/jumpboost.inc +++ b/src/zr/jumpboost.inc @@ -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. * @@ -25,11 +30,22 @@ JumpBoostOnClientJump(client) new Float:vecVelocity[3]; 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[1] *= distance; + + // Apply vertical jump boost. vecVelocity[2] += height; + // Apply velocity. JumpBoostSetClientVelocity(client, vecVelocity); }