Raised This Month: $ Target: $400
 0% 

Server will restart(restart comand)at 5.00am


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
superang
Senior Member
Join Date: Apr 2009
Location: Portugal
Old 09-16-2009 , 12:00   Server will restart(restart comand)at 5.00am
Reply With Quote #1

What i want (plz) is a plugin to use comand restart at 5.00am GMT
I think its easy, + Karma for the author of course
__________________
superang is offline
Send a message via MSN to superang
soolt
BANNED
Join Date: Aug 2009
Location: Lithuania
Old 09-16-2009 , 13:49   Re: Server will restart(restart comand)at 5.00am
Reply With Quote #2

Why u need this ? then map changed server is restarted.
soolt is offline
Send a message via Skype™ to soolt
superang
Senior Member
Join Date: Apr 2009
Location: Portugal
Old 09-16-2009 , 14:50   Re: Server will restart(restart comand)at 5.00am
Reply With Quote #3

because my dedicated server keeps consuming more and more cpu.
and when i do restart my dedicated stays more smoth
__________________
superang is offline
Send a message via MSN to superang
mando127
Veteran Member
Join Date: Dec 2006
Location: virginia
Old 09-16-2009 , 17:59   Re: Server will restart(restart comand)at 5.00am
Reply With Quote #4

i need this to my zombie server is packed with mods that take to much CPU.
__________________
mando127 is offline
Send a message via Skype™ to mando127
tolsty
Senior Member
Join Date: Feb 2008
Location: Latvia
Old 09-16-2009 , 18:39   Re: Server will restart(restart comand)at 5.00am
Reply With Quote #5

try this
PHP Code:
#include <amxmodx>

#define PLUGIN "restart"
#define VERSION "1.0"
#define AUTHOR "tolsty"
#define TIME get_pcvar_num(restart_time)

new restart_time
new restartstatus

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
restartstatus register_cvar("restartstatus""0");
    
restart_time register_cvar("restart_time""5");
    new 
hour[6];
    
get_time("%H",hour,5)
    new 
hrs str_to_num(hour)
    if( 
hrs == TIME && !get_pcvar_num(restartstatus))
    {
        
set_pcvar_num(restartstatus1)
        
server_cmd ("restart")
    } else if( 
hrs TIME )
        
set_pcvar_num(restartstatus0)


__________________
[IMG]http://img2.**************/img2/7173/signfp.jpg[/IMG]

Last edited by tolsty; 09-16-2009 at 18:42.
tolsty is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 09-17-2009 , 13:51   Re: Server will restart(restart comand)at 5.00am
Reply With Quote #6

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

new const g_szVaultKey[ ] = "last_restart";

new 
g_iEntity;
new 
g_iNextTime;

public 
plugin_init( ) {
    
register_plugin"Restart At X Hour""0.0.1""Exolent" );
    
    new const 
szClassname[ ] = "restart_entity";
    
g_iEntity create_entity"info_target" );
    
entity_set_stringg_iEntityEV_SZ_classnameszClassname );
    
register_thinkszClassname"FwdRestart" );
    
    new 
iRestartHour get_pcvar_numregister_cvar"amx_restart_hour""5" ) );
    
    new 
iLastTime;
    if( !
vaultdata_existsg_szVaultKey ) ) {
        new 
szHour], szDay], szMonth], szYear];
        
format_timeszHour2"%H" );
        
format_timeszDay2"%d" );
        
format_timeszMonth2"%m" );
        
format_timeszYear4"%Y" );
        
        new 
iCurHour str_to_numszHour );
        new 
iCurDay str_to_numszDay );
        new 
iCurMonth str_to_numszMonth );
        new 
iCurYear str_to_numszYear );
        
        if( 
iCurHour iRestartHour ) {
            if( --
iCurDay == ) {
                if( --
iCurMonth == ) {
                    
iCurDay 31;
                    
iCurMonth 12;
                    
iCurYear--;
                } else {
                    switch( 
iCurMonth ) {
                        case 
135781012: {
                            
iCurDay 31;
                        }
                        case 
46911: {
                            
iCurDay 30;
                        }
                        case 
2: {
                            
iCurDay IsLeapYeariCurYear ) ? 29 28;
                        }
                    }
                }
            }
        }
        
        
iLastTime TimeToUnixiCurYeariCurMonthiCurDayiRestartHour0);
        
        new 
szTime32 ];
        
num_to_striLastTimeszTime31 );
        
set_vaultdatag_szVaultKeyszTime );
    } else {
        
iLastTime get_vaultdatag_szVaultKey );
        
        new 
iYeariMonthiDayiHouriMinuteiSecond;
        
UnixToTimeiLastTimeiYeariMonthiDayiHouriMinuteiSecond );
        
        
// if plugin was recompiled with a different hour,
        // this makes sure the new hour is used instead of continuing with 24-hour interval from the first hour used
        
if( iHour != iRestartHour ) {
            
iHour iRestartHour;
            
iLastTime TimeToUnixiYeariMonthiDayiHouriMinuteiSecond );
        }
    }
    
    
g_iNextTime iLastTime + ( 60 60 24 ); // 60 * 60 * 24 = 24 hours in seconds
    
new iCurTime get_systime( );
    if( 
g_iNextTime <= iCurTime ) {
        
FwdRestartg_iEntity );
    } else {
        
entity_set_floatg_iEntityEV_FL_nextthinkget_gametime( ) + floatiNextTime iCurTime ) );
    }
}

public 
FwdRestartiEntity ) {
    if( 
iEntity == g_iEntity ) {
        static 
szTime32 ];
        
num_to_strg_iNextTimeszTime31 );
        
set_vaultdatag_szVaultKeyszTime );
        
        
client_print0print_chat"[ RESTART ] Sorry, everyone. The server is scheduled to restart in 5 seconds..." );
        
        
set_task5.0"TaskRestart" );
    }
}

public 
TaskRestart( ) {
    
server_cmd"restart" );
}

// Unix Time Conversion by Bugsy
stock const YearSeconds[2] = 

    
31536000,    //Normal year
    
31622400     //Leap year
};

stock const MonthSeconds[12] = 

    
2678400//January    31 
    
2419200//February    28
    
2678400//March    31
    
2592000//April    30
    
2678400//May        31
    
2592000//June        30
    
2678400//July        31
    
2678400//August    31
    
2592000//September    30
    
2678400//October    31
    
2592000//November    30
    
2678400  //December    31
};

stock const DaySeconds 86400;
stock const HourSeconds 3600;
stock const MinuteSeconds 60;

stock UnixToTimeiTimeStamp , &iYear , &iMonth , &iDay , &iHour , &iMinute , &iSecond )
{
    new 
iNewTimeStamp iTimeStamp;
    
    new 
iTemp;
    
    
iYear 1970;
    
iMonth 1;
    
iDay 1;
    
iHour 0;

    while ( 
iNewTimeStamp )
    {
        
iTemp IsLeapYear(iYear);

        if ( ( 
iNewTimeStamp YearSeconds[iTemp] ) >= )
        {
            
iNewTimeStamp -= YearSeconds[iTemp];
            
iYear++;
        }
        else
        {
            break;
        }
    }

    while ( 
iNewTimeStamp )
    {
        
iTemp SecondsInMonthiYear iMonth );

        if ( ( 
iNewTimeStamp iTemp ) >= 
        {
            
iNewTimeStamp -= iTemp;
            
iMonth++;
        }
        else
        {
            break;
        }
    }

    while ( 
iNewTimeStamp 0)
    {
        if ( ( 
iNewTimeStamp DaySeconds ) >= )
        {
            
iNewTimeStamp -= DaySeconds;
            
iDay++;
        }
        else
        {
            break;
        }
    }
    
    while ( 
iNewTimeStamp )
    {
        if ( ( 
iNewTimeStamp HourSeconds ) >= )
        {
            
iNewTimeStamp -= HourSeconds;
            
iHour++;
        }
        else
        {
            break;
        }
    }
    
    
iMinute = ( iNewTimeStamp 60 );
    
iSecond = ( iNewTimeStamp 60 );
}

stock TimeToUnix( const iYear , const iMonth , const iDay , const iHour , const iMinute , const iSecond )
{
    new 
i;
    new 
iTimeStamp;

    for ( 
1970 iYear i++ )
        
iTimeStamp += YearSecondsIsLeapYear(i) ];

    for ( 
iMonth i++ )
        
iTimeStamp += SecondsInMonthiYear );

    
iTimeStamp += ( ( iDay ) * DaySeconds );
    
iTimeStamp += ( iHour HourSeconds );
    
iTimeStamp += ( iMinute MinuteSeconds );
    
iTimeStamp += iSecond;

    return 
iTimeStamp;
}

stock SecondsInMonth( const iYear , const iMonth 
{
    return ( ( 
IsLeapYeariYear ) && ( iMonth == ) ) ? ( MonthSeconds[iMonth 1] + DaySeconds ) : MonthSeconds[iMonth 1] );
}

stock IsLeapYear( const iYear 
{
    return ( ( (
iYear 4) == 0) && ( ( (iYear 100) != 0) || ( (iYear 400) == ) ) );

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

Last edited by Exolent[jNr]; 09-29-2009 at 18:30.
Exolent[jNr] is offline
puttsmobiles
Senior Member
Join Date: Mar 2009
Location: Chicago
Old 09-25-2009 , 09:50   Re: Server will restart(restart comand)at 5.00am
Reply With Quote #7

which one is better? o.o
puttsmobiles is offline
Send a message via AIM to puttsmobiles Send a message via MSN to puttsmobiles Send a message via Yahoo to puttsmobiles Send a message via Skype™ to puttsmobiles
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 09-25-2009 , 16:29   Re: Server will restart(restart comand)at 5.00am
Reply With Quote #8

I just fixed my code.
I believe mine is better because it restarts exactly at 5 am.
If the server is down at the time or changing maps so the plugin cannot detect 5 am, it will instantly restart the next chance it gets.
Also, if it is not 5 am when the map starts, it will set a timer to restart at 5 am.
If the map changes before the timer goes off, it resets the timer on next map and then sets it again to go off at 5 am.

The other plugin only restarts every map start if it is 5 am (minutes are not accounted for).
If the server misses that hour from 5 am to 5:59 am, then the server won't restart until 5 am the next day.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
superang
Senior Member
Join Date: Apr 2009
Location: Portugal
Old 09-28-2009 , 17:43   Re: Server will restart(restart comand)at 5.00am
Reply With Quote #9

Exolent I just love you
superang is offline
Send a message via MSN to superang
Whazza
Veteran Member
Join Date: Oct 2006
Location: germany/Kassel
Old 09-29-2009 , 15:48   Re: Server will restart(restart comand)at 5.00am
Reply With Quote #10

can arbitrarily set the time?
__________________
"Ein kluger Mensch macht nicht alle Fehler selber, er gibt auch anderen eine Chance."
Whazza 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 21:43.


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