View Single Post
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 09-29-2013 , 17:22   Re: [CREATION] plugin sprint
#8

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_pcvarSprintTimeg_pcvarSprintSpeedg_pcvarSprintDelay;

public 
plugin_init()
{
    
register_pluginPLUGINVERSION"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_soundBREATHE_SOUND );
}

public 
client_putinserver(id)
{
    
g_bSprinting{id} = false;
}

public 
OnCmdStart(idcmd)
{
    if( 
is_user_alive(id) )
    {
        new 
button get_uc(cmdUC_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_ResetMaxSpeedid);
                
g_flSprintNextTime[id] = flTime get_pcvar_float(g_pcvarSprintDelay);
                
Util_BarTime_f(id0.0);
                if( 
g_flSprintEndTime[id] <= flTime )
                {
                    
emit_sound(idCHAN_VOICEBREATHE_SOUNDVOL_NORMATTN_NORM0PITCH_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(idget_pcvar_float(g_pcvarSprintSpeed));
                
Util_BarTime_f(idflSprintTime);
            }
            else
            {
                
client_print(idprint_center"Tu dois attendre %.1f secondes"g_flSprintNextTime[id] - flTime);
            }
        }
    }
}

public 
OnCBasePlayer_ResetMaxSpeed_Pid )
{
    if( 
g_bSprinting{id} && is_user_alive(id) && get_user_maxspeed(id) != 1.0 )
    {
        
set_user_maxspeed(idget_pcvar_float(g_pcvarSprintSpeed));
    }
}

Util_BarTime_f(idFloat:flTime 0.0)
{
    if( 
flTime < -0.0 )
    {
        return;
    }

    static 
msgBarTime2 0;
    if( !
msgBarTime2 )
    {
        
msgBarTime2 get_user_msgid("BarTime2");
    }

    new 
iSeconds floatround(flTimefloatround_ceil);

    
message_begin(id MSG_ONE MSG_ALLmsgBarTime2_id);
    
write_shortiSeconds );
    
write_short100 floatround( (flTimeiSeconds ) * 100 ) );
    
message_end();

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline