#include <amxmodx>
#include <reapi>
new bool:bh_enabled;
public plugin_init()
{
register_plugin("BunnyHop", "Best", "PurposeLess");
RegisterHookChain(RG_CBasePlayer_Jump, "@CBasePlayer__Jump_Post", true);
bind_pcvar_num(create_cvar("bh_enabled", "1", _, "Enable BunnyHop", true, 0.0, true, 1.0), bh_enabled);
}
@CBasePlayer__Jump_Post(iPlayer)
{
if(!bh_enabled)
return;
if(!(get_entvar(iPlayer, var_flags) & FL_ONGROUND))
return;
new Float:vecVelocity[3];
get_entvar(iPlayer, var_velocity, vecVelocity);
PM_PreventMegaBunnyJumping(iPlayer, vecVelocity);
vecVelocity[2] = 268.0;
set_entvar(iPlayer, var_velocity, vecVelocity);
}
PM_PreventMegaBunnyJumping(iPlayer, Float:vecVelocity[3])
{
#define BUNNYJUMP_MAX_SPEED_FACTOR 1.2
new Float:flMaxScaledSpeed = BUNNYJUMP_MAX_SPEED_FACTOR * Float:get_entvar(iPlayer, var_maxspeed);
if(flMaxScaledSpeed <= 0.0)
return;
new Float:flSpeed = vector_length(vecVelocity);
if(flSpeed <= flMaxScaledSpeed)
return;
new Float:flFraction = (flMaxScaledSpeed / flSpeed) * 0.8;
vecVelocity[0] *= flFraction;
vecVelocity[1] *= flFraction;
vecVelocity[2] *= flFraction;
}