Jump to content

team saver not working


Johns

Recommended Posts

hi some time ago castillo give a script that saves team why it no work? he said he have no time to test.

 

function playerLogin (thePreviousAccount, theCurrentAccount, autoLogin) 
  if  not (isGuestAccount (getPlayerAccount (source))) then 
    local accountData = getAccountData (theCurrentAccount, "team") 
    if (accountData) then 
    setPlayerTeam(source,accountData) 
    end    
  end 
end 
addEventHandler ("onPlayerLogin", getRootElement(), playerLogin) 
  
function onQuit (quitType, reason, responsibleElement,thePreviousAccount) 
  if not (isGuestAccount (getPlayerAccount (source))) then 
    account = getPlayerAccount (source) 
    if (account) then 
    local team = getPlayerTeam(source) 
    local teamname = getTeamName(team)   
      setAccountData (account, "team", teamname) 
        end 
    end 
end 
addEventHandler ("onPlayerQuit", getRootElement(), onQuit) 
  
function onLogout(prevAccount) 
  if not (isGuestAccount (getPlayerAccount (source))) then 
    account = getPlayerAccount (source) 
    if (account) then 
    local team = getPlayerTeam(source) 
    local teamname = getTeamName(team) 
      setAccountData (account, "team", teamname) 
        end 
    end 
end 
addEventHandler("onPlayerLogout", getRootElement(), onLogout) 

 

Link to comment
function playerLogin (thePreviousAccount, theCurrentAccount, autoLogin) 
  if  not (isGuestAccount (getPlayerAccount (source))) then 
    local accountData = getAccountData (theCurrentAccount, "team") 
    if (accountData) then 
    setPlayerTeam(source,accountData) 
    end    
  end 
end 
addEventHandler ("onPlayerLogin", getRootElement(), playerLogin) 
  
function onQuit (quitType, reason, responsibleElement,thePreviousAccount) 
  if not (isGuestAccount (getPlayerAccount (source))) then 
    account = getPlayerAccount (source) 
    if (account) then 
    local team = getPlayerTeam(source) 
    local teamname = getTeamName(team)   
      setAccountData (account, "team", teamname) 
        end 
    end 
end 
addEventHandler ("onPlayerQuit", getRootElement(), onQuit) 
addEventHandler("onPlayerLogout", getRootElement(), onQuit)  

 

Link to comment
46 minutes ago, TheMOG said:

function playerLogin (thePreviousAccount, theCurrentAccount, autoLogin) 
  if  not (isGuestAccount (getPlayerAccount (source))) then 
    local accountData = getAccountData (theCurrentAccount, "team") 
    if (accountData) then 
    setPlayerTeam(source,accountData) 
    end    
  end 
end 
addEventHandler ("onPlayerLogin", getRootElement(), playerLogin) 

 

setPlayerTeam requires a team not a string.

function playerLogin (thePreviousAccount, theCurrentAccount, autoLogin) 
  if  not (isGuestAccount (getPlayerAccount (source))) then 
    local playerTeam = getTeamFromName(getAccountData (theCurrentAccount, "team"))
    if playerTeam then 
      setPlayerTeam(source,playerTeam) 
    end    
  end 
end 
addEventHandler ("onPlayerLogin", root, playerLogin) 

 

Edited by Mr.Loki
Link to comment

add this on your code 

	function SaveTeam (	)
	
	local aPlayersTable = getElementsByType ( "player" )
	
	if ( #aPlayersTable ~= 0 ) then	
	
	if ( eventName == "onResourceStart" ) then
	
	for _ , aPlayers in ipairs ( aPlayersTable ) do
	
	local playersAccount = getPlayerAccount ( aPlayers )
	
	if ( playersAccount ) and not ( isGuestAccount ( playersAccount ) ) then
	
	local aPlayersTeam = getTeamFromName ( getAccountData ( playersAccount , "team" ) )
	
	if ( aPlayersTeam ) then
	
	setPlayerTeam ( aPlayers , aPlayersTeam )
	
			end
		end
	end
	
	elseif ( eventName == "onResourceStop" ) then
	
	for _ , aPlayers in ipairs ( aPlayersTable ) do

	local playersAccount = getPlayerAccount ( aPlayers )
	
	if ( playersAccount ) and not ( isGuestAccount ( playersAccount ) ) then
		
	local playerTeam = getPlayerTeam ( aPlayers ) 
	
	if ( playerTeam ) then
	
	setAccountData ( playersAccount , "team" , getTeamName ( playerTeam ) )

						end
					end
				end
			end
		end
	end
addEventHandler ( "onResourceStart", resourceRoot , SaveTeam )	
addEventHandler ( "onResourceStop", resourceRoot , SaveTeam )	
	

 

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