AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Loop delay help (sv_restart for x seconds) (https://forums.alliedmods.net/showthread.php?t=95883)

hunter_stth 06-28-2009 08:58

Loop delay help (sv_restart for x seconds)
 
How to make loop delay in this code?
I want to run this loop in a 1 second delay.

Code:

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Restart and live!"
#define VERSION "1.0"
#define AUTHOR "HunTeR"

new roundcount = 0
new i = 60
public plugin_init() {
    register_plugin(PLUGIN, VERSION, AUTHOR)   
    register_logevent("RoundEnd", 2, "1=Round_End")
    register_logevent("RoundStart", 2, "1=Round_Start")
}
public RoundEnd() {
    if(roundcount == 0) {
    server_cmd("sv_restart 1")
    roundcount++
    }
}
public RoundStart() {
    if(roundcount == 0) {
                for(i=60;i>=0;i--) {
                        if(i == 1) {
                                set_hudmessage(0, 255, 0, -1.0, -1.0, 0, 6.0, 12.0)
                                show_hudmessage(0, "Live for 1 second!")
                                console_print(0, "Live for 1 second!")
                        }
                        else {
                                set_hudmessage(0, 255, 0, -1.0, -1.0, 0, 6.0, 12.0)
                                show_hudmessage(0, "Live for %d seconds!",i)
                                console_print(0, "Live for %d seconds!",i)
                        }

               
                }
    }
        else if(roundcount == 1) {
        set_hudmessage(0, 255, 0, -1.0, -1.0, 0, 6.0, 12.0)
        show_hudmessage(0, "Game is now Live!!!")
        }
}

Sorry for my bad english!

Bugsy 06-28-2009 09:57

Re: Loop delay help (sv_restart for x seconds)
 
http://www.amxmodx.org/funcwiki.php?go=func&id=253

set_task ( 1.0 , "loopfunc" , _, _, _, "a" , 60 )

In loopfunc function, use a static variable as your loop index. The above line will call loopfunc once a second 60 times.

hunter_stth 06-28-2009 11:21

Re: Loop delay help (sv_restart for x seconds)
 
Quote:

Originally Posted by Bugsy (Post 859275)
http://www.amxmodx.org/funcwiki.php?go=func&id=253

set_task ( 1.0 , "loopfunc" , _, _, _, "a" , 60 )

In loopfunc function, use a static variable as your loop index. The above line will call loopfunc once a second 60 times.

I don't understand you

Bugsy 06-28-2009 13:31

Re: Loop delay help (sv_restart for x seconds)
 
Not sure exactly what your trying to do but this will print out time in seconds up to 60.

PHP Code:

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Restart and live!"
#define VERSION "1.0"
#define AUTHOR "HunTeR"

new g_iRoundCount;

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)    
    
register_logevent("RoundEnd"2"1=Round_End")
    
register_logevent("RoundStart"2"1=Round_Start")
}

public 
RoundEnd() 
{
    if( !
g_iRoundCount 
    {
        
server_cmd("sv_restart 1")
        
g_iRoundCount++
    }
}

public 
RoundStart() 
{
    if ( !
g_iRoundCount  
    {
        
set_task 1.0 "DisplayLive" ___"a" 60 
    }
    else if ( 
g_iRoundCount == 
    {
        
set_hudmessage(02550, -1.0, -1.006.012.0)
        
console_print(0"Game is now Live!!!" )
        
show_hudmessage(0"Game is now Live!!!")
    }
}

public 
DisplayLive()
{
    static 
iSecond;
    static 
szMsg30 ];

    
iSecond++;
    
    
formatexszMsg 29 "Live for %d second%s!" iSecond , ( iSecond == ) ? "" "s" ); 
    
    
set_hudmessage(02550, -1.0, -1.006.012.0)
    
show_hudmessage(0szMsg )

    
console_print(0szMsg )

    if ( 
iSecond == 60 )
        
iSecond 0;



hunter_stth 06-28-2009 16:16

Re: Loop delay help (sv_restart for x seconds)
 
Thanks a lot!

+karma


All times are GMT -4. The time now is 15:28.

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