Jump to content

[Help] jail


Fire Monkey

Recommended Posts

Posted

Use getTime or getRealTime to store the time of the jail start and use it to see how much time have he spent in jail.

Resources I made:

Do not PM me for help with leaked scripts! I WILL NOT HELP YOU!

 

Posted
23 minutes ago, Tekken said:

Use getTime or getRealTime to store the time of the jail start and use it to see how much time have he spent in jail.

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.

Posted
setElementData(player, "jailtime", 10*1000)

set jailtime for 10 secondes; 

element data is synced between client and server

Resources I made:

Do not PM me for help with leaked scripts! I WILL NOT HELP YOU!

 

  • Moderators
Posted
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

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
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

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...