AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Server Uptime (https://forums.alliedmods.net/showthread.php?t=182012)

Privet1337 04-05-2012 02:14

Server Uptime
 
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. :3

Doodil 04-05-2012 02:57

Re: Server Uptime
 
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;

Impact123 04-05-2012 03:19

Re: Server Uptime
 
@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

Privet1337 04-05-2012 03:47

Re: Server Uptime
 
@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?

Doodil 04-05-2012 03:51

Re: Server Uptime
 
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

Impact123 04-05-2012 03:51

Re: Server Uptime
 
@Privet1337
That should do what you want.

@Doodil
Yes, thats what i meant to say.

Yours sincerely
Impact

Privet1337 04-05-2012 03:52

Re: Server Uptime
 
Okay. Thank you guys :)
Anyway I wanted to know only about time formating.

Dr. Greg House 04-05-2012 07:59

Re: Server Uptime
 
http://docs.sourcemod.net/api/index....d=show&id=602&
?

Doodil 04-05-2012 08:09

Re: Server Uptime
 
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

Skyy 04-05-2012 09:27

Re: Server Uptime
 
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


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

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