Seule chose sur le fonctionnement, si on relâche avancer ou attack2 avant la fin du sprint, on doit quand même attendre le délai par défaut avant de pouvoir reprinter, ça facilitait grandement le code.
PHP Code:
#include < amxmodx >
#include < fakemeta >
#include < hamsandwich >
#include < fun >
#pragma semicolon 1
#define PLUGIN "Sprint"
#define VERSION "0.0.1"
new const BREATHE_SOUND[] = "player/breathe.wav";
new g_bSprinting[33 char];
new Float:g_flSprintEndTime[33];
new Float:g_flSprintNextTime[33];
new g_pcvarSprintTime, g_pcvarSprintSpeed, g_pcvarSprintDelay;
public plugin_init()
{
register_plugin( PLUGIN, VERSION, "ConnorMcLeod" );
g_pcvarSprintTime = register_cvar("amx_sprint_time", "5.0");
g_pcvarSprintDelay = register_cvar("amx_sprint_delay", "5.0");
g_pcvarSprintSpeed = register_cvar("amx_sprint_maxspeed", "320.0");
register_forward(FM_CmdStart, "OnCmdStart");
RegisterHam(Ham_CS_Player_ResetMaxSpeed, "player", "OnCBasePlayer_ResetMaxSpeed_P", true);
}
public plugin_precache()
{
precache_sound( BREATHE_SOUND );
}
public client_putinserver(id)
{
g_bSprinting{id} = false;
}
public OnCmdStart(id, cmd)
{
if( is_user_alive(id) )
{
new button = get_uc(cmd, UC_Buttons) & (IN_ATTACK2|IN_FORWARD);
new Float:flTime = get_gametime();
if( g_bSprinting{id} )
{
if( button != (IN_ATTACK2|IN_FORWARD)
|| g_flSprintEndTime[id] <= flTime )
{
g_bSprinting{id} = false;
ExecuteHamB(Ham_CS_Player_ResetMaxSpeed, id);
g_flSprintNextTime[id] = flTime + get_pcvar_float(g_pcvarSprintDelay);
Util_BarTime_f(id, 0.0);
if( g_flSprintEndTime[id] <= flTime )
{
emit_sound(id, CHAN_VOICE, BREATHE_SOUND, VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
}
}
}
else if( button == (IN_ATTACK2|IN_FORWARD) && get_user_maxspeed(id) != 1.0 )
{
if( g_flSprintNextTime[id] <= flTime )
{
g_bSprinting{id} = true;
new Float:flSprintTime = get_pcvar_float(g_pcvarSprintTime);
g_flSprintEndTime[id] = flTime + flSprintTime;
set_user_maxspeed(id, get_pcvar_float(g_pcvarSprintSpeed));
Util_BarTime_f(id, flSprintTime);
}
else
{
client_print(id, print_center, "Tu dois attendre %.1f secondes", g_flSprintNextTime[id] - flTime);
}
}
}
}
public OnCBasePlayer_ResetMaxSpeed_P( id )
{
if( g_bSprinting{id} && is_user_alive(id) && get_user_maxspeed(id) != 1.0 )
{
set_user_maxspeed(id, get_pcvar_float(g_pcvarSprintSpeed));
}
}
Util_BarTime_f(id, Float:flTime = 0.0)
{
if( flTime < -0.0 )
{
return;
}
static msgBarTime2 = 0;
if( !msgBarTime2 )
{
msgBarTime2 = get_user_msgid("BarTime2");
}
new iSeconds = floatround(flTime, floatround_ceil);
message_begin(id ? MSG_ONE : MSG_ALL, msgBarTime2, _, id);
write_short( iSeconds );
write_short( 100 - floatround( (flTime/ iSeconds ) * 100 ) );
message_end();
}
__________________