BorderLine Posted February 9, 2012 Posted February 9, 2012 Hi everyone, i have a question and other is a help first is how i can make to when pass 60 minuts, back to 0. and the help.. my script dont save the time online Im try much thinks, and dont work debug dont show erros exports.BHZ4_scoreboard:addScoreboardColumn('Tiempo Jugado') setTimer( function( ) for _, v in pairs( getElementsByType( "player" ) ) do local totalTime = getElementData( v,"totalTime" ) or 0 setElementData( v,"totalTime",totalTime+1 ) setElementData( v,"Tiempo Jugado",math.floor( tonumber( totalTime )/3600 ).." H : "..math.floor( tonumber( totalTime )/60 ).." M" ) end end, 1000, 0 ) function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then local time = getAccountData ( playeraccount , totalTime ) setAccountData ( playeraccount, "totalTime", time ) end end function onPlayerLogin (_, playeraccount ) if ( playeraccount ) then local time = getAccountData ( playeraccount, "totalTime" ) if ( time ) then setElementData ( playeraccount, time ) end end end addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin) Actual Nick: [XGN]BorderLine Actual Clan: XLatino Actual Status: Staff, Mod Level 1 (BOSS)Yakuza - [vS]Yakuza - [sXE]Yakuza - [uG]Yakuza - [FTLS]Racing - [XGN]Borderline
Castillo Posted February 9, 2012 Posted February 9, 2012 exports.BHZ4_scoreboard:addScoreboardColumn('Tiempo Jugado') setTimer( function( ) for _, v in pairs( getElementsByType( "player" ) ) do local totalTime = getElementData( v,"totalTime" ) or 0 setElementData( v,"totalTime",totalTime+1 ) setElementData( v,"Tiempo Jugado",math.floor( tonumber( totalTime )/3600 ).." H : "..math.floor( tonumber( totalTime )/60 ).." M" ) end end, 1000, 0 ) function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then local time = getElementData ( source, "totalTime" ) setAccountData ( playeraccount, "totalTime", time ) end end function onPlayerLogin (_, playeraccount ) if ( playeraccount ) then local time = getAccountData ( playeraccount, "totalTime" ) if ( time ) then setElementData ( source, "totalTime", time ) end end end addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin) San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
BorderLine Posted February 9, 2012 Author Posted February 9, 2012 Perfect. Working. Thanks a loot And how i can make to in minute 59 pass to 0.. because here when players are online 1:20 minutes the score show 1:80 Actual Nick: [XGN]BorderLine Actual Clan: XLatino Actual Status: Staff, Mod Level 1 (BOSS)Yakuza - [vS]Yakuza - [sXE]Yakuza - [uG]Yakuza - [FTLS]Racing - [XGN]Borderline
drk Posted February 9, 2012 Posted February 9, 2012 exports.BHZ4_scoreboard:addScoreboardColumn('Tiempo Jugado') setTimer( function( ) for _, v in pairs( getElementsByType( "player" ) ) do local totalTime = getElementData( v,"totalTime" ) or 0 setElementData( v,"totalTime",totalTime+1 ) setElementData( v,"Tiempo Jugado",math.floor( tonumber( totalTime )/3600 ).." H : "..math.floor( tonumber( totalTime )/59 ).." M" ) end end, 1000, 0 ) function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then local time = getElementData ( source, "totalTime" ) setAccountData ( playeraccount, "totalTime", time ) end end function onPlayerLogin (_, playeraccount ) if ( playeraccount ) then local time = getAccountData ( playeraccount, "totalTime" ) if ( time ) then setElementData ( source, "totalTime", time ) end end end addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin) ? EPT Team Server Development: 0% Learning C++ | C++ is amazing
Kenix Posted February 9, 2012 Posted February 9, 2012 exports.BHZ4_scoreboard:addScoreboardColumn('Tiempo Jugado') local t = { } function table.empty( t ) if type( t ) ~= "table" then return false end return not next( t ) end function checkValues( source,arg1,arg2 ) if arg1 > 60 then t[ source ][ 'min' ] = tonumber( t[ source ][ 'min' ] or 0 ) + 1 t[ source ][ 'sec' ] = 0 elseif arg2 > 3600 then t[ source ][ 'sec' ] = 0 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 ] = v end if table.empty( t[ v ] ) then t[ v ] = { } end t[ v ][ 'sec' ] = tonumber( t[ v ][ 'sec' ] or 0 ) + 1 local min,hour = checkValues ( v, t[ v ][ 'min' ] or 0, t[ v ][ 'hour' ] or 0 ) setElementData( v, "Tiempo Jugado", tostring( hour )..':'..tostring( min ) ) end end, 1000, 0 ) function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then local sValue = getElementData( source,'Tiempo Jugado' ) setAccountData ( playeraccount, "Tiempo Jugado", sValue ) end t[ source ] = nil end function onPlayerLogin (_, playeraccount ) if ( playeraccount ) then local time = getAccountData ( playeraccount, "Tiempo Jugado" ) if ( time ) then setElementData ( source, "Tiempo Jugado", time ) end end end addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) addEventHandler ( "onPlayerLogin", root, onPlayerLogin ) Updated. http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
BorderLine Posted February 9, 2012 Author Posted February 9, 2012 debugscript 3 34:attempt to index field '?' ( a userdata value) edit: i dont know what i can do Actual Nick: [XGN]BorderLine Actual Clan: XLatino Actual Status: Staff, Mod Level 1 (BOSS)Yakuza - [vS]Yakuza - [sXE]Yakuza - [uG]Yakuza - [FTLS]Racing - [XGN]Borderline
Castillo Posted February 10, 2012 Posted February 10, 2012 Try this: local t = { } function checkValues( source,arg1,arg2 ) if (arg1 > 60) then t[ source ][ 'min' ] = tonumber( t[ source ][ 'min' ] or 0 ) + 1 t[ source ][ 'sec' ] = 0 elseif (arg2 > 3600) then t[ source ][ 'sec' ] = 0 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,hour = checkValues ( v, t[ v ][ 'min' ] or 0, t[ v ][ 'hour' ] or 0 ) setElementData( v, "Tiempo Jugado", tostring( hour )..':'..tostring( min ) ) end end, 1000, 0 ) function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then local sValue = getElementData( source,'Tiempo Jugado' ) setAccountData ( playeraccount, "Tiempo Jugado", sValue ) end t[ source ] = nil end function onPlayerLogin (_, playeraccount ) if ( playeraccount ) then local time = getAccountData ( playeraccount, "Tiempo Jugado" ) if ( time ) then setElementData ( source, "Tiempo Jugado", time ) end end end addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) addEventHandler ( "onPlayerLogin", root, onPlayerLogin ) San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
BorderLine Posted February 10, 2012 Author Posted February 10, 2012 all good, dont show errors, but the time in the score board dont change the minutes. i was waiting 5 minutes and dont change. still in 0:0 Actual Nick: [XGN]BorderLine Actual Clan: XLatino Actual Status: Staff, Mod Level 1 (BOSS)Yakuza - [vS]Yakuza - [sXE]Yakuza - [uG]Yakuza - [FTLS]Racing - [XGN]Borderline
Kenix Posted February 10, 2012 Posted February 10, 2012 local t = { } function checkValues( source,arg1,arg2 ) if arg1 > 60 then t[ source ][ 'min' ] = tonumber( t[ source ][ 'min' ] or 0 ) + 1 t[ source ][ 'sec' ] = 0 elseif arg2 > 3600 then t[ source ][ 'sec' ] = 0 t[ source ][ 'min' ] = 0 t[ source ][ 'hour' ] = tonumber( t[ source ][ 'hour' ] or 0 ) + 1 end 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 checkValues ( v, t[ v ][ 'sec' ] or 0, t[ v ][ 'min' ] or 0 ) setElementData( v, "Tiempo Jugado", tostring( t[ v ][ 'hour' ] or 0 )..':'..tostring( t[ v ][ 'min' ] or 0 ) ) end end, 1000, 0 ) function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then local sValue = getElementData( source,'Tiempo Jugado' ) setAccountData ( playeraccount, "Tiempo Jugado", sValue ) end t[ source ] = nil end function onPlayerLogin (_, playeraccount ) if ( playeraccount ) then local time = getAccountData ( playeraccount, "Tiempo Jugado" ) if ( time ) then setElementData ( source, "Tiempo Jugado", time ) end end end addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) addEventHandler ( "onPlayerLogin", root, onPlayerLogin ) Again updated. http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
BorderLine Posted February 10, 2012 Author Posted February 10, 2012 now count the minutes, but when i disconnect then join and i login don save the times i added a serttimer to function onJoinQuit for save every minute. but dont work that Some variable is wrong? Actual Nick: [XGN]BorderLine Actual Clan: XLatino Actual Status: Staff, Mod Level 1 (BOSS)Yakuza - [vS]Yakuza - [sXE]Yakuza - [uG]Yakuza - [FTLS]Racing - [XGN]Borderline
Kenix Posted February 10, 2012 Posted February 10, 2012 Try local t = { } function checkValues( source,arg1,arg2 ) if arg1 > 60 then t[ source ][ 'min' ] = tonumber( t[ source ][ 'min' ] or 0 ) + 1 t[ source ][ 'sec' ] = 0 elseif arg2 > 3600 then t[ source ][ 'sec' ] = 0 t[ source ][ 'min' ] = 0 t[ source ][ 'hour' ] = tonumber( t[ source ][ 'hour' ] or 0 ) + 1 end 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 checkValues ( v, t[ v ][ 'sec' ] or 0, t[ v ][ 'min' ] or 0 ) setElementData( v, "Tiempo Jugado", tostring( t[ v ][ 'hour' ] or 0 )..':'..tostring( t[ v ][ 'min' ] or 0 ) ) end end, 1000, 0 ) function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then local sValue = getElementData( source,'Tiempo Jugado' ) setAccountData ( playeraccount, "Tiempo Jugado", tostring( sValue ) ) end t[ source ] = nil end function onPlayerLogin (_, playeraccount ) if ( playeraccount ) then local time = getAccountData ( playeraccount, "Tiempo Jugado" ) if ( time ) then setElementData ( source, "Tiempo Jugado", tostring( time ) ) end end end addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) addEventHandler ( "onPlayerLogin", root, onPlayerLogin ) I tested it later. http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
BorderLine Posted February 10, 2012 Author Posted February 10, 2012 Not work, i think the problem is in 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 checkValues ( v, t[ v ][ 'sec' ] or 0, t[ v ][ 'min' ] or 0 ) setElementData( v, "Tiempo Jugado", tostring( t[ v ][ 'hour' ] or 0 )..':'..tostring( t[ v ][ 'min' ] or 0 ) ) end end, 1000, 0 ) For example, im stay 5 minutes in the server, then i quit and i login,and when i login the time in score show 0:5 minutes. but one second after come back the time to 0:0 Actual Nick: [XGN]BorderLine Actual Clan: XLatino Actual Status: Staff, Mod Level 1 (BOSS)Yakuza - [vS]Yakuza - [sXE]Yakuza - [uG]Yakuza - [FTLS]Racing - [XGN]Borderline
drk Posted February 10, 2012 Posted February 10, 2012 I think its because it start the count from 0, then it sets to 0 again and start count again. EPT Team Server Development: 0% Learning C++ | C++ is amazing
Kenix Posted February 10, 2012 Posted February 10, 2012 exports.scoreboard:addScoreboardColumn( 'Tiempo Jugado' ) local t = { } local uTimers = { } function checkValues( source,arg1,arg2 ) if arg1 > 60 then t[ source ][ 'min' ] = tonumber( t[ source ][ 'min' ] or 0 ) + 1 t[ source ][ 'sec' ] = 0 elseif arg2 > 3600 then t[ source ][ 'sec' ] = 0 t[ source ][ 'min' ] = 0 t[ source ][ 'hour' ] = tonumber( t[ source ][ 'hour' ] or 0 ) + 1 end end function onPlayerLogOut ( _,account ) if ( account ) and not isGuestAccount ( account ) then local sValue = getElementData( source,'Tiempo Jugado' ) setAccountData ( account, "Tiempo Jugado", tostring( sValue ) ) end if isTimer( uTimers[ source ] ) then killTimer( uTimers[ source ] ) end uTimers[ source ] = nil t[ source ] = nil end function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then local sValue = getElementData( source,'Tiempo Jugado' ) setAccountData ( playeraccount, "Tiempo Jugado", tostring( sValue ) ) end if isTimer( uTimers[ source ] ) then killTimer( uTimers[ source ] ) end uTimers[ source ] = nil t[ source ] = nil end function subFind( str,mod ) if mod == 'hour' then return str:sub( 1,str:find( ':' ) -1 ) else return str:sub( str:find( ':' ) + 1,str:len( ) ) end end function onPlayerLogin (_, account ) if account then uTimers[ source ] = setTimer( function( player,acc ) local time = getAccountData ( acc, "Tiempo Jugado" ) if time then if not t[ player ] then t[ player ] = { ["hour"] = tonumber( subFind( time,'hour' ) ), ["min"] = tonumber( subFind( time ) ), ["sec"] = 0 } end else if not t[ player ] then t[ player ] = { ["hour"] = 0, ["min"] = 0, ["sec"] = 0 } end end t[ player ][ 'sec' ] = tonumber( t[ player ][ 'sec' ] or 0 ) + 1 checkValues ( player, t[ player ][ 'sec' ] or 0, t[ player ][ 'min' ] or 0 ) setElementData ( player, "Tiempo Jugado", tostring( t[ player ][ 'hour' ] or 0 )..':'..tostring( t[ player ][ 'min' ] or 0 ) ) end, 1000, 0 ,source,account ) end end addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) addEventHandler ( "onPlayerLogin", root, onPlayerLogin ) addEventHandler( 'onPlayerLogout',root, onPlayerLogOut ) Again updated. http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
BorderLine Posted February 10, 2012 Author Posted February 10, 2012 Perfecto. Working 100% thanks for ur time kenix and solid maybe some day i could help you Edit: i dont know what happen, was working good, now show this message debugscript 44: attempt to perform artihmetic on a nill value edit: i found the error no problem thanks Actual Nick: [XGN]BorderLine Actual Clan: XLatino Actual Status: Staff, Mod Level 1 (BOSS)Yakuza - [vS]Yakuza - [sXE]Yakuza - [uG]Yakuza - [FTLS]Racing - [XGN]Borderline
Kenix Posted February 10, 2012 Posted February 10, 2012 No problem http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
Booo Posted May 12, 2012 Posted May 12, 2012 hi dude can i use this code ? try this dude !!. exports.scoreboard:addScoreboardColumn('PlayTime') 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 )..':'..tostring( min )..':'..tostring( sec ) ) end end, 1000, 0 ) function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then local sValue = getElementData( source,'PlayTime' ) setAccountData ( playeraccount, "PlayTime", tostring(sValue) ) end t[ source ] = nil end function onPlayerLogin (_, playeraccount ) if ( playeraccount ) then local time = getAccountData ( playeraccount, "PlayTime" ) if ( time ) then setElementData ( source, "PlayTime", time ) else setElementData ( source, "PlayTime",0 ) setAccountData ( playeraccount, "PlayTime",0 ) end end end addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) addEventHandler ( "onPlayerLogin", root, onPlayerLogin ) تذكر عند تصفحك للأنترنت قوله تعالى: (( وهو معكم أين ما كنتم والله بما تعملون بصير )) ا
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