AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   +use Button | 3Sec Boost | 20 Sec Cooldown. (https://forums.alliedmods.net/showthread.php?t=160489)

ImXinR 06-27-2011 03:45

+use Button | 3Sec Boost | 20 Sec Cooldown.
 
How Do I set the user like , By press +use (e button) They can boost for 3 seconds & a 20 second cool down . They just have to press E once , Then they will be able to boost for 3 sec.
I've tried using & reading the method here > [TUT] Using Button Constant but still doesn't work . Its either it doesn't work or the player the moment on spawn , keep walking to the front . Also , I've already read all post / thread regarding to button , but still it didn't helped me in any .

EDIT ;
Can someone just help me edit this code below to the button +use to speed instead of shift key ? But I still need the 3 sec boost & 20 second cool down.
PHP Code:

#include <amxmodx>
#include <fakemeta>

new boolg_sprint[33]
new 
cvar_speed

public plugin_init()
{
    
register_plugin("Sprint""0.1""Mini_Midget");
    
cvar_speed register_cvar("sprint_speed""400");
    
register_forwardFM_CmdStart"FMCmdStart" );
    
register_forwardFM_PlayerPreThink"FMPreThink" );
    
register_forward(FM_UpdateClientData"FMUpdateClientData"1)
    
}

public 
client_putinserver(id)
{
    
g_sprint[id] = false
}

public 
FMCmdStartiduc_handlerandseed )
{
    if (!
is_user_alive(id))
        return 
FMRES_IGNORED
        
    
new Float:fmoveFloat:smove;
    
get_uc(uc_handleUC_ForwardMovefmove);
    
get_uc(uc_handleUC_SideMovesmove );
    
    new 
Float:maxspeed;
    
pev(idpev_maxspeedmaxspeed);
    new 
Float:walkspeed = (maxspeed 0.52); 
    
fmove floatabsfmove );
    
smove floatabssmove );
    
    if(
fmove <= walkspeed && smove <= walkspeed && !(fmove == 0.0 && smove == 0.0))
    { 
        
//client_print( id, print_center, "WALKING" );
        
g_sprint[id] = true
    
}
    else
    {
        
//client_print( id, print_center, "RUNNING" );    
        
g_sprint[id] = false
    
}
    
    return 
FMRES_IGNORED
}

public 
FMPreThink(id)
{
    if (!
is_user_alive(id))
        return 
FMRES_IGNORED
    
    
static flag flag pev(idpev_flags)
    static 
button button pev(idpev_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
        
    
static Floatsprinting[3], Floatnormal[3]
    static 
speed speed get_pcvar_num(cvar_speed)
    
    
velocity_by_aim(idspeedsprinting//Speed
    
pev(idpev_velocitynormal)
    
sprinting[2] = normal[2]
    
    if (
g_sprint[id] == true//Walking
    
{
        
set_pev(idpev_velocitysprinting//Set the speed of sprinting
        
set_pev(idpev_buttonpev(id,pev_button) & ~IN_ATTACK);
        
set_pev(idpev_buttonpev(id,pev_button) & ~IN_ATTACK2 );    
        
engclient_cmd(id"weapon_knife")
        
//set_pev(id, pev_viewmodel2, "")
    
}
    else if (
g_sprint[id] == false//Running
    
{
        
set_pev(idpev_velocitynormal)  //Return to normal speed
    
}
    
    return 
FMRES_IGNORED
}

public 
FMUpdateClientData(idsendweaponscd_handle )
{
    if ( !
is_user_alive(id) || !g_sprint[id])
        return 
FMRES_IGNORED;

    
set_cd(cd_handleCD_ID0);        
        
    return 
FMRES_HANDLED;


Get From Here

Exolent[jNr] 06-27-2011 09:30

Re: +use Button | 3Sec Boost | 20 Sec Cooldown.
 
PHP Code:

#include <amxmodx>
#include <fakemeta>

new boolg_sprint[33]
new 
cvar_speed

public plugin_init()
{
    
register_plugin("Sprint""0.1""Mini_Midget");
    
cvar_speed register_cvar("sprint_speed""400");
    
register_forwardFM_CmdStart"FMCmdStart" );
    
register_forwardFM_PlayerPreThink"FMPreThink" );
    
register_forward(FM_UpdateClientData"FMUpdateClientData"1)
    
}

public 
client_putinserver(id)
{
    
g_sprint[id] = false
}

public 
FMCmdStartiduc_handlerandseed )
{
    if (!
is_user_alive(id))
        return 
FMRES_IGNORED
        
    
if(get_uc(uc_handleUC_Buttons) & IN_USE)
    { 
        
g_sprint[id] = true
    
}
    else
    {
        
g_sprint[id] = false
    
}
    
    return 
FMRES_IGNORED
}

public 
FMPreThink(id)
{
    if (!
is_user_alive(id))
        return 
FMRES_IGNORED
    
    
static flag flag pev(idpev_flags)
    static 
button button pev(idpev_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
        
    
static Floatsprinting[3], Floatnormal[3]
    static 
speed speed get_pcvar_num(cvar_speed)
    
    
velocity_by_aim(idspeedsprinting//Speed
    
pev(idpev_velocitynormal)
    
sprinting[2] = normal[2]
    
    if (
g_sprint[id] == true//Walking
    
{
        
set_pev(idpev_velocitysprinting//Set the speed of sprinting
        
set_pev(idpev_buttonpev(id,pev_button) & ~IN_ATTACK);
        
set_pev(idpev_buttonpev(id,pev_button) & ~IN_ATTACK2 );    
        
engclient_cmd(id"weapon_knife")
        
//set_pev(id, pev_viewmodel2, "")
    
}
    else if (
g_sprint[id] == false//Running
    
{
        
set_pev(idpev_velocitynormal)  //Return to normal speed
    
}
    
    return 
FMRES_IGNORED
}

public 
FMUpdateClientData(idsendweaponscd_handle )
{
    if ( !
is_user_alive(id) || !g_sprint[id])
        return 
FMRES_IGNORED;

    
set_cd(cd_handleCD_ID0);        
        
    return 
FMRES_HANDLED;



ImXinR 06-27-2011 10:24

Re: +use Button | 3Sec Boost | 20 Sec Cooldown.
 
Ok thanks , Can you help me add 20 sec delay , 3 sec boosting?

FoxueR 06-27-2011 11:03

Re: +use Button | 3Sec Boost | 20 Sec Cooldown.
 
Try this:

PHP Code:

#include <amxmodx>
#include <fakemeta>

new boolg_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_forwardFM_CmdStart"FMCmdStart" );
    
register_forwardFM_PlayerPreThink"FMPreThink" );
    
register_forward(FM_UpdateClientData"FMUpdateClientData"1)
    
}

public 
client_putinserver(id)
{
    
g_sprint[id] = false
}

public 
FMCmdStartiduc_handlerandseed )
{
    if (!
is_user_alive(id))
        return 
FMRES_IGNORED

    
new Float:curtime get_gametime()
        
    if ( 
curtime gStartTime[id] > get_pcvar_floatcvar_cooldown ) ) 
    {
        if(
get_uc(uc_handleUC_Buttons) & IN_USE)
        { 
            
g_sprint[id] = true
            gStartTime
[id] = curtime
        
}
        else
        {
            
g_sprint[id] = false
        
}
    }
    
    return 
FMRES_IGNORED
}

public 
FMPreThink(id)
{
    if (!
is_user_alive(id))
        return 
FMRES_IGNORED
    
    
static flag flag pev(idpev_flags)
    static 
button button pev(idpev_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
        
    
static Floatsprinting[3], Floatnormal[3]
    static 
speed speed get_pcvar_num(cvar_speed)
    
    
velocity_by_aim(idspeedsprinting//Speed
    
pev(idpev_velocitynormal)
    
sprinting[2] = normal[2]
    
    if ( 
g_sprint[id] == true && get_gametime() - gStartTime[id] < get_pcvar_floatcvar_speedtime ) ) //Walking
    
{
        
set_pev(idpev_velocitysprinting//Set the speed of sprinting
        
set_pev(idpev_buttonpev(id,pev_button) & ~IN_ATTACK);
        
set_pev(idpev_buttonpev(id,pev_button) & ~IN_ATTACK2 );    
        
engclient_cmd(id"weapon_knife")
        
//set_pev(id, pev_viewmodel2, "")
    
}
    else if (
g_sprint[id] == false//Running
    
{
        
set_pev(idpev_velocitynormal)  //Return to normal speed
    
}
    
    return 
FMRES_IGNORED
}

public 
FMUpdateClientData(idsendweaponscd_handle )
{
    if ( !
is_user_alive(id) || !g_sprint[id])
        return 
FMRES_IGNORED;

    
set_cd(cd_handleCD_ID0);        
        
    return 
FMRES_HANDLED;



Exolent[jNr] 06-27-2011 12:39

Re: +use Button | 3Sec Boost | 20 Sec Cooldown.
 
Some optimizations:
PHP Code:

#include <amxmodx>
#include <fakemeta>

new boolg_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_forwardFM_CmdStart"FMCmdStart" );
    
register_forwardFM_PlayerPreThink"FMPreThink" );
    
register_forward(FM_UpdateClientData"FMUpdateClientData"1)
    
}

public 
client_putinserver(id)
{
    
g_sprint[id] = false
}

public 
FMCmdStartiduc_handlerandseed )
{
    if (!
is_user_alive(id))
        return 
FMRES_IGNORED
    
    
if(g_sprint[id])
    {
        if(~
get_uc(uc_handleUC_Buttons) & IN_USE
        
|| get_gametime() - gStartTime[id] > get_pcvar_float(cvar_speedtime))
        {
            
g_sprint[id] = false
        
}
    }
    else if(
get_uc(uc_handleUC_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(idpev_flags)
    static 
button button pev(idpev_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 
Floatsprinting[3], Floatnormal[3]
        
        
velocity_by_aim(idget_pcvar_num(cvar_speed), sprinting//Speed
        
pev(idpev_velocitynormal)
        
sprinting[2] = normal[2]
        
        
set_pev(idpev_velocitysprinting//Set the speed of sprinting
        
set_pev(idpev_buttonbutton & ~(IN_ATTACK|IN_ATTACK2));   
        
engclient_cmd(id"weapon_knife")
        
//set_pev(id, pev_viewmodel2, "")
    
}
    
    return 
FMRES_IGNORED
}

public 
FMUpdateClientData(idsendweaponscd_handle )
{
    if ( !
is_user_alive(id) || !g_sprint[id])
        return 
FMRES_IGNORED;

    
set_cd(cd_handleCD_ID0);        
        
    return 
FMRES_HANDLED;



FoxueR 06-27-2011 13:43

Re: +use Button | 3Sec Boost | 20 Sec Cooldown.
 
Trivial.

Exolent[jNr] 06-27-2011 13:49

Re: +use Button | 3Sec Boost | 20 Sec Cooldown.
 
Quote:

Originally Posted by FoxueR (Post 1497964)
Trivial.

Maybe the logic.
However, resetting the velocity in the PreThink hook was only setting the velocity that the player already had, so it was useless.
Also, there were extra native calls to pev() for pev_button in PreThink.

FoxueR 06-27-2011 13:56

Re: +use Button | 3Sec Boost | 20 Sec Cooldown.
 
Quote:

Originally Posted by Exolent[jNr] (Post 1497975)
Maybe the logic.
However, resetting the velocity in the PreThink hook was only setting the velocity that the player already had, so it was useless.
Also, there were extra native calls to pev() for pev_button in PreThink.

True.

ImXinR 06-28-2011 04:07

Re: +use Button | 3Sec Boost | 20 Sec Cooldown.
 
Thanks ! Can you help me add also the client_print message for like "You can boost for %s Sec . and , You have to wait for %s cooldown .


All times are GMT -4. The time now is 23:29.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.