manve1 Posted February 18, 2013 Share Posted February 18, 2013 clientside: number = 0 setTimer( function() number = number + 1 end, 60000, 0 ) serverside: function saveAll( ) local account = getPlayerAccount( root ) if ( account ) then setAccountData( account, 'nbr', number ) end end addEventHandler( 'onResourceStop', getRootElement(), saveAll ) addEventHandler( 'onPlayerQuit', getRootElement(), saveAll ) function giveAll( ) local account = getPlayerAccount( root ) if (account) then getAccountData( account, 'nbr' ) end end addEventHandler( 'onResourceStart', getRootElement(), giveAll ) addEventHandler( 'onPlayerLogin', getRootElement(), giveAll ) I tryed saving number loads of times, but some how it still doesn't work, please post a corrected script file Link to comment
tosfera Posted February 18, 2013 Share Posted February 18, 2013 Okee first thing I see that isn't right(in my eye's) is: local account = getPlayerAccount( root ) normally thats handeled like; local account = getPlayerAccount(source) but since you want to save the user that quits; server: function saveAll( number ) local account = getPlayerAccount( player ) if ( account ) then triggerClientEvent(player, "count", root) setAccountData( account, "number", number) end end addEventHandler( "onPlayerQuit", getRootElement(), saveAll ) function giveAll() local account = getPlayerAccount( player ) if ( account ) then getAccountData( account, "number") end end addEventHandler( "onPlayerLogin", getRootElement(), giveAll() ) client: number = 0 addEvent("count", true) addEventHandler("count", getLocalPlayer(), setTimer( function() number = number + 1 triggerServerEvent("saveAll",getLocalPlayer(),number) end, 60000, 0 ) ) See if it works (haven't tested it) Link to comment
Sparrow Posted February 19, 2013 Share Posted February 19, 2013 server: function saveAll( number ) for k,v in ipairs(getElementsByType("player")) do local account = getPlayerAccount( v ) if ( account ) then triggerClientEvent(v, "count", root) setAccountData( account, "number", number) end end end addEventHandler( "onPlayerQuit", getRootElement(), saveAll ) function giveAll() for k,v in ipairs(getElementsByType("player")) do local account = getPlayerAccount( v ) if ( account ) then getAccountData( account, "number") end end end addEventHandler( "onPlayerLogin", getRootElement(), giveAll ) Link to comment
manve1 Posted February 19, 2013 Author Share Posted February 19, 2013 still ain't working (( p.s. the script doesn't fully look like that, as it is re-named a bit )) Link to comment
denny199 Posted February 19, 2013 Share Posted February 19, 2013 Client: number = 0 setTimer( function() number = number + 1 setElementData ( getLocalPlayer(), "hours.number", number ) end, 60000, 0 ) addEvent ( "newnmbrvalue", true ) addEventHandler ( "newnmbrvalue", root, function(countupnmbr) number = tonumber(countupnmbr) end) ServeR: addEventHandler ( "onPlayerQuit", getRootElement(), function () local account = getPlayerAccount( source ) if ( account ) then hData = getElementData ( source, "hours.number" ) if ( hData ) then setAccountData( account, 'nbr', tonumber(hData) ) end end end) addEventHandler("onPlayerLogin", root, function() local account = getPlayerAccount( source ) if (account) then countupnmbr = getAccountData( account, 'nbr' ) triggerClientEvent ( source, "newnmbrvalue", source, countupnmbr ) end end ) addEventHandler( "onResourceStop", resourceRoot, function () for k,v in ipairs(getElementsByType("player")) do local account = getPlayerAccount( v ) if ( account ) then hData = getElementData ( source, "hours.number" ) if ( hData ) then setAccountData( account, 'nbr', tonumber(hData) ) end end end end) addEventHandler( "onResourceStart", resourceRoot, function () for k,v in ipairs(getElementsByType("player")) do local account = getPlayerAccount( v ) if (account) then countupnmbr = getAccountData( account, 'nbr' ) triggerClientEvent ( v, "newnmbrvalue", v, countupnmbr ) end end end ) Link to comment
manve1 Posted February 20, 2013 Author Share Posted February 20, 2013 with the script you gave me denny199, i get this error: server trigger clientside event newnmbrvalue, but event is not added clientside Any reasons why? Link to comment
Guest Guest4401 Posted February 20, 2013 Share Posted February 20, 2013 local t = {} addEventHandler('onPlayerLogin',root, function(_,acc) t[acc] = setTimer( function() setAccountData(acc,'nbr',(getAccountData(acc,'nbr') or 0) + 1) end,60000,0 ) end ) function loggedOut(acc) local a = acc if eventName == 'onPlayerQuit' then local acc = getPlayerAccount(source) if not isGuestAccount(acc) then a = acc end end if isTimer(t[a]) then killTimer(t[a]) end t[a] = nil end addEventHandler('onPlayerLogout',root,loggedOut) addEventHandler('onPlayerQuit',root,loggedOut) for i,v in ipairs(getElementsByType'player') do local acc = getPlayerAccount(v) if not isGuestAccount(acc) then t[acc] = setTimer( function() setAccountData(acc,'nbr',(getAccountData(acc,'nbr') or 0) + 1) end,60000,0 ) end 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