[Snippet] Host Time (aka hoston)

Started by MacTavish, Oct 24, 2015, 07:28 PM

Previous topic - Next topic

MacTavish

First i will Thank to @Rocky and @Thijn for an useful function GetTimeFormat

I know it isn't hard to made for us but it would be really hard to made for newbies so i made it :)

Main.nut
onScriptLoad()
{
Start <-0;
Start = time();
}

Command:
if (cmd=="hoston")
{
local time_taken = time()-Start;
Message("Server Host Time "+GetTimeFormat(time_taken));
}

function GetTimeFormat( secs )
{
                local nDays, nHours, nMinutes, nMonths, nYears, nTime = "";
nYears = secs/31536000;
secs = secs%31536000;
nMonths = secs/2678400;
secs = secs%2678400;
nDays = secs/86400;
secs = secs%86400;
nHours = secs/3600;
secs = secs%3600;
nMinutes = secs/60;
secs = secs%60;
if( nYears != 0 ) nTime = nTime + nYears + " Year" + (nYears > 1 ? "s":"");
if( nMonths != 0 ) nTime = nTime + (nTime != "" ? ", ":"") + nMonths + " Month" + (nMonths > 1 ? "s":"");
if( nDays != 0 ) nTime = nTime  + (nTime != "" ? ", ":"") + nDays + " Day" + (nDays > 1 ? "s":"");
if( nHours != 0 ) nTime = nTime + (nTime != "" ? ", ":"") + nHours + " Hour" + (nHours > 1 ? "s":"");
if( nMinutes != 0 ) nTime = nTime +  (nTime != "" ? ", ":"") + nMinutes + " Minute" + (nMinutes > 1 ? "s":"");
if( secs != 0 ) nTime = nTime + (nTime != "" ? ", ":"") + secs + " Second" + (secs > 1 ? "s":"");
return nTime;
}

Update: Changed time() with GetTickCount()

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

Cool


Thijn

You should use the time() function for this. GetTickCount will stop working after your server has been online for 49.7 days, because of the millisecond accuracy. You're calculating with seconds anyways, so why do the extra calculation.

Xmair


Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

KAKAN

Nice work.
But SLC already did it in an easy way :)
oh no

MacTavish

@Thijn i changed to time but i cant test it atm so can you tell me that does it works

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

Thijn


SAzEe21


Mr.Dip 2020

does this mean we can host our server in the master list?

Inferno

Quote from: Mr.Dip 2020 on Dec 16, 2020, 04:41 PMdoes this mean we can host our server in the master list?

You just bumped a 5 years old post to ask that?
._.

Host Time is the uptime to check the time since when the server is up / hosted.

To show your server in masterlist, you need announce plugin and port forwarded internet ( if local hosted ) or VPS
Viva la VU
VFS Developer
VCCNR Administrator

umar4911

Quote from: Inferno on Dec 16, 2020, 06:35 PM
Quote from: Mr.Dip 2020 on Dec 16, 2020, 04:41 PMdoes this mean we can host our server in the master list?

You just bumped a 5 years old post to ask that?
._.

Host Time is the uptime to check the time since when the server is up / hosted.

To show your server in masterlist, you need announce plugin and port forwarded internet ( if local hosted ) or VPS
O B V I O U S L Y
I am gamer, programmer and hacker. Try to find me!
xD

MacTavish

Quote from: Inferno on Dec 16, 2020, 06:35 PM
Quote from: Mr.Dip 2020 on Dec 16, 2020, 04:41 PMdoes this mean we can host our server in the master list?

Host Time is the uptime to check the time since when the server is up / hosted.

To show your server in masterlist, you need announce plugin and port forwarded internet ( if local hosted ) or VPS

TOPIC LOCKED

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P