#pragma semicolon 1
#include <amxmodx>
#define PLUGIN "Swim Speed Limiter"
#define VERSION "1.0"
#define AUTHOR "Admrfsh"
#include <reapi>
#include <xs>
new g_pCvarPluginEnable;
new Float:g_fCvarSwimHorizontalMaxSpeed;
new HookChain:g_hEventCBasePlayerJump;
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
hook_cvar_change(
(g_pCvarPluginEnable = create_cvar("ssl_enable", "0", FCVAR_NONE, "Enable/disable plugin.", true, 0.0, true, 1.0)),
"OnEvent_CvarChange_PluginEnable"
);
bind_pcvar_float(
create_cvar("ssl_speed", "350", FCVAR_NONE, "Set horizontal swimming speed limit.", true, 1.0),
g_fCvarSwimHorizontalMaxSpeed
);
g_hEventCBasePlayerJump = RegisterHookChain(RG_CBasePlayer_Jump, "OnEvent_CBasePlayer_Jump", true);
if (!get_pcvar_num(g_pCvarPluginEnable))
{
DisableHookChain(g_hEventCBasePlayerJump);
}
}
public OnEvent_CvarChange_PluginEnable(const pCvar, const oldValue[], const newValue[])
{
strtol(newValue) ?
EnableHookChain(g_hEventCBasePlayerJump) :
DisableHookChain(g_hEventCBasePlayerJump);
}
public OnEvent_CBasePlayer_Jump(const iPlayerId)
{
if (get_entvar(iPlayerId, var_waterlevel) == 1)
{
static Float:fVecPlayerVelocity[3];
static Float:fPlayerHorizontalSpeed;
get_entvar(iPlayerId, var_velocity, fVecPlayerVelocity);
fPlayerHorizontalSpeed = xs_vec_len_2d(fVecPlayerVelocity);
if (fPlayerHorizontalSpeed > g_fCvarSwimHorizontalMaxSpeed)
{
fPlayerHorizontalSpeed = g_fCvarSwimHorizontalMaxSpeed / fPlayerHorizontalSpeed;
fVecPlayerVelocity[0] *= fPlayerHorizontalSpeed;
fVecPlayerVelocity[1] *= fPlayerHorizontalSpeed;
set_entvar(iPlayerId, var_velocity, fVecPlayerVelocity);
}
}
}