AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Delay command until round end / start (https://forums.alliedmods.net/showthread.php?t=134416)

DarkGod 08-04-2010 12:11

Delay command until round end / start
 
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. :x

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)
    }



joaquimandrade 08-04-2010 12:19

Re: Delay command until round end / start
 
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


DarkGod 08-04-2010 13:26

Re: Delay command until round end / start
 
Thank you for your help. :)


All times are GMT -4. The time now is 00:18.

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