Raised This Month: $ Target: $400
 0% 

Exec Command at isactly 12:00h


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Syturi0
Veteran Member
Join Date: Aug 2014
Location: Your mom house -Portugal
Old 01-02-2016 , 00:29   Exec Command at isactly 12:00h
Reply With Quote #1

I wanted a plugin to restart the server at isactly 12:00h and 24:00h.
So i made this:
Spoiler


It works 100%, but i dont like it.
Do you know a better way/method to achieve this?
Whiout the need of NewRound event, or set_tasks...

Thank you.
Syturi0 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-02-2016 , 00:45   Re: Exec Command at isactly 12:00h
Reply With Quote #2

If it works well then I don't see any necessary changes to the core functionality. You should optimize that massive if else if structure. Namely, str_to_num() should only be called once. Also, you should make it such that you only need two prints where you calculate either minutes or seconds left instead of having them hardcoded.
__________________
fysiks is offline
Syturi0
Veteran Member
Join Date: Aug 2014
Location: Your mom house -Portugal
Old 01-02-2016 , 00:55   Re: Exec Command at isactly 12:00h
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
you should make it such that you only need two prints where you calculate either minutes or seconds left instead of having them hardcoded.
I dont know how.
Syturi0 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-02-2016 , 01:44   Re: Exec Command at isactly 12:00h
Reply With Quote #4

Quote:
Originally Posted by Syturi0 View Post
I dont know how.
You need to calculate how many minutes/seconds are left then you pass that as an argument of the print function (changing the number from static to dynamic in the format).
__________________
fysiks is offline
Phant
Veteran Member
Join Date: Sep 2009
Location: New Jersey
Old 01-02-2016 , 02:26   Re: Exec Command at isactly 12:00h
Reply With Quote #5

This restart useless. It's equal simple map change.
Phant is offline
Send a message via ICQ to Phant
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-02-2016 , 02:50   Re: Exec Command at isactly 12:00h
Reply With Quote #6

Quote:
Originally Posted by Phant View Post
This restart useless. It's equal simple map change.
You are correct but might be useful on a 24/7 single-map server. If it's not a 24/7 single-map server then you could replace "restart" with "quit" assuming your host properly handles the server quitting.

Quote:
Originally Posted by Syturi0 View Post
I dont know how.
I would do something like this:

PHP Code:
public CmdRestart()
{
    
// Get the current time
    
static iHouriMinuteiSecondiSecondsLeft
    time
(iHouriMinuteiSecond)
    
    if( 
iHour == 11 || iHour == 23 // Just in case this function gets executed some other time
    
{
        
// Calculate the seconds until the next hour
        
iSecondsLeft 3600 - (iMinute 60 iSecond)
        
        if( 
iSecondsLeft 60 == )  // Every minute on the minute except when we restart
        
{
            
client_print(0print_chat"!gO servidor ira reiniciar automaticamente em !n%d!g minutos."iSecondsLeft 60)
        }
        else if( 
iSecondsLeft == 30 || iSecondsLeft == 15 || iSecondsLeft <= 10 // Select times
        
{
            
client_print(0print_chat"!gO servidor ira reiniciar automaticamente em !n%d!g segundos."iSecondsLeft)
        }
        
        if( 
iSecondsLeft == )  // Restart on the hour
        
{
            
server_cmd("restart")
        }
    }

__________________

Last edited by fysiks; 01-02-2016 at 11:58.
fysiks is offline
Syturi0
Veteran Member
Join Date: Aug 2014
Location: Your mom house -Portugal
Old 01-02-2016 , 05:25   Re: Exec Command at isactly 12:00h
Reply With Quote #7

Quote:
Originally Posted by Phant View Post
This restart useless. It's equal simple map change.
The map doesnt change, its always the same.
Syturi0 is offline
Syturi0
Veteran Member
Join Date: Aug 2014
Location: Your mom house -Portugal
Old 01-02-2016 , 05:26   Re: Exec Command at isactly 12:00h
Reply With Quote #8

Quote:
Originally Posted by fysiks View Post
I would do something like this:

PHP Code:
public CmdRestart()
{
    
// Get the current time
    
static iHouriMinuteiSecondiSecondsLeft
    time
(iHouriMinuteiSecond)
    
    if( 
iHour == 11 || iHour == 23 // Just in case this function gets executed some other time
    
{
        
// Calculate the seconds until the next hour
        
iSecondsLeft 3600 - (iMinute 60 iSecond)
        
        if( 
iSecondsLeft 60 == && iSecondsLeft 0)  // Every minute on the minute except when we restart
        
{
            
client_print(0print_chat"!gO servidor ira reiniciar automaticamente em !n%d!g minutos."iSecondsLeft 60)
        }
        else if( 
iSecondsLeft == 30 || iSecondsLeft == 15 || iSecondsLeft <= 10 // Select times
        
{
            
client_print(0print_chat"!gO servidor ira reiniciar automaticamente em !n%d!g segundos."iSecondsLeft)
        }
        else if( 
iSecondsLeft == )  // Restart on the hour
        
{
            
server_cmd("restart")
        }
    }

Thank you!
Syturi0 is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 01-02-2016 , 07:31   Re: Exec Command at isactly 12:00h
Reply With Quote #9

Quote:
Originally Posted by Syturi0 View Post
The map doesnt change, its always the same.
in this case you can get rid of the new round event and task by just setting mp_timelimit to right amount of time in plugin_init
jimaway is offline
Syturi0
Veteran Member
Join Date: Aug 2014
Location: Your mom house -Portugal
Old 01-02-2016 , 09:03   Re: Exec Command at isactly 12:00h
Reply With Quote #10

fysiks

Everything works well, except this:
Quote:
else if( iSecondsLeft == 0 ) // Restart on the hour
{
server_cmd("restart")
}
Syturi0 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 09:30.


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