Rob0 Posted June 5, 2015 Share Posted June 5, 2015 I've seen this resource elsewhere. In the scoreboard it displays the players total time on server. If this is public can someone name what I'm looking for? Otherwise I need a pointer to write it. I need the lua/mta equivalent of $ctime. A number fixed to some pointless date based on seconds that i can use to calculate elapsed time. Link to comment
WhoAmI Posted June 5, 2015 Share Posted June 5, 2015 It's kinda easy mate, I can write it for you: local columnName = "Online time"; addEventHandler ( "onResourceStart", resourceRoot, function ( ) exports.scoreboard:scoreboardAddColumn ( columnName ); for _, player in pairs ( getElementsByType ( "player" ) ) do setElementData ( player, "global:time", getTickCount ( ) ); end end ); addEventHandler ( "onPlayerLogin", root, function ( _, account ) setElementData ( source, "global:time", getTickCount ( ) ); end ); addEventHandler ( "onPlayerQuit", root, function ( ) local time = getElementData ( source, "global:time" ); local timeSpentOnServer = ( getTickCount ( ) - time ) / 1000; local account = getPlayerAccount ( source ) if ( account and not isGuestAccount ( account ) ) then local data = getAccountData ( account, "global:time" ); if ( data ) then setAccountData ( account, "global:time", data + timeSpentOnServer ); else setAccountData ( account, "global:time", timeSpentOnServer ); end end end ); setTimer ( function ( ) for _, player in pairs ( getElementsByType ( "player" ) ) do local startTime = getElementData ( player, "global:time" ); if ( startTime ) then local onlineTime = ( getTickCount - startTime ) / 1000; setElementData ( player, columnName, string.format ( "%.2d:%.2d:%.2d", onlineTime / (60*60), onlineTime / 60 %6 0, onlineTime % 60 ) ); end end end, 500, 0 ); Should work. Not tested. Link to comment
Rob0 Posted June 6, 2015 Author Share Posted June 6, 2015 could you give this line a second look please it is giving me trouble setElementData ( player, columnName, string.format ( "%.2d:%.2d:%.2d", onlineTime / (60*60), onlineTime / 60 %6 0, onlineTime % 60 ) ); ')' expected near '0' Link to comment
Walid Posted June 6, 2015 Share Posted June 6, 2015 remove the space between 6 and 0. Link to comment
Rob0 Posted June 6, 2015 Author Share Posted June 6, 2015 and no equivalent to mirc's $ctime, a 1 second ticks based in the 1970's, useful for measuring large amounts of time. 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