K4stic Posted May 10, 2013 Posted May 10, 2013 i Find this script on Community and i need Help to remake it The Problem is then i restart the resource and i'm in Game then it set me 0 hours/min/sec local t = { } function checkValues( source,arg1,arg2) if (arg2 >= 60) then t[ source ][ 'min' ] = tonumber( t[ source ][ 'min' ] or 0 ) + 1 t[ source ][ 'sec' ] = 0 end if (arg1 >= 60) then t[ source ][ 'min' ] = 0 t[ source ][ 'hour' ] = tonumber( t[ source ][ 'hour' ] or 0 ) + 1 end return arg1, arg2 end setTimer( function( ) for _, v in pairs( getElementsByType( "player" ) ) do if (not t[ v ]) then t[ v ] = { ["hour"] = 0, ["min"] = 0, ["sec"] = 0 } end t[ v ][ 'sec' ] = tonumber( t[ v ][ 'sec' ] or 0 ) + 1 local min,sec = checkValues ( v, t[ v ][ 'min' ] or 0, t[ v ][ 'sec' ] or 0 ) local hour = tonumber( t[ v ][ 'hour' ] or 0 ) setElementData( v, "PlayTime", tostring( hour )..' Hours') end end, 1000, 0 ) function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then local sValue = getElementData( source,'PlayTime' ) local hour = tonumber( t[ source ][ 'hour' ] or 0 ) local min = tonumber( t[ source ][ 'min' ] or 0 ) local sec = tonumber( t[ source ][ 'sec' ] or 0 ) setAccountData ( playeraccount, "PlayTime-hour", tostring(hour) ) setAccountData ( playeraccount, "PlayTime-min", tostring(min) ) setAccountData ( playeraccount, "PlayTime-sec", tostring(sec) ) setAccountData ( playeraccount, "PlayTime", tostring(sValue) ) end t[ source ] = nil end addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) function onPlayerLogin (_, playeraccount ) if ( playeraccount ) then local time = getAccountData ( playeraccount, "PlayTime" ) local hou = getAccountData ( playeraccount, "PlayTime-hour") local min = getAccountData ( playeraccount, "PlayTime-min") local sec = getAccountData ( playeraccount, "PlayTime-sec") if ( time ) then setElementData ( source, "PlayTime", time ) t[ source ]["hour"] = tonumber(hou) t[ source ]["min"] = tonumber(min) t[ source ]["sec"] = tonumber(sec) else setElementData ( source, "PlayTime",0 ) setAccountData ( playeraccount, "PlayTime",0 ) end end end addEventHandler ( "onPlayerLogin", root, onPlayerLogin ) addEventHandler ( "onResourceStart", resourceRoot, onPlayerLogin )
PaiN^ Posted May 10, 2013 Posted May 10, 2013 You need to make a different function for the 'onResourceStart' event. Because it have different arguments .
K4stic Posted May 10, 2013 Author Posted May 10, 2013 local t = { } function checkValues( source,arg1,arg2) if (arg2 >= 60) then t[ source ][ 'min' ] = tonumber( t[ source ][ 'min' ] or 0 ) + 1 t[ source ][ 'sec' ] = 0 end if (arg1 >= 60) then t[ source ][ 'min' ] = 0 t[ source ][ 'hour' ] = tonumber( t[ source ][ 'hour' ] or 0 ) + 1 end return arg1, arg2 end setTimer( function( ) for _, v in pairs( getElementsByType( "player" ) ) do if (not t[ v ]) then t[ v ] = { ["hour"] = 0, ["min"] = 0, ["sec"] = 0 } end t[ v ][ 'sec' ] = tonumber( t[ v ][ 'sec' ] or 0 ) + 1 local min,sec = checkValues ( v, t[ v ][ 'min' ] or 0, t[ v ][ 'sec' ] or 0 ) local hour = tonumber( t[ v ][ 'hour' ] or 0 ) setElementData( v, "PlayTime", tostring( hour )..' Hours') end end, 1000, 0 ) function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then local sValue = getElementData( source,'PlayTime' ) local hour = tonumber( t[ source ][ 'hour' ] or 0 ) local min = tonumber( t[ source ][ 'min' ] or 0 ) local sec = tonumber( t[ source ][ 'sec' ] or 0 ) setAccountData ( playeraccount, "PlayTime-hour", tostring(hour) ) setAccountData ( playeraccount, "PlayTime-min", tostring(min) ) setAccountData ( playeraccount, "PlayTime-sec", tostring(sec) ) setAccountData ( playeraccount, "PlayTime", tostring(sValue) ) end t[ source ] = nil end addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) function onPlayerLogin (_, playeraccount ) if ( playeraccount ) then local time = getAccountData ( playeraccount, "PlayTime" ) local hou = getAccountData ( playeraccount, "PlayTime-hour") local min = getAccountData ( playeraccount, "PlayTime-min") local sec = getAccountData ( playeraccount, "PlayTime-sec") if ( time ) then setElementData ( source, "PlayTime", time ) t[ source ]["hour"] = tonumber(hou) t[ source ]["min"] = tonumber(min) t[ source ]["sec"] = tonumber(sec) else setElementData ( source, "PlayTime",0 ) end end end addEventHandler ( "onPlayerLogin", root, onPlayerLogin ) addEventHandler ( "onResourceStart", resourceRoot, onPlayerLogin ) function onrestart ( ) local time = getAccountData ( playeraccount, "PlayTime" ) local hou = getAccountData ( playeraccount, "PlayTime-hour") local min = getAccountData ( playeraccount, "PlayTime-min") local sec = getAccountData ( playeraccount, "PlayTime-sec") setElementData ( source, "PlayTime", time ) t[ source ]["hour"] = tonumber(hou) or 0 t[ source ]["min"] = tonumber(min) or 0 t[ source ]["sec"] = tonumber(sec) or 0 end end addEventHandler ( "onResourceStart", resourceRoot, onrestart ) something like this?
iPrestege Posted May 10, 2013 Posted May 10, 2013 No you have to make a loop and get all players for _,player in ipairs ( getElementsByType ( "player" ) ) do getAccount -- ....etc
PaiN^ Posted May 10, 2013 Posted May 10, 2013 Errors : - playeraccount is not defined . - The source of 'onResourceStart' is the root element in the resource that started, Not a player element You should do a 'for' loop, Get all players, Check there accounts' data, And then set there data if it was found .
K4stic Posted May 10, 2013 Author Posted May 10, 2013 so use this? function onrestart ( playeraccount ) local time = getAccountData ( playeraccount, "PlayTime" ) local hou = getAccountData ( playeraccount, "PlayTime-hour") local min = getAccountData ( playeraccount, "PlayTime-min") local sec = getAccountData ( playeraccount, "PlayTime-sec") for _,player in ipairs ( getElementsByType ( "player" ) ) do setElementData ( source, "PlayTime", time ) t[ player ]["hour"] = tonumber(hou) or 0 t[ player ]["min"] = tonumber(min) or 0 t[ player ]["sec"] = tonumber(sec) or 0 end end addEventHandler ( "onResourceStart", resourceRoot, onrestart )
iPrestege Posted May 10, 2013 Posted May 10, 2013 function onrestart ( ) for _,player in ipairs ( getElementsByType ( "player" ) ) do local playeraccount = getPlayerAccount ( player ) if not playeraccount then return end local time = getAccountData ( playeraccount, "PlayTime" ) local hou = getAccountData ( playeraccount, "PlayTime-hour") local min = getAccountData ( playeraccount, "PlayTime-min") local sec = getAccountData ( playeraccount, "PlayTime-sec") setElementData ( player, "PlayTime", time ) t[ player ]["hour"] = tonumber(hou) or 0 t[ player ]["min"] = tonumber(min) or 0 t[ player ]["sec"] = tonumber(sec) or 0 end end addEventHandler ( "onResourceStart", resourceRoot, onrestart )
PaiN^ Posted May 10, 2013 Posted May 10, 2013 function onrestart ( ) for _,player in ipairs ( getElementsByType ( "player" ) ) do local playeraccount = getPlayerAccount ( player ) if isGuestAccount ( playeraccount ) then return end local time = getAccountData ( playeraccount, "PlayTime" ) local hou = getAccountData ( playeraccount, "PlayTime-hour") local min = getAccountData ( playeraccount, "PlayTime-min") local sec = getAccountData ( playeraccount, "PlayTime-sec") setElementData ( player, "PlayTime", time ) t[ player ]["hour"] = tonumber(hou) or 0 t[ player ]["min"] = tonumber(min) or 0 t[ player ]["sec"] = tonumber(sec) or 0 end end addEventHandler ( "onResourceStart", resourceRoot, onrestart ) @ #X_Mr.Pres[T]ege_X# : The players will allways have an account ( a guest account ) .
iPrestege Posted May 10, 2013 Posted May 10, 2013 function onrestart ( ) for _,player in ipairs ( getElementsByType ( "player" ) ) do local playeraccount = getPlayerAccount ( player ) if isGuestAccount ( playeraccount ) then return end local time = getAccountData ( playeraccount, "PlayTime" ) local hou = getAccountData ( playeraccount, "PlayTime-hour") local min = getAccountData ( playeraccount, "PlayTime-min") local sec = getAccountData ( playeraccount, "PlayTime-sec") setElementData ( player, "PlayTime", time ) t[ player ]["hour"] = tonumber(hou) or 0 t[ player ]["min"] = tonumber(min) or 0 t[ player ]["sec"] = tonumber(sec) or 0 end end addEventHandler ( "onResourceStart", resourceRoot, onrestart ) @ #X_Mr.Pres[T]ege_X# : The players will allways have an account ( a guest account ) . HeHeHe what's the problem ? The script work with a guest account !
iPrestege Posted May 10, 2013 Posted May 10, 2013 There is no problem, But your check is usless . SKIPPER did not ask about if the account guest or not .
K4stic Posted May 10, 2013 Author Posted May 10, 2013 Not work and i talk for who login account no guest or others
K4stic Posted May 10, 2013 Author Posted May 10, 2013 Nothing just then resource restarting is sent me time to 0
iPrestege Posted May 10, 2013 Posted May 10, 2013 function onrestart ( ) for _,player in ipairs ( getElementsByType ( "player" ) ) do local playeraccount = getPlayerAccount ( player ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then local time = getAccountData ( playeraccount, "PlayTime" ) local hou = getAccountData ( playeraccount, "PlayTime-hour") local min = getAccountData ( playeraccount, "PlayTime-min") local sec = getAccountData ( playeraccount, "PlayTime-sec") setElementData ( player, "PlayTime", time ) t[ player ] = {} t[ player ]["hour"] = tonumber(hou) or 0 t[ player ]["min"] = tonumber(min) or 0 t[ player ]["sec"] = tonumber(sec) or 0 end end end addEventHandler ( "onResourceStart", resourceRoot, onrestart )
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