Jump to content

Registro de Tiempo Conectado Staff


Recommended Posts

Hola ocupo algo de ayuda... pienso hacer un resource pero no se me ocurre el como... quiero crear un registro o algo que me diga cuantas horas a la semana pasa online una cuenta...

Supongamos hoy juego 2 horas... mañana 2... que se sume y en toda la semana marque un total nose 8 horas... por ejemplo y a la proxima semana comienze de nuevo sin borrar el anterior y crear un log

Semana 1 - Narutimmy - 8 Horas

Semana 2 - Narutimmy 3 Horas

Semana 3 - Narutimmy 15 Horas

por ejemplo.

Link to comment
  
local cacheTable = {} 
  
setTimer( 
function () 
    for k,v in ipairs(getElementsByType("player")) do 
        local account = getPlayerAccount ( v ) 
        if ( isGuestAccount ( account ) ) then return end -- Chequeamos si el jugador no esta logueado, si no lo esta terminamos la funcion. 
        local accountName = getAccountName ( account ) 
        if not ( isObjectInACLGroup ( aclGetGroup("Admin"), "user."..accountName ) ) then -- Si no es un administrador, le colocamos un off-set de 0. 
            setAccountData( getPlayerAccount(v), "off-set_on-duty_hours", 0) 
        else 
            if not cacheTable[v] then -- Si no existe un registro del jugador en la cache, la buscamos en su cuenta. 
                local prevDuration = getAccountData( getPlayerAccount(v), "off-set_on-duty_hours") or 0              
                cacheTable[v] = {tick = getTickCount() - prevDuration, account = getPlayerAccount(v)} -- Lo agregamos a la cache. 
            end 
             
            if (getTickCount() - cacheTable[v].tick >= 1000 * 60 * 60) then -- Si cumplio una hora, se la agregamos a su cuenta. 
                local currentHours = getAccountData( account, "On-Duty_hours" ) or 0 
                setAccountData ( getPlayerAccount(v), "On-Duty_hours", currentHours + 1) 
                cacheTable[v].tick = getTickCount() -- Y reiniciamos el tick. 
            end 
        end 
    end 
     
    for k,v in pairs(cacheTable) do 
        if not isElement(k) then -- Si el jugador no existe, guardamos el tiempo que duro logueado esta sesion en su cuenta. 
            local lastDuration = getTickCount() - cacheTable[k].tick 
  
            setAccountData(cacheTable[k].account, "off-set_on-duty_hours", lastDuration) 
  
            cacheTable[k] = nil -- Borramos registros del jugador en la cache. 
        end 
    end 
end , 60000, 0) 
  

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...