Jump to content

[Help] jail


Fire Monkey

Recommended Posts

  • Moderators
4 hours ago, Fire Monkey said:

no , i want it to be seconds.

that's why I use setTimer

what is the best method to sync server and client jail time.

Get real time uses seconds.

------------
-- server --

local timestamp = getRealTime().timestamp -- seconds

local jailDuration =  (60 * 4) -- seconds
local jailEndTime = timestamp + jailDuration

--

local remainingJailTime = jailEndTime - timestamp
triggerClientEvent(player, "sync-jail-time", player, remainingJailTime ) -- the client only has to know this once

------------
-- client --

local jailEndTime
addEvent("sync-jail-time", true)
addEventHandler("sync-jail-time", localPlayer, 
function (remainingJailTime) 
	jailEndTime = (remainingJailTime * 1000) + getTickCount() -- convert to miliseconds, to make it more accurate (as the machine times are not aligned by seconds)
end, false)


function getRemainingJailTime ()
	if jailEndTime then
		local timeNow = getTickCount()
		return math.ceil(math.max(jailEndTime - timeNow, 0) / 1000) -- seconds
	end
	return 0
end

 

 

  • Like 1
Link to comment
7 hours ago, IIYAMA said:

Get real time uses seconds.

------------
-- server --

local timestamp = getRealTime().timestamp -- seconds

local jailDuration =  (60 * 4) -- seconds
local jailEndTime = timestamp + jailDuration

--

local remainingJailTime = jailEndTime - timestamp
triggerClientEvent(player, "sync-jail-time", player, remainingJailTime ) -- the client only has to know this once

------------
-- client --

local jailEndTime
addEvent("sync-jail-time", true)
addEventHandler("sync-jail-time", localPlayer, 
function (remainingJailTime) 
	jailEndTime = (remainingJailTime * 1000) + getTickCount() -- convert to miliseconds, to make it more accurate (as the machine times are not aligned by seconds)
end, false)


function getRemainingJailTime ()
	if jailEndTime then
		local timeNow = getTickCount()
		return math.ceil(math.max(jailEndTime - timeNow, 0) / 1000) -- seconds
	end
	return 0
end

 

 

Thanks ❤️

  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...