Jump to content

TeamSaver


ZeyadGTX

Recommended Posts

Hello i have this script which saves team when quit but the problem is : i kicked some one from The Team when he reconnect again he joins the Team Automatic i want it saves if the player in Team or not because when i kick my self from the team when i reconnect i join the team again automatic

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

When the player quits you only store data in the "team" key if the player is in a team. You skip the case if getPlayerTeam returns false. Check if there was no team found and set "false" inside the "team" key and then when he joins, check if the string from the account data is "false" and skip the setting of the team if so, else set it's team to getTeamFromName(getAccountData(account,"team)).

Link to comment
tell me what functions -_-

Or you are just going to read the scripting tutorials so you know how to do the basics. If you want free scripts, then move to https://community.multitheftauto.com/ and download them there. We are not your slaves here to give you every script you want. Go learn the basics, go learn understand what the scripts are actually doing at every rule. Then you LEARN to script something like this EASILY.

Link to comment

Replace from line 13 to this:

if team and not isGuestAccount(account) then  
    setAccountData(account, "team", getTeamName(team))  
elseif not team then 
    setAccountData(account, "team", getTeamFromName("Insert_teme_here"))  
end 

Personally I would use the solution provided by Cheez3D, but since that wasn't good enough for you, we're making it the hard way. This solves the special case but causes new issues if you want to have team less players too, which I wouldn't recommend, it's all up to you now.

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