Fire Monkey Posted October 31, 2020 Share Posted October 31, 2020 hi everyone i writing jail system , but i have questions! what is the best method to show the jail time to client with dxDrawText? jail time is saved in mysql database. Link to comment
Tekken Posted October 31, 2020 Share Posted October 31, 2020 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. Link to comment
Fire Monkey Posted October 31, 2020 Author Share Posted October 31, 2020 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. Link to comment
Tekken Posted October 31, 2020 Share Posted October 31, 2020 setElementData(player, "jailtime", 10*1000) set jailtime for 10 secondes; element data is synced between client and server Link to comment
Moderators IIYAMA Posted October 31, 2020 Moderators Share Posted October 31, 2020 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 1 Link to comment
Fire Monkey Posted October 31, 2020 Author Share Posted October 31, 2020 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 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now