Raised This Month: $ Target: $400
 0% 

block a command for a certain time


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Shiro
Junior Member
Join Date: Nov 2010
Old 01-06-2011 , 06:26   block a command for a certain time
Reply With Quote #1

Hi all,
How to block a command for a certain time? For 5 or more seconds.. thanks

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>

#define PLUGIN "Respawn"
#define VERSION "1.0"
#define AUTHOR "fR4gn0tiX!"

new lastused[33]

stock register_saycmd(saycommand[], function[], flags = -1info[])
{
    static 
sTemp[64]
    
formatex(sTempsizeof sTemp 1"say /%s"saycommand)
    
register_clcmd(sTemp, function, flagsinfo)
    
formatex(sTempsizeof sTemp 1"say .%s"saycommand)
    
register_clcmd(sTemp, function, flagsinfo)
    
formatex(sTempsizeof sTemp 1"say_team /%s"saycommand)
    
register_clcmd(sTemp, function, flagsinfo)
    
formatex(sTempsizeof sTemp 1"say_team .%s"saycommand)
    
register_clcmd(sTemp, function, flagsinfo)
}


public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_cvar("gacocxleba""v1.0 by fR4gn0tiX!"FCVAR_SERVER|FCVAR_SPONLY)
    
    
register_concmd("amx_respawn""cmd_gacocxleba"ADMIN_SLAY"< saxeli | #userid > - Respawn player")    
    
register_saycmd("respawn""cl_gacocxleba"ADMIN_SLAY"Respawn yourself")            
}

public 
cmd_gacocxleba(idlevelcid)
{
    if (!
cmd_access(idlevelcid2))
       return 
PLUGIN_HANDLED
       
    
new Argument[32
    
    
read_argv(1Argument31
    
    new 
Target cmd_target(idArgumentCMDTARGET_ALLOW_SELF CMDTARGET_OBEY_IMMUNITY
    
    if (
Target
    {    
        if (
is_user_alive(Target)) 
        {
            new 
saxeli[32]            
            
get_user_name(Targetsaxeli31)    
            
            
console_print(id"%s is already alive!"saxeli
            return 
PLUGIN_HANDLED
        
}
        
        
ExecuteHamB(Ham_CS_RoundRespawnTarget)
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_HANDLED
}

public 
cl_gacocxleba(id)
{
    if (
is_user_alive(id)) 
    {
        
client_print(idprint_chat"You are already alive!"
        return 
PLUGIN_HANDLED
    
}
    
    
ExecuteHamB(Ham_CS_RoundRespawnid
    return 
PLUGIN_HANDLED


Last edited by Shiro; 01-06-2011 at 06:32.
Shiro is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 01-06-2011 , 06:36   Re: block a command for a certain time
Reply With Quote #2

You would check a certain global variable whether or not the action related to the command should be executed. When blocking the command you would change the value of the global variable and set_task to change the global variable to it's original value.
SnoW is offline
Send a message via MSN to SnoW
Elusive138
Senior Member
Join Date: Dec 2010
Old 01-06-2011 , 07:25   Re: block a command for a certain time
Reply With Quote #3

For this kind of purpose (cooldown) it should be more efficient to do this..

PHP Code:
new Float:gCooldown[33], cvarCooldown

public plugin_init() {
    
cvarCooldown register_cvar("revive_cooldown""5.0"FCVAR_SPONLY)
}

public 
ReviveFunction(id)
{
    
// access level check (cmd_access) here.
    //Also anything else you don't want disabled.

    
new Float:cooldownTime get_pcvar_float(cvarCooldown)
    new 
Float:currentTime get_gametime()
    if (
gCooldown[id] > currentTime)
    {
        
//command disabled
        
return PLUGIN_HANDLED
    
}
    
gCooldown[id] = currentTime cooldownTime
    
    
// Command enabled. Continue here.

That will only check when the function is called. gCooldown[id] is set to the time the command is enabled again.

I recommend you use the id of the player to be respawned (Target)

See http://forums.alliedmods.net/showthread.php?t=43049 (near the end of the first post) for more info..

Last edited by Elusive138; 01-06-2011 at 09:55.
Elusive138 is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 01-06-2011 , 08:03   Re: block a command for a certain time
Reply With Quote #4

That is very true, sir. But how is your array only 32 long? You should never use "function" as a function name, at least use PAWN-tags then.
SnoW is offline
Send a message via MSN to SnoW
Elusive138
Senior Member
Join Date: Dec 2010
Old 01-06-2011 , 08:30   Re: block a command for a certain time
Reply With Quote #5

Quote:
Originally Posted by SnoW View Post
That is very true, sir. But how is your array only 32 long? You should never use "function" as a function name, at least use PAWN-tags then.
Sorry, the function was supposed to be an example

And the array size was just a stupid mistake. Thanks for pointing it out

Last edited by Elusive138; 01-06-2011 at 08:34.
Elusive138 is offline
Shiro
Junior Member
Join Date: Nov 2010
Old 01-06-2011 , 08:53   Re: block a command for a certain time
Reply With Quote #6

oh, warning 209 - ReviveFunction
Shiro is offline
Elusive138
Senior Member
Join Date: Dec 2010
Old 01-06-2011 , 09:20   Re: block a command for a certain time
Reply With Quote #7

You know, it would really help if you put those examples of how to use a cooldown into your actual code

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>

#define PLUGIN "Respawn"
#define VERSION "1.0"
#define AUTHOR "fR4gn0tiX!"

new Float:gCooldown[33], cvarCooldown

stock register_saycmd
(saycommand[], function[], flags = -1info[])
{
    static 
sTemp[64]
    
formatex(sTempsizeof sTemp 1"say /%s"saycommand)
    
register_clcmd(sTemp, function, flagsinfo)
    
formatex(sTempsizeof sTemp 1"say .%s"saycommand)
    
register_clcmd(sTemp, function, flagsinfo)
    
formatex(sTempsizeof sTemp 1"say_team /%s"saycommand)
    
register_clcmd(sTemp, function, flagsinfo)
    
formatex(sTempsizeof sTemp 1"say_team .%s"saycommand)
    
register_clcmd(sTemp, function, flagsinfo)
}


public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_cvar("gacocxleba""v1.0 by fR4gn0tiX!"FCVAR_SERVER|FCVAR_SPONLY)
    
    
register_concmd("amx_respawn""cmd_gacocxleba"ADMIN_SLAY"< saxeli | #userid > - Respawn player")    
    
register_saycmd("respawn""cl_gacocxleba"ADMIN_SLAY"Respawn yourself")            

    
cvarCooldown register_cvar("revive_cooldown""5.0"FCVAR_SPONLY)
}

public 
cmd_gacocxleba(idlevelcid)
{
    if (!
cmd_access(idlevelcid2))
       return 
PLUGIN_HANDLED
       
    
new Argument[32
    
    
read_argv(1Argument31
    
    new 
Target cmd_target(idArgumentCMDTARGET_ALLOW_SELF CMDTARGET_OBEY_IMMUNITY
    
    if (
Target
    {    
        if (
is_user_alive(Target)) 
        {
            new 
saxeli[32]            
            
get_user_name(Targetsaxeli31)    
            
            
console_print(id"%s is already alive!"saxeli
            return 
PLUGIN_HANDLED
        
}
    
        new 
Float:cooldownTime get_pcvar_float(cvarCooldown)
        new 
Float:currentTime get_gametime()
        if (
gCooldown[Target] > currentTime)
        {
            
client_print(idprint_console"Please wait another %i seconds before attempting to revive this player."floatround(gCooldown[Target] - currentTime))
            return 
PLUGIN_HANDLED
        
}
        
gCooldown[Target] = currentTime cooldownTime
    
        ExecuteHamB
(Ham_CS_RoundRespawnTarget)
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_HANDLED
}

public 
cl_gacocxleba(id)
{
    if (
is_user_alive(id)) 
    {
        
client_print(idprint_chat"You are already alive!"
        return 
PLUGIN_HANDLED
    
}
    
    new 
Float:cooldownTime get_pcvar_float(cvarCooldown)
    new 
Float:currentTime get_gametime()
    if (
gCooldown[id] > currentTime)
    {
        
client_print(idprint_chat"Please wait another %i seconds before attempting to revive yourself."floatround(gCooldown[id] - currentTime))
        return 
PLUGIN_HANDLED
    
}
    
gCooldown[id] = currentTime cooldownTime
    
    ExecuteHamB
(Ham_CS_RoundRespawnid
    return 
PLUGIN_HANDLED

Untested. Cooldown is on target (i.e. player can only be revived once per cooldown). Change cooldown time with cvar revive_cooldown.

Last edited by Elusive138; 01-06-2011 at 09:23.
Elusive138 is offline
Shiro
Junior Member
Join Date: Nov 2010
Old 01-06-2011 , 09:56   Re: block a command for a certain time
Reply With Quote #8

Elusive138, big thanks! Close
Shiro is offline
Reply



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 02:10.


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