Raised This Month: $7 Target: $400
 1% 

+use Button | 3Sec Boost | 20 Sec Cooldown.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ImXinR
Member
Join Date: Dec 2010
Old 06-27-2011 , 03:45   +use Button | 3Sec Boost | 20 Sec Cooldown.
Reply With Quote #1

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
__________________
Sometimes , Life Sucks .. Don't You Agree? But ,
Listening To Music Make Us Feel Better

Last edited by ImXinR; 06-27-2011 at 04:37.
ImXinR is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-27-2011 , 09:30   Re: +use Button | 3Sec Boost | 20 Sec Cooldown.
Reply With Quote #2

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;

__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
ImXinR
Member
Join Date: Dec 2010
Old 06-27-2011 , 10:24   Re: +use Button | 3Sec Boost | 20 Sec Cooldown.
Reply With Quote #3

Ok thanks , Can you help me add 20 sec delay , 3 sec boosting?
__________________
Sometimes , Life Sucks .. Don't You Agree? But ,
Listening To Music Make Us Feel Better
ImXinR is offline
FoxueR
Senior Member
Join Date: Jun 2011
Old 06-27-2011 , 11:03   Re: +use Button | 3Sec Boost | 20 Sec Cooldown.
Reply With Quote #4

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;

__________________
¯\_(ツ)_/¯
FoxueR is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-27-2011 , 12:39   Re: +use Button | 3Sec Boost | 20 Sec Cooldown.
Reply With Quote #5

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;

__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 06-27-2011 at 13:47.
Exolent[jNr] is offline
FoxueR
Senior Member
Join Date: Jun 2011
Old 06-27-2011 , 13:43   Re: +use Button | 3Sec Boost | 20 Sec Cooldown.
Reply With Quote #6

Trivial.
__________________
¯\_(ツ)_/¯
FoxueR is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-27-2011 , 13:49   Re: +use Button | 3Sec Boost | 20 Sec Cooldown.
Reply With Quote #7

Quote:
Originally Posted by FoxueR View Post
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.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
FoxueR
Senior Member
Join Date: Jun 2011
Old 06-27-2011 , 13:56   Re: +use Button | 3Sec Boost | 20 Sec Cooldown.
Reply With Quote #8

Quote:
Originally Posted by Exolent[jNr] View Post
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.
__________________
¯\_(ツ)_/¯
FoxueR is offline
ImXinR
Member
Join Date: Dec 2010
Old 06-28-2011 , 04:07   Re: +use Button | 3Sec Boost | 20 Sec Cooldown.
Reply With Quote #9

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 .
__________________
Sometimes , Life Sucks .. Don't You Agree? But ,
Listening To Music Make Us Feel Better
ImXinR is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:10.


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