Jump to content

getElementData


Chronic

Recommended Posts

Hello :roll:

For some reason getElementData is always returning false.

server

addEventHandler ( "onPlayerQuit", root,  
    function ( ) 
    setElementData ( source, "team", getPlayerTeam ( source ) ) 
    setElementData ( source, "skin", getElementModel ( source ) ) 
    end ) 
  
addEventHandler ( "onPlayerJoin", root,  
    function ( ) 
    setElementModel ( source, getElementData ( source, "skin" ) ) 
    setPlayerTeam ( source, getElementData ( source, "team" ) ) 
    end ) 

Does anyone know how to fix this?

Edited by Guest
Link to comment

Element data is lost whenever the element is destroyed. In your case, the element is a player who is just about to leave your server. So his data is lost. You will have to find another way of storing your data. You can for example use setAccountData, or create an xml file where you'd store their serials next to their settings.

Link to comment

Alright I tried it, the skin gets set on login, however the team doesn't.

addEventHandler ( "onPlayerQuit", root,  
    function ( ) 
    acc = getPlayerAccount ( source ) 
    setAccountData ( acc, "team", getPlayerTeam ( source ) ) 
    setAccountData ( acc, "skin", getElementModel ( source ) ) 
    end ) 
  
addEventHandler ( "onPlayerLogin", root,  
    function ( ) 
    setElementModel ( source, getAccountData ( acc, "skin" ) ) 
    setPlayerTeam ( source, getAccountData ( acc, "team" ) ) 
    end ) 

Link to comment

You can't save elements via setAccountData. If you want to save the team, you'll have to find another solution such as saving the team name + using getTeamFromName later.

EDIT:

addEventHandler("onPlayerQuit", root, 
    function() 
        local acc = getPlayerAccount(source) 
        setAccountData(acc, "team", getTeamName(getPlayerTeam(source))) 
        setAccountData(acc, "skin", getElementModel(source)) 
    end 
) 
  
addEventHandler("onPlayerLogin", root, 
    function(oldAccount, newAccount) 
        setElementModel(source, getAccountData(newAccount, "skin")) 
         
        local teamName = getAccountData(newAccount, "team") 
        local team = getTeamFromName(teamName) or createTeam(teamName) -- get existing team if exists or create a new one 
        setPlayerTeam(source, team) 
    end 
) 

(Untested)

Edited by Guest
Link to comment
addEventHandler("onPlayerQuit", root, 
function() 
    local acc = getPlayerAccount(source) 
    if acc and not isGuestAccount(acc) then 
        local team = getPlayerTeam(source) 
        setAccountData(acc, "skin", getElementModel(source)) 
        if team then 
            setAccountData(acc, "team", getTeamName(team)) 
        else 
            setAccountData(acc, "team", false) 
        end 
    end 
end) 
  
addEventHandler("onPlayerLogin", root, 
function(_, acc) 
    local skin = getAccountData(acc, "skin") 
    local teamName = getAccountData(acc, "team") 
    local team = teamName and getTeamFromName(teamName) or false 
    setElementModel(source, skin) 
    if team then 
        setPlayerTeam(source, team) 
    end 
end) 

You may want to spawn the player before anyway.

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