Jump to content

Need help with savesystem


MrJuhis

Recommended Posts

So this is my code. When i quit from the game and go back to game, i go to the staff team every time i login. Even when i quit on another team but it still goes to the staff team. It looks like it doesn't not save the stats when i quit. Any help is welcome! :)

function SaveTeamOnLogOut() 
local playerTeam = getPlayerTeam ( source ) 
local TeamName = getTeamName ( playerTeam ) 
local playerAccount = getPlayerAccount(source) 
local r,g,b = getPlayerNametagColor ( source ) 
  
setAccountData(playerAccount, "Team", TeamName ) 
setAccountData(playerAccount, "Tag", r,g,b ) 
setAccountData(playerAccount, "Occupation", getElementData( source, "Occupation") ) 
end 
addEventHandler("onPlayerQuit",getRootElement(),SaveTeamOnLogOut) 
  
function LoadSaveOnLogin() 
local playerAccount = getPlayerAccount(source) 
local r,g,b = getAccountData(playerAccount, "Tag") 
setPlayerTeam( source, getTeamFromName(getAccountData(playerAccount, "Team"))) 
setPlayerNametagColor ( source, r, g, b ) 
setElementData( source, "Occupation",(getAccountData(playerAccount, "Occupation")), true ) 
end 
addEventHandler("onPlayerLogin",getRootElement(),LoadSaveOnLogin) 

And the errors that script output:

WARNING: Bad argument @ 'setPlayerNametagColor' [Expected number at argument 3, got nil] 

Link to comment
It's because getElementData (line 15 of your snippet) only returns one value.

I tried again with code:

function SaveTeamOnLogOut() 
local playerTeam = getPlayerTeam ( source ) 
local TeamName = getTeamName ( playerTeam ) 
local playerAccount = getPlayerAccount(source) 
if playerAccount then 
setAccountData(playerAccount, "Team", TeamName ) 
setAccountData(playerAccount, "Occupation", getElementData( source, "Occupation") ) 
end 
end 
addEventHandler("onPlayerQuit",getRootElement(),SaveTeamOnLogOut) 
  
function LoadSaveOnLogin() 
local playerAccount = getPlayerAccount(source) 
if playerAccount then 
setPlayerTeam( source, getTeamFromName(getAccountData(playerAccount, "Team"))) 
setElementData( source, "Occupation",(getAccountData(playerAccount, "Occupation")), true ) 
end 
end 
addEventHandler("onPlayerLogin",getRootElement(),LoadSaveOnLogin) 

It doesn't work and doesn't output any errors. It moves me again to the staff team.

Link to comment

For your error, try this script:

function SaveTeamOnLogOut() 
    local playerAccount = getPlayerAccount(source) 
    if playerAccount then 
        local playerTeam = getPlayerTeam ( source ) 
        local TeamName = getTeamName ( playerTeam ) 
        local Nametag = getPlayerNametagColor ( source ) 
        local occupation = getElementData( source, "Occupation") 
         
        setAccountData(playerAccount, "Team", TeamName ) 
        setAccountData(playerAccount, "Tag", Nametag ) 
        setAccountData(playerAccount, "Occupation", occupation ) 
    end 
end 
addEventHandler("onPlayerQuit",getRootElement(),SaveTeamOnLogOut) 
  
function LoadSaveOnLogin() 
    local playerAccount = getPlayerAccount(source) 
    if playerAccount then 
        local r,g,b = getAccountData(playerAccount, "Tag") 
        local TeamName = getAccountData(playerAccount, "Team") 
        local occupation = getAccountData(playerAccount, "Occupation") 
         
        setPlayerTeam( source, getTeamFromName(TeamName)) 
        setPlayerNametagColor ( source, r, g, b ) 
        setElementData( source, "Occupation", occupation, true ) 
    end 
end 
addEventHandler("onPlayerLogin",getRootElement(),LoadSaveOnLogin) 

And about getting in the same team everytime, it may not be a bug of this script but a feature of your other script?

Try stopping related scripts and running this one again.

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