Jump to content

Saving Team


Tox

Recommended Posts

Posted

Hey uh, I am a little stuck here in my team saving script.The code is below there. I am having a trouble seeing what's wrong-not sure if it's because the "play" resource tho- so I would be so glad if you would give me a hand.

function saveTeam () 
local account = getPlayerAccount (source) 
    if not isGuestAccount (account) then 
    local team = getPlayerTeam (source) 
    setAccountData (account, "savingTeam", team) 
    end  
end 
  
addEventHandler ("onPlayerWasted", root, saveTeam) 
addEventHandler ("onPlayerQuit", root, saveTeam) 
  
function getTeam () 
local account = getPlayerAccount (source) 
    if account then 
        if not isGuestAccount (account) then 
            team = getAccountData (account, "savingTeam") 
            if team then 
            setPlayerTeam (source, team) 
            end 
        end  
    end      
end 
  
addEventHandler ("onPlayerSpawn", root, getTeam) 
addEventHandler ("onPlayerLogin", root, getTeam) 
  

Posted

function saveTeam () 
local account = getPlayerAccount (source) 
     if not account or isGuestAccount(account) then return end 
    local team = getPlayerTeam (source) 
    setAccountData (account, "savingTeam", team) 
    end  
end 
addEventHandler ("onPlayerQuit", root, saveTeam) 
  
function getTeam (_,acc) 
        local team = getAccountData (acc, "savingTeam") 
            if team then 
            setPlayerTeam (source, team) 
    end     
end 
addEventHandler ("onPlayerLogin", root, getTeam) 
  
Posted
Are you sure you are in a team before you quit the server ?

Duh, but I created the team on admin panel and set my team by admin panel also. Not sure it is wrong

Posted

Ha .. you said no error, huh ?

What about the useless end in the first function?

Try this:

function saveTeam () 
    local account = getPlayerAccount (source) 
    if not account or isGuestAccount(account) then return end 
    local team = getPlayerTeam (source) 
    setAccountData (account, "savingTeam", team) 
end 
addEventHandler ("onPlayerQuit", root, saveTeam) 
  
function getTeam (_,acc) 
    local team = getAccountData (acc, "savingTeam") 
    if team then 
        setPlayerTeam (source, team) 
    end     
end 
addEventHandler ("onPlayerLogin", root, getTeam) 

Posted (edited)

Oh ... wait you can't save the team in your account data. It has to be a string...

function saveTeam () 
    local account = getPlayerAccount (source) 
    if not account or isGuestAccount(account) then return end 
    local team = getTeamName(getPlayerTeam(source)) 
    setAccountData (account, "savingTeam", team) 
end 
addEventHandler ("onPlayerQuit", root, saveTeam) 
  
function getTeam (_,acc) 
    local team = getTeamFromName(getAccountData(acc, "savingTeam")) 
    if team then 
        setPlayerTeam (source, team) 
    end     
end 
addEventHandler ("onPlayerLogin", root, getTeam) 

Now it should work!

Edited by Guest
Posted
Ha .. you said no error, huh ?

What about the useless end in the first function?

Try this:

function saveTeam () 
    local account = getPlayerAccount (source) 
    if not account or isGuestAccount(account) then return end 
    local team = getPlayerTeam (source) 
    setAccountData (account, "savingTeam", team) 
end 
addEventHandler ("onPlayerQuit", root, saveTeam) 
  
function getTeam (_,acc) 
    local team = getAccountData (acc, "savingTeam") 
    if team then 
        setPlayerTeam (source, team) 
    end     
end 
addEventHandler ("onPlayerLogin", root, getTeam) 

Well it just doesn't work... Sorry

Posted
Oh ... wait you can't save the team in your account data. It has to be a string...
function saveTeam () 
    local account = getPlayerAccount (source) 
    if not account or isGuestAccount(account) then return end 
    local team = getTeamName(getPlayerTeam(source)) 
    setAccountData (account, "savingTeam", team) 
end 
addEventHandler ("onPlayerQuit", root, saveTeam) 
  
function getTeam (_,acc) 
    local team = getTeamFromName(getAccountData(acc, "savingTeam")) 
    if team then 
        setPlayerTeam (source, team) 
    end     
end 
addEventHandler ("onPlayerLogin", root, getTeam) 

Now it should work!

Posted
Oh ... wait you can't save the team in your account data. It has to be a string...
function saveTeam () 
    local account = getPlayerAccount (source) 
    if not account or isGuestAccount(account) then return end 
    local team = getTeamName(getPlayerTeam(source)) 
    setAccountData (account, "savingTeam", team) 
end 
addEventHandler ("onPlayerQuit", root, saveTeam) 
  
function getTeam (_,acc) 
    local team = getTeamFromName(getAccountData(acc, "savingTeam")) 
    if team then 
        setPlayerTeam (source, team) 
    end     
end 
addEventHandler ("onPlayerLogin", root, getTeam) 

Now it should work!

Oh, thank you man.

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