Jump to content

Is this possible?


abu5lf

Recommended Posts

What do you think?

function SaveTime ( thePlayer ) 
    setElementData (player, "joinTime", getTickCount() )  
    setElementData (player, "Online Time", "0 :, 0 :, 0 :" )  
    local timeOnline = (getTickCount() - getElementData ( player, "joinTime" ))     
    local player = getPlayerAccount ( thePlayer ) 
     local Time = getAccountData (player ) 
    if ( account ) then 
        setAccountData ( account ) 
    end 
end 
  

Link to comment

It's still wrong.

function saveTime(player, account) 
    if (account and not isGuestAccount(account)) then 
        local joinTime = getElementData(player,"joinTime") 
        setAccountData(account,"joinTime",joinTime) 
    end 
end 
  
addEventHandler("onPlayerLogout",root, 
    function (prev) 
        saveTime(source, prev) 
    end 
) 
  
addEventHandler("onPlayerQuit",root, 
    function () 
        saveTime(source, getPlayerAccount(source)) 
    end 
) 

That should get the element data "joinTime" from the player when he logs out or leaves the server, and save it on player account. This won't load it, I leave that to you.

Link to comment

I did not understand Did you mean when it comes out from the server?

I have tried!

  
addEventHandler("onPlayerLogout",root, 
 function logouot(player, account) 
  if (account and not isGuestAccount(account)) then 
        local joinTime = getElementData(player,"joinTime") 
        setAccountData(account,"joinTime",joinTime) 
) 

Link to comment
I did not understand Did you mean when it comes out from the server?

I have tried!

  
  
  
addEventHandler("onPlayerLogout",root, 
 function saveTime(player, account) 
  if (account and not isGuestAccount(account)) then 
        local joinTime = getElementData(player,"joinTime") 
        setAccountData(account,"joinTime",joinTime) 
) 

addEventHandler ( 'onPlayerLogout', root, 
    function ( _, account ) 
         if ( account and not isGuestAccount ( account ) ) then 
                 local joinTime = getElementData ( _, 'joinTime' ) 
                 setAccountData ( account, 'joinTime', joinTime ) 
         end 
    end 
) 

Link to comment

You need to use end, to end each block.

exports["scoreboard"]:addScoreboardColumn("joinTime") 
function saveTime(player, account) 
    if (account and not isGuestAccount(account)) then 
        local joinTime = getElementData(player,"joinTime") 
        setAccountData(account,"joinTime",joinTime) 
    end 
end 
  
addEventHandler("onPlayerLogout",root, 
    function (prev) 
        saveTime(source, prev) 
    end 
) 
  
addEventHandler("onPlayerQuit",root, 
    function () 
        saveTime(source, getPlayerAccount(source)) 
    end 
) 
  
addEventHandler("onPlayerLogin", root, 
function(_,account) 
local joinTime = getAccountData(account,"joinTime") 
if not joinTime then joinTime = 0 end 
setElementData(source,"joinTime",joinTime) 
end) 

This will make a scoreboard column with the online time of everyplayer.

Link to comment
function onResourceStart() 
    call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Online Time") 
    for index, player in pairs (getElementsByType("player")) do 
        setElementData (player, "joinTime", getTickCount() ) 
        setElementData (player, "Online Time", "0 :, 0 :, 0 :" )         
    end 
end 
addEventHandler("onResourceStart",resourceRoot,onResourceStart) 
  
function joinTime() 
    setElementData (source, "joinTime", getTickCount() ) 
    setElementData (source, "Online Time", "0 :, 0 :, 0 :" ) 
end 
addEventHandler ( "onPlayerJoin", root, joinTime ) 
  
function all() 
    for index , player in ipairs ( getElementsByType ( "player" ) ) do 
        local s = getElementData(player,"joinTime") or getTickCount() 
         s = (getTickCount() - s) / 1000 
        local string = string.format("%02d:%02d:%02d", s/3600, s%3600/60, s%60) 
        setElementData(player,"Online Time",string) 
    end 
end 
setTimer(all,1000,0) 
  
exports["scoreboard"]:addScoreboardColumn("Online Time") 
function saveTime(player, account) 
    if (account and not isGuestAccount(account)) then 
        local Online Time = getElementData(player,"Online Time") 
        setAccountData(account,"OnlineTime",Online Time) 
    end 
end 
  
addEventHandler("onPlayerLogout",root, 
    function (prev) 
        saveTime(source, prev) 
    end 
) 
  
addEventHandler("onPlayerQuit",root, 
    function () 
        saveTime(source, getPlayerAccount(source)) 
    end 
) 
  
addEventHandler("onPlayerLogin", root, 
function(_,account) 
local Online Time = getAccountData(account,"Online Time") 
if not Online Time then Online Time = 0 end 
setElementData(source,"Online Time",Online Time) 
end) 

WARNING: Loading script failed: OnLineTime5\OnLine.lua:35: ')' expected near 'Time' 

Link to comment
function onResourceStart () 
    call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Online Time") 
     
    for index, player in pairs ( getElementsByType("player") ) do 
        setElementData (player, "joinTime", getTickCount() ) 
        setElementData (player, "Online Time", "0 :, 0 :, 0 :" )         
    end 
end 
addEventHandler("onResourceStart",resourceRoot,onResourceStart) 
  
function joinTime () 
    setElementData ( source, "joinTime", getTickCount() ) 
    setElementData ( source, "Online Time", "0 :, 0 :, 0 :" ) 
end 
addEventHandler ( "onPlayerJoin", root, joinTime ) 
  
function all() 
    for index , player in ipairs ( getElementsByType ( "player" ) ) do 
        local s = getElementData( player, "joinTime" ) or getTickCount( ) 
        s = ( getTickCount() - s ) / 1000 
        local string = string.format( "%02d:%02d:%02d", s/3600, s%3600/60, s%60 ) 
        setElementData( player, "Online Time", string ) 
    end 
end 
setTimer( all, 1000, 0) 
  
function saveTime( player, account ) 
    if ( account and not isGuestAccount(account) ) then 
        local OnlineTime = getElementData( player, "joinTime" ) 
        setAccountData(account, "OnlineTime", OnlineTime) 
    end 
end 
  
addEventHandler ( "onPlayerLogout", root, 
    function ( prev ) 
        saveTime( source, prev ) 
    end 
) 
  
addEventHandler ( "onPlayerQuit", root, 
    function ( ) 
        saveTime( source, getPlayerAccount( source ) ) 
    end 
) 
  
addEventHandler ( "onPlayerLogin", root, 
    function ( _, account ) 
        local OnlineTime = getAccountData( account, "Online Time" ) 
        if ( not OnlineTime ) then OnlineTime = 0 end 
        setElementData( source, "joinTime", OnlineTime ) 
    end 
) 

Your problem(s) we're:

1: You can't make a variable with spaces, e.g: Online Time = "hello world", it has to be: OnlineTime = "hello world".

2: You we're saving the time string, not the milliseconds.

3: It still won't work though, when you login back, it'll set it to 9 hours and something.

Link to comment

We have succeeded thanks to you

But I got a new idea I want to appear on the screen with the best time, but I can not do so :(

addEventHandler("onClientResourceStart",resourceRoot, 
    function() 
         
        best = guiCreateLabel(31,409,105,17,"BesT TimeOnLine :",false) 
        guiLabelSetColor(best,255,255,0) 
        guiSetFont(best,"default-bold-small") 
  
        playername = guiCreateLabel(133,407,135,20,"",false) 
  
        besttime = guiCreateLabel(140,428,81,20,"",false) 
    end 
) 
function() 
        call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "Online Time") 
        call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "Name") 
        call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "joinTime") 
    end 
) 

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...