abu5lf Posted March 4, 2012 Posted March 4, 2012 (edited) function onResourceStart()XX Is it possible to save the time that I played it when I get out and enter? Edited March 7, 2012 by Guest
Castillo Posted March 4, 2012 Posted March 4, 2012 getPlayerAccount -- To get player account. setAccountData -- To save the time on his account. getAccountData -- To obtain the saved time from his account. getElementData -- To get player time. setElementData -- To set player time.
abu5lf Posted March 7, 2012 Author Posted March 7, 2012 (edited) XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx Edited March 8, 2012 by Guest
Castillo Posted March 7, 2012 Posted March 7, 2012 That's just a mess, go back to the wiki and start from the beginning.
abu5lf Posted March 7, 2012 Author Posted March 7, 2012 I know that, but what in the hand trick I will try again
abu5lf Posted March 7, 2012 Author Posted March 7, 2012 What do you think? function SaveTime ( thePlayer ) setElementData (player, "joinTime", getTickCount() ) setElementData (player, "Online Time", "0 :, 0 :, 0 :" ) local timeOnline = (getTickCount() - getElementData ( player, "joinTime" )) local player = getPlayerAccount ( thePlayer ) local Time = getAccountData (player ) if ( account ) then setAccountData ( account ) end end
Castillo Posted March 7, 2012 Posted March 7, 2012 It's still wrong. function saveTime(player, account) if (account and not isGuestAccount(account)) then local joinTime = getElementData(player,"joinTime") setAccountData(account,"joinTime",joinTime) end end addEventHandler("onPlayerLogout",root, function (prev) saveTime(source, prev) end ) addEventHandler("onPlayerQuit",root, function () saveTime(source, getPlayerAccount(source)) end ) That should get the element data "joinTime" from the player when he logs out or leaves the server, and save it on player account. This won't load it, I leave that to you.
abu5lf Posted March 7, 2012 Author Posted March 7, 2012 I did not understand Did you mean when it comes out from the server? I have tried! addEventHandler("onPlayerLogout",root, function logouot(player, account) if (account and not isGuestAccount(account)) then local joinTime = getElementData(player,"joinTime") setAccountData(account,"joinTime",joinTime) )
drk Posted March 7, 2012 Posted March 7, 2012 I did not understand Did you mean when it comes out from the server?I have tried! addEventHandler("onPlayerLogout",root, function saveTime(player, account) if (account and not isGuestAccount(account)) then local joinTime = getElementData(player,"joinTime") setAccountData(account,"joinTime",joinTime) ) addEventHandler ( 'onPlayerLogout', root, function ( _, account ) if ( account and not isGuestAccount ( account ) ) then local joinTime = getElementData ( _, 'joinTime' ) setAccountData ( account, 'joinTime', joinTime ) end end )
JR10 Posted March 8, 2012 Posted March 8, 2012 You need to use end, to end each block. exports["scoreboard"]:addScoreboardColumn("joinTime") function saveTime(player, account) if (account and not isGuestAccount(account)) then local joinTime = getElementData(player,"joinTime") setAccountData(account,"joinTime",joinTime) end end addEventHandler("onPlayerLogout",root, function (prev) saveTime(source, prev) end ) addEventHandler("onPlayerQuit",root, function () saveTime(source, getPlayerAccount(source)) end ) addEventHandler("onPlayerLogin", root, function(_,account) local joinTime = getAccountData(account,"joinTime") if not joinTime then joinTime = 0 end setElementData(source,"joinTime",joinTime) end) This will make a scoreboard column with the online time of everyplayer.
abu5lf Posted March 8, 2012 Author Posted March 8, 2012 function onResourceStart() call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Online Time") for index, player in pairs (getElementsByType("player")) do setElementData (player, "joinTime", getTickCount() ) setElementData (player, "Online Time", "0 :, 0 :, 0 :" ) end end addEventHandler("onResourceStart",resourceRoot,onResourceStart) function joinTime() setElementData (source, "joinTime", getTickCount() ) setElementData (source, "Online Time", "0 :, 0 :, 0 :" ) end addEventHandler ( "onPlayerJoin", root, joinTime ) function all() for index , player in ipairs ( getElementsByType ( "player" ) ) do local s = getElementData(player,"joinTime") or getTickCount() s = (getTickCount() - s) / 1000 local string = string.format("%02d:%02d:%02d", s/3600, s%3600/60, s%60) setElementData(player,"Online Time",string) end end setTimer(all,1000,0) exports["scoreboard"]:addScoreboardColumn("Online Time") function saveTime(player, account) if (account and not isGuestAccount(account)) then local Online Time = getElementData(player,"Online Time") setAccountData(account,"OnlineTime",Online Time) end end addEventHandler("onPlayerLogout",root, function (prev) saveTime(source, prev) end ) addEventHandler("onPlayerQuit",root, function () saveTime(source, getPlayerAccount(source)) end ) addEventHandler("onPlayerLogin", root, function(_,account) local Online Time = getAccountData(account,"Online Time") if not Online Time then Online Time = 0 end setElementData(source,"Online Time",Online Time) end) WARNING: Loading script failed: OnLineTime5\OnLine.lua:35: ')' expected near 'Time'
Castillo Posted March 8, 2012 Posted March 8, 2012 function onResourceStart () call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Online Time") for index, player in pairs ( getElementsByType("player") ) do setElementData (player, "joinTime", getTickCount() ) setElementData (player, "Online Time", "0 :, 0 :, 0 :" ) end end addEventHandler("onResourceStart",resourceRoot,onResourceStart) function joinTime () setElementData ( source, "joinTime", getTickCount() ) setElementData ( source, "Online Time", "0 :, 0 :, 0 :" ) end addEventHandler ( "onPlayerJoin", root, joinTime ) function all() for index , player in ipairs ( getElementsByType ( "player" ) ) do local s = getElementData( player, "joinTime" ) or getTickCount( ) s = ( getTickCount() - s ) / 1000 local string = string.format( "%02d:%02d:%02d", s/3600, s%3600/60, s%60 ) setElementData( player, "Online Time", string ) end end setTimer( all, 1000, 0) function saveTime( player, account ) if ( account and not isGuestAccount(account) ) then local OnlineTime = getElementData( player, "joinTime" ) setAccountData(account, "OnlineTime", OnlineTime) end end addEventHandler ( "onPlayerLogout", root, function ( prev ) saveTime( source, prev ) end ) addEventHandler ( "onPlayerQuit", root, function ( ) saveTime( source, getPlayerAccount( source ) ) end ) addEventHandler ( "onPlayerLogin", root, function ( _, account ) local OnlineTime = getAccountData( account, "Online Time" ) if ( not OnlineTime ) then OnlineTime = 0 end setElementData( source, "joinTime", OnlineTime ) end ) Your problem(s) we're: 1: You can't make a variable with spaces, e.g: Online Time = "hello world", it has to be: OnlineTime = "hello world". 2: You we're saving the time string, not the milliseconds. 3: It still won't work though, when you login back, it'll set it to 9 hours and something.
abu5lf Posted March 8, 2012 Author Posted March 8, 2012 They no longer show the time in the scoreboard I do not know is it saves time or not
abu5lf Posted March 8, 2012 Author Posted March 8, 2012 We have succeeded thanks to you But I got a new idea I want to appear on the screen with the best time, but I can not do so addEventHandler("onClientResourceStart",resourceRoot, function() best = guiCreateLabel(31,409,105,17,"BesT TimeOnLine :",false) guiLabelSetColor(best,255,255,0) guiSetFont(best,"default-bold-small") playername = guiCreateLabel(133,407,135,20,"",false) besttime = guiCreateLabel(140,428,81,20,"",false) end ) function() call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "Online Time") call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "Name") call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "joinTime") end )
Castillo Posted March 8, 2012 Posted March 8, 2012 I'm afraid I don't understand you, what do you mean by "best time"?
abu5lf Posted March 8, 2012 Author Posted March 8, 2012 I mean like the best drift The best time to OnLine in the server
Castillo Posted March 8, 2012 Posted March 8, 2012 Oh, you're talking about the player who has the most online time?
Thelastride Posted March 8, 2012 Posted March 8, 2012 Is this possible? Yes it is .You can use getTickCount function https://wiki.multitheftauto.com/wiki/GetTickCount Read example. Take getTickCount when player joins server and subtract it from current tick count.
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