Jump to content

Team save problem


Wei

Recommended Posts

whats wrong here ? :redhotevil:

function setTeam() 
local account = getPlayerAccount(source) -- gets players account 
local team = getAccountData (account, "team") -- gets players team 
if (team) and getTeamFromName(team) then 
      setPlayerTeam(source, getTeamFromName(team)) -- sets players team 
     end 
end 
addEventHandler("onPlayerLogin",root,setTeam) -- sets players team on login 
  
function save() 
 local team = getPlayerTeam(source) -- Gets the players team 
local account = getPlayerAccount(source) 
if (team) and not isGuestAccount(account) then -- Checks to see if the player is a guest or not 
setAccountData(account, "team", getTeamName(team)) --saves team 
 end 
    end 
addEventHandler("onPlayerQuit", getRootElement(), save) -- saves team on quit 

Link to comment

try this:

addEventHandler("onPlayerLogin",root,function() 
    local team = getAccountData (getPlayerAccount(source), "team") -- gets players team 
    if (team==getTeamName(getTeamFromName(team))) then 
      setPlayerTeam(source, getTeamFromName(team)) -- sets players team 
    end 
end) -- sets players team on login 
  
function save() 
    local team = getPlayerTeam(source) -- Gets the players team 
    local account = getPlayerAccount(source) 
    if not isGuestAccount(account) then -- Checks to see if the player is a guest or not 
        if(team)then 
            setAccountData(account, "team", getTeamName(team)) --saves team 
        end 
    end 
end 
addEventHandler("onPlayerLogout", root, save) -- saves team on logout 
addEventHandler("onPlayerQuit", root, save) -- saves team on quit 

Link to comment

Here Use My Script you'r free to edit it :D

addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), 
function() 
    teamPolice = createTeam ( "Police", 0, 0, 255 ) 
    teamFreeroamers = createTeam ( "Roberes", 255, 255, 0 ) 
    for id, player in ipairs(getElementsByType("player")) do 
    bindKey(player,"F3","down",teamP,"Police") 
    bindKey(player,"F5","down",teamP,"Roberes") 
    end 
end) 
  
function setTeam() 
    local account = getPlayerAccount(source) 
    local team = getAccountData (account, "team") 
        if team and getTeamFromName(team) then 
              setPlayerTeam(source, getTeamFromName(team)) 
    end 
end 
addEventHandler("onPlayerLogin",getRootElement(),setTeam) 
  
function saveTeam() 
    local team = getPlayerTeam(source) 
    local account = getPlayerAccount(source) 
       if (team) and not isGuestAccount(account) then 
          setAccountData(account, "team", getTeamName(team)) 
    end 
end 
addEventHandler("onPlayerQuit",getRootElement(),saveTeam) 
  
addEventHandler("onPlayerJoin",getRootElement(), 
function() 
    bindKey(source,"F3","down",teamP,"Police") 
    bindKey(source,"F5","down",teamP,"Roberes") 
end) 
  
function teamP(player,key,state,team) 
        if team == "Police" then 
            setPlayerTeam(player,teamPolice) 
        elseif team == "Roberes" then 
            setPlayerTeam(player,teamFreeroamers) 
        end 
end 

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