[Release] Show uptime in server list


#1

I just wrote this quick script because I thought having uptime shown on the fivem server list is very useful.

Installation

There’s no download because I didn’t justify someone downloading a file for the tiny code. Here’s how to very easily implement it to your server, simply read the installation manual and you should be good to go!

  1. Add the following to your server configuration file:
    add_ace resource.uptime command.sets allow
    In this case the resource has been named uptime (if you fail to do this you’ll get an error that the sets command was denied)
  2. Add the below to a server sided FXserver file (must have the same resource name as above)
Citizen.CreateThread(function()
	local uptimeMinute, uptimeHour = 0, 0

	while true do
		Citizen.Wait(1000 * 60) -- every minute
		uptimeMinute = uptimeMinute + 1
	
		if uptimeMinute == 60 then
			uptimeMinute = 0
			uptimeHour = uptimeHour + 1
		end

		ExecuteCommand(string.format("sets Uptime \"%02dh %02dm\"", uptimeHour, uptimeMinute))
	end
end)

#2

Create a download its better.


#3

Didn’t you read the entire thread? Motivate why it’s ‘better’ to have a download


#4

That way people don’t have to waste there time copying and creating files and shit.


#5

A seperate resource for 30 lines of code?


#6

@Photobox_2009

I am pretty sure you meant: I am a lazy fuck and would like to just download and extract it. or I am too stupid to to create the files myself.


#10

Awesome Release :))
Thanks <3


#11

Nice stuff man… Keep up the good work!


#12

Hey Ice nice to see you active


#14

Great release man! Keep it up :slight_smile:


#15

It keep saying *sets command was denied in console on my server. I named it uptime and did
add_ace resource.uptime command.sets allow …


#16

why your codes long and complicated
why are you use this function:

function FormatUptime(hour, minute)
	if hour <= 9 then
		hour = ('0%s'):format(hour)
	end

	if minute <= 9 then
		minute = ('0%s'):format(minute)
	end

	return ('%sh %sm'):format(hour, minute)
end

use this:

Citizen.CreateThread(function()
	local uptimeMinute = 0
	local uptimeHour = 0

	while true do
		Citizen.Wait(1000 * 60) -- each minute
		uptimeMinute = uptimeMinute + 1
	
		if uptimeMinute == 60 then
			uptimeMinute = 0
			uptimeHour = uptimeHour + 1
		end

		ExecuteCommand(string.format("sets Uptime \"%02dh %02dm\"", uptimeHour, uptimeMinute))
	end
end)

if you want this exact then use this:

Citizen.CreateThread(function()
	local starttick = GetGameTimer()
	while true do
		Citizen.Wait(15000) -- check all 15 seconds
		local tick = GetGameTimer()
		-- if you want days then use this:
		-- local uptimeDay = math.floor(tick-starttick)/86400000)
		-- if you use day then change the hour to this:
		-- local uptimeHour = math.floor(tick-starttick)/3600000) % 24
		local uptimeHour = math.floor((tick-starttick)/3600000)
		local uptimeMinute = math.floor((tick-starttick)/60000) % 60
		--if you want seconds then use this:
		--local uptimeSecond = math.floor((tick-starttick)/1000) % 60
		ExecuteCommand(string.format("sets Uptime \"%02dh %02dm\"", uptimeHour, uptimeMinute))
	end
end)

#17

Because I’m not similar with the formatting, sorry for making you puke. I’ll improve the code thanks to you.


#18

Do i add this file add_ace resource.uptime command.sets allow to my server.cfg and save it like just put it on top or anywhere sorry im new to this stuff


#19

nice thanks for release


#20

I did not understand this


#21

Is there anyone to help me understand this


#22

I did not know how to install it