Some optimizations:
PHP Code:
#include <amxmodx>
#include <fakemeta>
new bool: g_sprint[33]
new cvar_speed
new cvar_cooldown
new cvar_speedtime
new Float:gStartTime[33]
public plugin_init()
{
register_plugin("Sprint", "0.1", "Mini_Midget");
cvar_speed = register_cvar("sprint_speed", "400");
cvar_cooldown = register_cvar("sprint_cooldown", "20");
cvar_speedtime = register_cvar("sprint_speedtime", "3");
register_forward( FM_CmdStart, "FMCmdStart" );
register_forward( FM_PlayerPreThink, "FMPreThink" );
register_forward(FM_UpdateClientData, "FMUpdateClientData", 1)
}
public client_putinserver(id)
{
g_sprint[id] = false
}
public FMCmdStart( id, uc_handle, randseed )
{
if (!is_user_alive(id))
return FMRES_IGNORED
if(g_sprint[id])
{
if(~get_uc(uc_handle, UC_Buttons) & IN_USE
|| get_gametime() - gStartTime[id] > get_pcvar_float(cvar_speedtime))
{
g_sprint[id] = false
}
}
else if(get_uc(uc_handle, UC_Buttons) & IN_USE)
{
new Float:curtime = get_gametime()
if(curtime - gStartTime[id] > get_pcvar_float(cvar_cooldown))
{
g_sprint[id] = true
gStartTime[id] = curtime
}
}
return FMRES_IGNORED
}
public FMPreThink(id)
{
if (!is_user_alive(id))
return FMRES_IGNORED
static flag ; flag = pev(id, pev_flags)
static button ; button = pev(id, pev_button)
if ( !(flag & FL_ONGROUND) || (flag & FL_DUCKING) || !(button & IN_FORWARD) ) //Block not on ground or ducking or left, back, right movement keys
return FMRES_IGNORED
if ( g_sprint[id] ) //Walking
{
static Float: sprinting[3], Float: normal[3]
velocity_by_aim(id, get_pcvar_num(cvar_speed), sprinting) //Speed
pev(id, pev_velocity, normal)
sprinting[2] = normal[2]
set_pev(id, pev_velocity, sprinting) //Set the speed of sprinting
set_pev(id, pev_button, button & ~(IN_ATTACK|IN_ATTACK2));
engclient_cmd(id, "weapon_knife")
//set_pev(id, pev_viewmodel2, "")
}
return FMRES_IGNORED
}
public FMUpdateClientData(id, sendweapons, cd_handle )
{
if ( !is_user_alive(id) || !g_sprint[id])
return FMRES_IGNORED;
set_cd(cd_handle, CD_ID, 0);
return FMRES_HANDLED;
}
__________________