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

Server Uptime


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Privet1337
Junior Member
Join Date: Apr 2012
Old 04-05-2012 , 02:14   Server Uptime
Reply With Quote #1

Hello everyone,
i want to know if thats possible to get time format from GetGameTime(). I want to get days, hours, minutes, seconds and miliseconds.
Thanks.
Privet1337 is offline
Doodil
Senior Member
Join Date: Mar 2012
Old 04-05-2012 , 02:57   Re: Server Uptime
Reply With Quote #2

Code:
public OnPluginStart()
{
    RegConsoleCmd("sm_uptime",Command_Time);
}

public Action:Command_Time(client,args)
{
    new Float:theTime=GetGameTime();
    new days = RoundToZero(theTime/86400);
    new hours = RoundToZero((theTime-days)/3600);
    new minutes = RoundToZero((theTime-days-hours)/60);
    new seconds = RoundToZero(theTime-days-hours-minutes);
    new milli = RoundToZero((theTime-days-hours-minutes-seconds)*1000);
    PrintToChat(client,"Uptime: %d days %d hours %d minutes %d seconds and %d milliseconds",days,hours,minutes,seconds,milli);
    return Plugin_Handled;
}
Try this

Edit:return Plugin_Handled;

Last edited by Doodil; 04-05-2012 at 02:58.
Doodil is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 04-05-2012 , 03:19   Re: Server Uptime
Reply With Quote #3

@Doodil

Just one proposal:
PHP Code:
#include <sourcemod>
#pragma semicolon 1


public OnPluginStart()
{
    
RegConsoleCmd("sm_uptime"Command_Time);
}



public 
Action:Command_Time(clientargs)
{
    new 
Float:theTime GetGameTime();
    new 
days          RoundToZero(theTime 86400);
    new 
hours         RoundToZero( (theTime-days) / 3600);
    new 
minutes       RoundToZero( (theTime-days-hours)/60);
    new 
seconds       RoundToZero(theTime days hours minutes);
    new 
milli         RoundToZero( (theTime days hours minutes seconds) * 1000);
    
    
    if(
client && client <= MAXPLAYERS && IsClientInGame(client))
    {
        
PrintToChat(client"\x03Uptime: %d days %d hours %d minutes %d seconds and %d milliseconds"dayshoursminutessecondsmilli);
    }
    else if(
client == 0)
    {
        
PrintToServer("Uptime: %d days %d hours %d minutes %d seconds and %d milliseconds"dayshoursminutessecondsmilli);
    }
    
    return 
Plugin_Handled;

@Privet1337
Note that GetGameTime() does not count until there are/was players in the server.

Yours sincerely
Impact
__________________

Last edited by Impact123; 04-05-2012 at 03:24.
Impact123 is offline
Privet1337
Junior Member
Join Date: Apr 2012
Old 04-05-2012 , 03:47   Re: Server Uptime
Reply With Quote #4

@Impact123 I know that its just server uptime, and not player session time.
But for player session time i just need to save the connect time and do (GetGameTime() - ConnectTime). Right?

Last edited by Privet1337; 04-05-2012 at 03:50.
Privet1337 is offline
Doodil
Senior Member
Join Date: Mar 2012
Old 04-05-2012 , 03:51   Re: Server Uptime
Reply With Quote #5

No he tried to say that GetGameTime() will return 0.0 as long as there hasn't been anyone on the server, and only start adding gametime once someone joins.

But yea, for the session time just save the time on connect and use GetGameTime()-ConnectionTime[client] to calculate
Doodil is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 04-05-2012 , 03:51   Re: Server Uptime
Reply With Quote #6

@Privet1337
That should do what you want.

@Doodil
Yes, thats what i meant to say.

Yours sincerely
Impact
__________________

Last edited by Impact123; 04-05-2012 at 03:52.
Impact123 is offline
Privet1337
Junior Member
Join Date: Apr 2012
Old 04-05-2012 , 03:52   Re: Server Uptime
Reply With Quote #7

Okay. Thank you guys
Anyway I wanted to know only about time formating.

Last edited by Privet1337; 04-05-2012 at 03:53.
Privet1337 is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 04-05-2012 , 07:59   Re: Server Uptime
Reply With Quote #8

http://docs.sourcemod.net/api/index....d=show&id=602&
?
Dr. Greg House is offline
Doodil
Senior Member
Join Date: Mar 2012
Old 04-05-2012 , 08:09   Re: Server Uptime
Reply With Quote #9

FormatTime() only works with a timestamp, GetGameTime() doesn't return a timestamp but the seconds as a float, so sadly you cant use that function in this case
Doodil is offline
Skyy
AlliedModders Donor
Join Date: Jan 2010
Location: Toronto, Canada
Old 04-05-2012 , 09:27   Re: Server Uptime
Reply With Quote #10

if you want to get total server uptime, just have a plugin store GetTime() when it first initializes, just remember to format it as its stored in unix time

Last edited by Skyy; 04-05-2012 at 09:28.
Skyy 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 17:23.


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