JR10 Posted December 23, 2011 Share Posted December 23, 2011 It actually works, if it's the same, it's the one I'm using. Anyway, don't post the script here again please. Link to comment
JasperRieken Posted December 23, 2011 Author Share Posted December 23, 2011 (edited) this is what i've got ServerSide: function addASecond() local serial = getPlayerSerial(player) local oldData = executeSQLSelect( "TimePlayed", "TimePlayed","serial = '" .. serial .. "'") newData = tonumber(oldData[1]["TimePlayed"]) + 1 setElementData(player,"TimePlayed",tonumber(getElementData(player,"TimePlayed"))+1) executeSQLUpdate ( "TimePlayed", "TimePlayed = '"..newData.."'","serial = '" .. serial .. "'") end addEventHandler ( "onClientRender", getRootElement(), addASecond) ClientSide: function Columns() exports.dxscoreboard:scoreboardAddColumn("TimePlayed") setElementData(localPlayer,"TimePlayed",0) end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), Columns) Edited December 23, 2011 by Guest Link to comment
NotAvailable Posted December 23, 2011 Share Posted December 23, 2011 this is what i've gotServerSide: function addASecond() local serial = getPlayerSerial(player) local oldData = executeSQLSelect( "TimePlayed", "TimePlayed","serial = '" .. serial .. "'") newData = tonumber(oldData[1]["TimePlayed"]) + 1 setElementData(player,"TimePlayed",tonumber(getElementData(player,"TimePlayed"))+1) executeSQLUpdate ( "TimePlayed", "TimePlayed = '"..newData.."'","serial = '" .. serial .. "'") end addEventHandler ( "onClientRender", getRootElement(), addASecond) ClientSide: function Columns() exports.dxscoreboard:scoreboardAddColumn("TimePlayed") setElementData(localPlayer,"TimePlayed",0) end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), Columns) use tags. Easier to read. Link to comment
JasperRieken Posted December 23, 2011 Author Share Posted December 23, 2011 this is what i've got ServerSide: function addASecond() local serial = getPlayerSerial(player) local oldData = executeSQLSelect( "TimePlayed", "TimePlayed","serial = '" .. serial .. "'") newData = tonumber(oldData[1]["TimePlayed"]) + 1 setElementData(player,"TimePlayed",tonumber(getElementData(player,"TimePlayed"))+1) executeSQLUpdate ( "TimePlayed", "TimePlayed = '"..newData.."'","serial = '" .. serial .. "'") end addEventHandler ( "onClientRender", getRootElement(), addASecond) ClientSide: function Columns() exports.dxscoreboard:scoreboardAddColumn("TimePlayed") setElementData(localPlayer,"TimePlayed",0) end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), Columns) Link to comment
JasperRieken Posted December 23, 2011 Author Share Posted December 23, 2011 I don't know how Link to comment
JasperRieken Posted December 23, 2011 Author Share Posted December 23, 2011 It just doesn't work Link to comment
Castillo Posted December 23, 2011 Share Posted December 23, 2011 I won't offend anyone but, that's just a total mess, wtf? using onClientRender on a server side script and combined with SQLITE functions? that's just stupid and non-sense. -- server side: exports.dxscoreboard:scoreboardAddColumn("Time played") function updateTimePlayed() setTimer(updateTimePlayed,1000,1) for index, player in ipairs(getElementsByType("player")) do local timePlayed = getElementData(player, "Time played") if (not timePlayed) then setElementData(player, "Time played","0:0:0") end local hours, mins, secs = unpack(split(timePlayed, ":")) local hours = tonumber(hours) local mins = tonumber(mins) local secs = tonumber(secs) if (hours and mins and secs) then local newsec = secs + 1 if ( newsec >= 60 ) then newsec = 0 mins = mins + 1 end if ( mins >= 60 ) then mins = 0 hours = hours + 1 end setElementData ( player, "Time played", tostring(hours) ..":".. tostring(mins) ..":".. tostring(newsec)) end end end setTimer(updateTimePlayed,1000,1) Link to comment
Tete omar Posted May 18, 2012 Share Posted May 18, 2012 Take it and don't worry call ( getResourceFromName ( "scoreboard" ), "scoreboardAddColumn", "Online" ) addEventHandler ( "onResourceStart" , resourceRoot , function ( ) for index , player in ipairs ( getElementsByType ( "player" ) ) do local pAccount = getPlayerAccount ( player ) if not isGuestAccount ( pAccount ) then local minutes = getAccountData ( pAccount , "Online.minutes" ) if minutes then local hours = getAccountData ( pAccount , "Online.hours" ) if # tostring ( minutes ) == 1 then minutes = "0" .. minutes end if # tostring ( hours ) == 1 then hours = "0" .. hours end setElementData ( player , "Online" , hours .. ":" .. minutes .. "" ) local timer = setTimer ( updatePlayerOnline , 60000 , 1 , player ) setElementData ( player , "Online.timer" , timer ) else setAccountData ( pAccount , "Online.minutes" , 0 ) setAccountData ( pAccount , "Online.hours" , 0 ) setElementData ( player , "Online" , " 00:00 " ) local timer = setTimer ( updatePlayerOnline , 60000 , 1 , player ) setElementData ( player , "Online.timer" , timer ) end else setElementData ( player , "Online" , "N/A" ) end end end ) addEventHandler ( "onResourceStop" , resourceRoot , function ( ) for index , player in ipairs ( getElementsByType ( "player" ) ) do local pAccount = getPlayerAccount ( player ) if not isGuestAccount ( pAccount ) then local timer = getElementData ( player , "Online.timer" ) if isTimer ( timer ) then killTimer ( timer ) end end end end ) addEventHandler ( "onPlayerLogin" , root , function ( _ , pAccount ) local minutes = getAccountData ( pAccount , "Online.minutes" ) if minutes then local hours = getAccountData ( pAccount , "Online.hours" ) if # tostring ( minutes ) == 1 then minutes = "0" .. minutes end if # tostring ( hours ) == 1 then hours = "0" .. hours end setElementData ( source , "Online" , hours .. ":" .. minutes .. "" ) local timer = setTimer ( updatePlayerOnline , 60000 , 1 , source ) setElementData ( source , "Online.timer" , timer ) else setAccountData ( pAccount , "Online.minutes" , 0 ) setAccountData ( pAccount , "Online.hours" , 0 ) setElementData ( source , "Online" , " 00:00 " ) local timer = setTimer ( updatePlayerOnline , 60000 , 1 , source ) setElementData ( source , "Online.timer" , timer ) end end ) addEventHandler ( "onPlayerLogout" , root , function ( pAccount ) local timer = getElementData ( source , "Online.timer" ) if isTimer ( timer ) then killTimer ( timer ) end end ) addEventHandler ( "onPlayerJoin" , root , function ( ) setElementData ( source , "Online" , "N/A" ) end ) addEventHandler ( "onPlayerQuit" , root , function ( ) local pAccount = getPlayerAccount ( source ) if not isGuestAccount ( pAccount ) then local timer = getElementData ( source , "Online.timer" ) if isTimer ( timer ) then killTimer ( timer ) end end end ) function updatePlayerOnline ( player ) local pAccount = getPlayerAccount ( player ) local minutes = getAccountData ( pAccount , "Online.minutes" ) local hours = getAccountData ( pAccount , "Online.hours" ) minutes = tostring ( tonumber ( minutes ) + 1 ) if minutes == "60" then hours = tostring ( tonumber ( hours ) + 1 ) minutes = "00" end setAccountData ( pAccount , "Online.minutes" , tonumber ( minutes ) ) setAccountData ( pAccount , "Online.hours" , tonumber ( hours ) ) if # tostring ( minutes ) == 1 then minutes = "0" .. minutes end if # tostring ( hours ) == 1 then hours = "0" .. hours end setElementData ( player , "Online" , hours .. ":" .. minutes .. "" ) local timer = setTimer ( updatePlayerOnline , 60000 , 1 , player ) setElementData ( player , "Online.timer" , timer ) end 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