Jump to content

[HELP!] Save and Load team


John_Scott

Recommended Posts

Hi,

I have a problem witht my script. I would like to save the player's team when he quit, and load/set when logging in, but my code is not workins :S

Quit:

function saveAccountData(source) 
        local theTeam = getPlayerTeam ( source ) 
    setAccountData ( playeraccount, "tg.team", theTeam ) 
end 

Connect:

function loadAccountData() 
            local playerTeam = getAccountData ( playeraccount, "tg.team" ) 
             
            -- Spawning Player 
            local gx, gy, gz = 2500.9230957031, -1671.9180908203, 13.787899971008 
            spawnPlayer (source, gx, gy, gz, 0, playerSkin, 0, 0, playerTeam) 
            setCameraTarget ( source, source) 
end 

Thanks for help!

Link to comment

You can't store a team element, you must store the team name instead.

Saving:

function saveAccountData(source) 
    local theTeam = getPlayerTeam ( source ) 
    setAccountData ( playeraccount, "tg.team", getTeamName ( theTeam ) ) 
end 

Loading:

function loadAccountData() 
            local playerTeam = getAccountData ( playeraccount, "tg.team" ) 
            
            -- Spawning Player 
            local gx, gy, gz = 2500.9230957031, -1671.9180908203, 13.787899971008 
            spawnPlayer (source, gx, gy, gz, 0, playerSkin, 0, 0, getTeamFromName ( playerTeam) ) 
            setCameraTarget ( source, source) 
end 

Link to comment

Now working now too

Save data:

function saveAccountData(source) 
    local playeraccount = getPlayerAccount ( source ) 
        if ( playeraccount ) then 
            -- Save Money 
            local playermoney = getPlayerMoney ( source ) 
            setAccountData ( playeraccount, "tg.money", playermoney ) 
            outputChatBox("Money: " .. playermoney) 
             
            --Save Team 
            local theTeam = getPlayerTeam ( source ) 
            setAccountData ( playeraccount, "tg.team", getTeamName ( theTeam ) ) 
                outputChatBox("Team: " .. theTeam) 
             
            --Save Skin 
            local playerSkin = getElementModel ( source ) 
            setAccountData ( playeraccount, "tg.skin", playerSkin ) 
            outputChatBox("Skin ID: " .. playerSkin) 
        end 
end 
addEventHandler ( "onPlayerQuit", getRootElement ( ), saveAccountData ) 
addCommandHandler("save-all", saveAccountDat 

a)

Load data:

function loadAccountData() 
    local playeraccount = getPlayerAccount (source) 
        if ( playeraccount ) then 
            --Load Team 
            local playerTeam = getAccountData ( playeraccount, "tg.team" ) 
            
            --Load Skin 
            local playerSkin = getAccountData ( playeraccount, "tg.skin" ) 
             
            -- Spawning Player 
            local gx, gy, gz = 2500.9230957031, -1671.9180908203, 13.787899971008 
            spawnPlayer (source, gx, gy, gz, 0, playerSkin, 0, 0, getTeamFromName ( playerTeam) ) 
            setCameraTarget ( source, source) 
            outputChatBox("Spaswned") 
             
            -- Load Money 
            local playermoney = getAccountData ( playeraccount, "tg.money" ) 
                setPlayerMoney ( source, playermoney ) 
     
        end 
end 

Error:

http://kepfeltoltes.hu/131222/error_www ... es.hu_.png

Link to comment

Already try it, but doesn't work :S

Code:

function saveAccountData(thePlayer) 
    local playeraccount = getPlayerAccount ( thePlayer ) 
        if ( playeraccount ) then 
            -- Save Money 
            local playermoney = getPlayerMoney ( thePlayer ) 
            setAccountData ( playeraccount, "tg.money", playermoney ) 
            outputChatBox("Money: " .. playermoney) 
             
            --Save Team 
            local theTeam = getPlayerTeam ( thePlayer ) 
            local playerTeam = getTeamName ( theTeam ) 
            setAccountData ( playeraccount, "tg.team", playerTeam ) 
                outputChatBox("Team: " .. playerTeam ) 
             
            --Save Skin 
            local playerSkin = getElementModel ( thePlayer ) 
            setAccountData ( playeraccount, "tg.skin", playerSkin ) 
            outputChatBox("Skin ID: " .. playerSkin) 
        end 
end 
addEventHandler ( "onPlayerQuit", getRootElement ( ), saveAccountData ) 
addCommandHandler("save-all", saveAccountData) 
  
function loadAccountData() 
    local playeraccount = getPlayerAccount (source) 
        if ( playeraccount ) then 
             
            -- Spawning Player 
            local gx, gy, gz = 2500.9230957031, -1671.9180908203, 13.787899971008 
            spawnPlayer (source, gx, gy, gz, 0, 0, 0, 0, nil) 
            setCameraTarget ( source, source) 
            outputChatBox("Spaswned") 
             
            --Load Team 
            local playerTeam = getAccountData ( playeraccount, "tg.team" ) 
            local theTeam = getTeamFromName ( "playerTeam" ) 
            setPlayerTeam ( source, theTeam ) 
             
            --Load Skin 
            local playerSkin = getAccountData ( playeraccount, "tg.skin" ) 
            setElementModel(source, playerSkin) 
             
            -- Load Money 
            local playermoney = getAccountData ( playeraccount, "tg.money" ) 
                setPlayerMoney ( source, playermoney ) 
     
        end 
end 

Link to comment

I now use the onPlayerLogin, i place the function's call to the XML login:

function PlayerLogin(username,password,checksave) 
    if not (username == "") then 
        if not (password == "") then 
            local account = getAccount ( username, password ) 
            if ( account ~= false ) then 
                logIn(source, account, password) 
  
                triggerClientEvent (source,"hideLoginWindow",getRootElement()) 
                 
                    if checksave == true then 
                        triggerClientEvent(source,"saveLoginToXML",getRootElement(),username,password) 
                    else 
                        triggerClientEvent(source,"resetSaveXML",getRootElement(),username,password) 
                    end 
                 
                    loadAccountData() 
                 
            else 
                triggerClientEvent(source,"set_warning_text",getRootElement(),"Login","Wrong username and/or password") 
            end 
        else 
            triggerClientEvent(source,"set_warning_text",getRootElement(),"Login","Please enter your password!") 
        end 
    else 
        triggerClientEvent(source,"set_warning_text",getRootElement(),"Login","Please enter your username!") 
    end 
end 
addEvent("onRequestLogin",true) 
addEventHandler("onRequestLogin",getRootElement(),PlayerLogin) 

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