Raised This Month: $32 Target: $400
 8% 

Delay command until round end / start


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DarkGod
SourceMod DarkCrab
Join Date: Jul 2007
Location: Sweden
Old 08-04-2010 , 12:11   Delay command until round end / start
Reply With Quote #1

Okay, so I'm working on a plugin where I want the commands to be delayed for a set time or until round ends / starts.

I tried a quite dumb approach for the round end / start right now and it doesn't appear to work. If it did work, it'd also just be one command which worked... which isn't what I want either. I figured you'd need 3 dimensional arrays for it so I tried that out but just ended up getting lost. Here's my non-working code.

PHP Code:
#include <amxmodx>

#define VERSION    "0.6.7"

#define ROUNDEND_TASKID 2000
#define ROUNDSTART_TASKID 1000

public plugin_init()
{
    
register_plugin("Vix (Command Delayer)"VERSION"dg`")
    
register_concmd("amx_delay""cmdDelay"0"<time in seconds> <^"command^">")
    
    
register_logevent"EvRoundStart"2"1=Round_Start")
    
register_logevent"EvRoundEnd"2"1=Round_End")
}

public 
cmdDelay(index)
{
    new 
time[5], command[60], len charsmax(command)
    
    
read_argv(1timelen)
    
read_argv(2commandlen)
    
    if(!
time[0])
    {
        
console_print(index"Usage: amx_delay <seconds/-1 round end/-2 round start> <^"command^">")
        return 
PLUGIN_HANDLED
    
}
    
    new 
delay str_to_num(time)
    
    switch(
delay)
    {
        case -
1
        {
            
console_print(index"[Vix] You will perform the command %s on round end."command)
            
set_task(1000.0"ExecCmd"ROUNDEND_TASKID indexcommandlen)
        }
        case -
2
        {
            
console_print(index"[Vix] You will perform the command %s on round start."command)
            
set_task(1000.0"ExecCmd"ROUNDSTART_TASKID indexcommandlen)
        }
        default:
        {
            
set_task(float(delay), "ExecCmd"indexcommandlen)
            
console_print(index"[Vix] You set a task of %is to perform this command: %s"delaycommand)
        }
    }
    
    return 
PLUGIN_HANDLED
}

public 
ExecCmd(command[], index)
{
    if(!
is_user_connected(index)    )
        return
    
    
trim(command)
    
remove_quotes(command)
    while(
replace(command60"\'""^"")) { } //"
    
    
client_cmd(indexcommand)
}

public 
EvRoundEnd()
{
    new 
iplayers[32], numindex
    get_players
(playersnum)
    for(
0numi++)
    {
        
index players[i]
        
change_task(ROUNDEND_TASKID index0.1)
    }
}

public 
EvRoundStart()
{    
    new 
iplayers[32], numindex
    get_players
(playersnum)
    
    for(
0numi++)
    {
        
index players[i]
        
change_task(ROUNDSTART_TASKID index0.1)
    }

__________________
DarkGod is offline
Send a message via AIM to DarkGod Send a message via MSN to DarkGod
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 08-04-2010 , 12:19   Re: Delay command until round end / start
Reply With Quote #2

PHP Code:
new Array:CommandsRoundStartQueue
new Array:CommandsRoundEndQueue
const CommandMaxLen 60

plugin_init
()
{
    
CommandsRoundEndQueue ArrayCreate(CommandMaxLen)
}

...

switch(
delay)
    {
        case -
1
        { 
            
ArrayPushString(CommandsRoundEndQueue,command)
        }
...


At round end:
...

while(
ArrayGetSize(CommandsRoundEndQueue))
{
    static 
command[CommandMaxLen]
    
ArrayGetString(CommandsRoundEndQueue,0,command,charsmax(command))
    
ArrayDeleteItem(CommandsRoundEndQueue,0)
    
    
// use "command"    

Edit:

At round end do instead:

PHP Code:
new size ArrayGetSize(CommandsRoundEndQueue)

for(new 
i=0size ;i++)
{
    static 
command[CommandMaxLen]
    
ArrayGetString(CommandsRoundEndQueue,i,command,charsmax(command))
}

ArrayClear(CommandsRoundEndQueue
__________________

Last edited by joaquimandrade; 08-04-2010 at 12:23.
joaquimandrade is offline
DarkGod
SourceMod DarkCrab
Join Date: Jul 2007
Location: Sweden
Old 08-04-2010 , 13:26   Re: Delay command until round end / start
Reply With Quote #3

Thank you for your help.
__________________
DarkGod is offline
Send a message via AIM to DarkGod Send a message via MSN to DarkGod
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 07:11.


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