Jump to content

Lag


Recommended Posts

Olá, queria saber qual a melhor forma de eu re-fazer esse código.

--[[
-------------------------------------------------
original script
credits to Yakuza.Real and solidsnake and kenix
http://forum.mtasa.com/viewtopic.php?f=91&t=40132

-------------------------------------------------

booo just fix it 

]]


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
        	local playeraccount = getPlayerAccount ( v )
            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 )

			if not isGuestAccount(playeraccount) then
            	setElementData(v, "PlayTime", tostring( hour )..':'..tostring( min )..':'..tostring( sec ))
           	end
        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
 
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 ( "onPlayerQuit", root, onPlayerQuit )
addEventHandler ( "onPlayerLogin", root, onPlayerLogin )

Preciso fazer um sistema de tempo online de uma forma q eu consiga puxar o tempo de outros scripts mas essa função de time e elementData da muito lag, quando tá com mts players então. Oq posso fazer?

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...