Jump to content

Team save problem


Wei

Recommended Posts

Posted

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 

Diet with russian vodka, lose 3 days in one week !

Posted

You've set the script as server side on meta.xml, right?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
You've set the script as server side on meta.xml, right?

ofc.

And no debug errors.

Onli some errors from login panel...

Diet with russian vodka, lose 3 days in one week !

Posted

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 

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

Posted

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 

My ingame nickname : Ops!

-DeathMatch GameMode By Ops! : 5%

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