Jump to content

Save text from a row in scoreboard


Adde

Recommended Posts

Hello, how should I do if I want to save the text from scoreboardColumn "Class" onPlayerQuit and then set that text back in same scoreboardColumn onPlayerLogin? Is this near right?

function openClass() 
thePlayer = getPlayerAccount(source) 
if (thePlayer) then 
getAccountData(thePlayer, "theClass") 
setElementData(thePlayer, "theClass", Class) 
end 
end 
addEventHandler("onPlayerLogin",getRootElement(), openClass) 
  
function saveClass() 
thePlayer = getPlayerAccount(source) 
if (thePlayer) then 
local theClass = getElementData(source, "Class") 
setAccountData(thePlayer,"theClass", theClass) 
end 
end 
addEventHandler("onPlayerQuit",getRootElement(), saveClass) 

Thankfull for answears :)

Link to comment
function openClass( _,acc ) 
    if not isGuestAccount( acc ) then 
        local class = getAccountData(thePlayer, "theClass") 
        if class then 
            setElementData( source, "theClass", class ) 
        end 
    end 
end 
addEventHandler( "onPlayerLogin", getRootElement( ), openClass ) 
  
function saveClass( ) 
    local thePlayer = getPlayerAccount( source ) 
    if not isGuestAccount( thePlayer ) then 
        local theClass = getElementData( source, "Class" ) 
        setAccountData( thePlayer, "theClass", theClass ) 
    end 
end 
addEventHandler( "onPlayerQuit", getRootElement( ), saveClass ) 

Link to comment
function openClass() 
local thePlayer = getPlayerAccount(source) 
    if (thePlayer) then 
        local Class = getAccountData(thePlayer, "theClass") 
        setElementData(source, "theClass", Class) 
    end 
end 
addEventHandler("onPlayerLogin",getRootElement(), openClass) 
  
function saveClass( ) 
if (isGuestAccount ( getPlayerAccount ( source ) ) ) then 
  
  else 
    local account = getPlayerAccount (source) 
    if (account) then 
        local theClass = getElementData(source, "Class") 
        setAccountData(thePlayer,"theClass", theClass) 
    end 
end 
addEventHandler("onPlayerQuit", root, saveClass) 

Link to comment
function openClass( _,acc ) 
    if not isGuestAccount( acc ) then 
        local class = getAccountData(thePlayer, "theClass") 
        if class then 
            setElementData( source, "theClass", class ) 
        end 
    end 
end 
addEventHandler( "onPlayerLogin", getRootElement( ), openClass ) 
  
function saveClass( ) 
    local thePlayer = getPlayerAccount( source ) 
    if not isGuestAccount( thePlayer ) then 
        local theClass = getElementData( source, "Class" ) 
        setAccountData( thePlayer, "theClass", theClass ) 
    end 
end 
addEventHandler( "onPlayerQuit", getRootElement( ), saveClass ) 

thePlayer O_o = acc There's no need to check guest account.

Edited by Guest
Link to comment

I had an error at line 3, Re-read the code thePlayer is the account .

Corrected code :

function openClass( _,acc ) 
    if not isGuestAccount( acc ) then 
        local class = getAccountData( acc, "theClass" ) 
        if class then 
            setElementData( source, "theClass", class ) 
        end 
    end 
end 
addEventHandler( "onPlayerLogin", getRootElement( ), openClass ) 
  
function saveClass( ) 
    local acc = getPlayerAccount( source ) 
    if not isGuestAccount( acc ) then 
        local theClass = getElementData( source, "Class" ) 
        setAccountData( acc, "theClass", theClass ) 
    end 
end 
addEventHandler( "onPlayerQuit", getRootElement( ), saveClass ) 

Link to comment
I had an error at line 3, Re-read the code thePlayer is the account .

Corrected code :

function openClass( _,acc ) 
    if not isGuestAccount( acc ) then 
        local class = getAccountData( acc, "theClass" ) 
        if class then 
            setElementData( source, "theClass", class ) 
        end 
    end 
end 
addEventHandler( "onPlayerLogin", getRootElement( ), openClass ) 
  
function saveClass( ) 
    local acc = getPlayerAccount( source ) 
    if not isGuestAccount( acc ) then 
        local theClass = getElementData( source, "Class" ) 
        setAccountData( acc, "theClass", theClass ) 
    end 
end 
addEventHandler( "onPlayerQuit", getRootElement( ), saveClass ) 

It doesn´t work :/ The scoreboardColumn "Class" is still empty for me when I log on to the server after I left it with text in that column.

Link to comment

I left MTA 4-5 month ago but i am planning to come back in 2-3 week's. But if i remember well you can't use Account Data with "onPlayerQuit" it will return NULL (it's to late when the function is called the player already left the server so you can't get his account). If i am wrong then somebody corect me how i told it was long time ago :D

Link to comment
  • 3 weeks later...
@ bandi94 :

You can use it with onPlayerQuit ( as far as i know )

@Adde :

I don't see where you're adding the scoreboard column in that code, Post your full code .

I have a whole spawn script with that column, and I add your suggestion into that script.

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