Jump to content

Automatically add to the team


acp___(PL)

Recommended Posts

t is very annoying that such a simple script that I do not want to work ... : (

teamslogin = {}
teamslogin.__index = teamslogin
-- Events
addEventHandler('onResourceStart', getRootElement(),
function()
	teamslogin.startup()
	for i,player in ipairs(getElementsByType('player')) do
		teamslogin.handlePlayerJoin(player)
		outputConsole( "onResourceStart ipairs" )
	end
end
)
addEventHandler('onPlayerJoin', getRootElement(), teamslogin.handlePlayerJoin)
addEventHandler('onResourceStop', getRootElement(),
function()
	teamlist = nil
end
)
-- Startup
function teamslogin.startup()
teamlist = {}
teamlist[1] = createTeam ( "White", 255, 255, 255 )
teamlist[2] = createTeam ( "Gray", 129, 129, 129 )
teamlist[3] = createTeam ( "Black", 0, 0, 0 )
teamlist[4] = createTeam ( "2paq Drivers", 0, 0, 255 )
teamlist[5] = createTeam ( "Wojak Team", 153, 150, 26 )
teamlist[6] = createTeam ( "S&S bRoTHEr", 0, 255, 0 )
teamlist[7] = createTeam ( "DeTeR Team", 255, 255, 0 )
teamlist[8] = createTeam ( "MYsieZIMYnieBOIMY", 64, 0, 128 )
teamlist[9] = createTeam ( "Alkaida Team", 255, 140, 0 )
end
-- Players
function teamslogin.handlePlayerJoin(player)
if getPlayerName(player) == "[2RT]acp___(PL)" then
	setPlayerTeam ( player, teamlist[4] )
	outputConsole ( "teamslogin.handlePlayerJoin - [2RT]acp___(PL)" )
elseif getPlayerName(player) == "[2RT]DeTeR.PL" then
	setPlayerTeam ( player, teamlist[7] )
	outputConsole ( "teamslogin.handlePlayerJoin - [2RT]DeTeR.PL" )
elseif getPlayerName(player) == "[2RT]Wojak[PL]" then
	setPlayerTeam ( player, teamlist[5] )
	outputConsole ( "teamslogin.handlePlayerJoin - [2RT]Wojak[PL]" )
elseif getPlayerName(player) == "[2RT]Spazz" or getPlayerName(player) == "[2RT]Stroow" then
	setPlayerTeam ( player, teamlist[6] )
	outputConsole ( "teamslogin.handlePlayerJoin - [2RT]Spazz" )
elseif getPlayerName(player) == "enter" or getPlayerName(player) == "[2RT]macwiek" then
	setPlayerTeam ( player, teamlist[8] )
	outputConsole ( "teamslogin.handlePlayerJoin - [2RT]macwiek" )
end
outputConsole( "teamslogin.handlePlayerJoin" )
end

wants to on player join to server immediately added to the selected team

Link to comment

When I enter the server, doesn't log me into the team, but changes the color of the color of my team

if I add manually, t the next race throws me out of the team

I tried, spawnPlayer() but were similar problems

funny is that, a colleague also is try do that and we can not come to anything meaningful

teamsloginworning.png

teamslogin = {}
teamslogin.__index = teamslogin
addEventHandler('onResourceStart', getRootElement(),
function()
	teamslogin.startup()
	for i,player in ipairs(getElementsByType('player')) do
		teamslogin.handlePlayerJoin(player)
		outputConsole( "onResourceStart ipairs" )
	end
end
)
function teamslogin.handlePlayerJoin(player)
if getPlayerName(player) == "[2RT]acp___(PL)" then
	setPlayerTeam ( player, teamlist[4] )
	outputConsole ( "teamslogin.handlePlayerJoin - [2RT]acp___(PL)" )
elseif getPlayerName(player) == "[2RT]DeTeR.PL" then
	setPlayerTeam ( player, teamlist[7] )
	outputConsole ( "teamslogin.handlePlayerJoin - [2RT]DeTeR.PL" )
elseif getPlayerName(player) == "[2RT]Wojak[PL]" then
	setPlayerTeam ( player, teamlist[5] )
	outputConsole ( "teamslogin.handlePlayerJoin - [2RT]Wojak[PL]" )
elseif getPlayerName(player) == "[2RT]Spazz" or getPlayerName(player) == "[2RT]Stroow" then
	setPlayerTeam ( player, teamlist[6] )
	outputConsole ( "teamslogin.handlePlayerJoin - [2RT]Spazz" )
elseif getPlayerName(player) == "enter" or getPlayerName(player) == "[2RT]macwiek" then
	setPlayerTeam ( player, teamlist[8] )
	outputConsole ( "teamslogin.handlePlayerJoin - [2RT]macwiek" )
end
outputConsole( "teamslogin.handlePlayerJoin" )
end
addEventHandler('onPlayerJoin', getRootElement(), teamslogin.handlePlayerJoin)
addEventHandler('onResourceStop', getRootElement(),
function()
	teamlist = nil
end
)
function teamslogin.startup()
teamlist = {}
teamlist[1] = createTeam ( "White", 255, 255, 255 )
teamlist[2] = createTeam ( "Gray", 129, 129, 129 )
teamlist[3] = createTeam ( "Black", 0, 0, 0 )
teamlist[4] = createTeam ( "2paq Drivers", 0, 0, 255 )
teamlist[5] = createTeam ( "Wojak Team", 153, 150, 26 )
teamlist[6] = createTeam ( "S&S bRoTHErS", 0, 255, 0 )
teamlist[7] = createTeam ( "DeTeR Team", 255, 255, 0 )
teamlist[8] = createTeam ( "MYsieZIMYnieBOIMY", 64, 0, 128 )
teamlist[9] = createTeam ( "Alkaida Team", 255, 140, 0 )
end

Link to comment

there are no errors, but it does not work ...

executes all lines other than the addition to the team ...

function teamsloginhandleDopetla()
for iTL,the_playerTL in ipairs(getElementsByType('player')) do
	teamsloginhandlePlayerJoin(the_playerTL)
	outputConsole( "teamsloginhandleDopetla() ipairs" )
end
end
 
function teamsloginhandlePlayerJoin(the_playerTHPJ)
local teamsLoginPlayerName = getPlayerName(the_playerTHPJ)
if teamsLoginPlayerName == "[2RT]acp___(PL)" then
	setPlayerTeam ( the_playerTHPJ, teamlist[4] )
	outputConsole ( "teamslogin.handlePlayerJoin - " ..teamsLoginPlayerName )
elseif teamsLoginPlayerName == "[2RT]DeTeR.PL" then
	setPlayerTeam ( the_playerTHPJ, teamlist[7] )
	outputConsole ( "teamslogin.handlePlayerJoin - " ..teamsLoginPlayerName )
elseif teamsLoginPlayerName == "[2RT]Wojak[PL]" then
	setPlayerTeam ( the_playerTHPJ, teamlist[5] )
	outputConsole ( "teamslogin.handlePlayerJoin - " ..teamsLoginPlayerName )
elseif teamsLoginPlayerName == "[2RT]Spazz" or teamsLoginPlayerName == "[2RT]Stroow" then
	setPlayerTeam ( the_playerTHPJ, teamlist[6] )
	outputConsole ( "teamslogin.handlePlayerJoin - " ..teamsLoginPlayerName )
elseif teamsLoginPlayerName == "enter" or teamsLoginPlayerName == "[2RT]macwiek" then
	setPlayerTeam ( the_playerTHPJ, teamlist[8] )
	outputConsole ( "teamslogin.handlePlayerJoin - [2RT]macwiek" ..teamsLoginPlayerName )
end
outputConsole( "teamslogin.handlePlayerJoin" )
end
addEvent('onMapStarting')
addEventHandler('onMapStarting', getRootElement() , teamsloginhandleDopetla)
 
addEventHandler('onResourceStart', getRootElement(), 
function()
teamlist = {}
teamlist[1] = createTeam ( "White", 255, 255, 255 )
teamlist[2] = createTeam ( "Gray", 129, 129, 129 )
teamlist[3] = createTeam ( "Black", 0, 0, 0 )
teamlist[4] = createTeam ( "2paq Drivers", 0, 0, 255 )
teamlist[5] = createTeam ( "Wojak Team", 153, 150, 26 )
teamlist[6] = createTeam ( "S&S bRoTHErS", 0, 255, 0 )
teamlist[7] = createTeam ( "DeTeR Team", 255, 255, 0 )
teamlist[8] = createTeam ( "MYsieZIMYnieBOIMY", 64, 0, 128 )
teamlist[9] = createTeam ( "Alkaida Team", 255, 140, 0 )
end
)
addEventHandler('onResourceStop', getRootElement(),
function()
	teamlist = nil
end
)

Link to comment

getElementsByType('player'), this get ALL PLAYERS!

I edit the script and make it work properly achieved without any problem.

this is a small sample as I was able to operate

function teamsloginhandlePlayerJoin()
local teamsLoginPlayerName = getPlayerName(source)
if teamsLoginPlayerName == "blabla" then
setPlayerTeam ( source, teamlist[1])
end
end
 
addEventHandler('onPlayerJoin', getRootElement(), teamsloginhandlePlayerJoin)
addEventHandler('onResourceStart', getResourceRootElement(getThisResource()),
function()
  teamlist = {}
  teamlist[1] = createTeam ( "Pico", 255, 255, 255 )
  teamlist[2] = createTeam ( "Pal que", 255, 255, 255 )
  teamlist[3] = createTeam ( "Lee", 255, 255, 255 )
end
)

greetings and sharing resources remember :D

Link to comment
  • 3 weeks later...

I do not know why but the script will only work once you start

This works better, but there are errors

local teamlist = {}
function teamsloginhandlePlayerJoin()
local teamsLoginPlayerName = getPlayerName(source)
if teamsLoginPlayerName == "[2RT]acp___(PL)" then
	teamlist[4] = createTeam ( "2paq Best Drivers", 0, 0, 255 )
	setPlayerTeam ( source, teamlist[4] )
	outputConsole ( "teamslogin.handlePlayerJoin: " ..teamsLoginPlayerName )
elseif teamsLoginPlayerName == "[2RT]DeTeR.PL" then
	teamlist[7] = createTeam ( "DeTeARm", 255, 255, 0 )
	setPlayerTeam ( source, teamlist[7] )
	outputConsole ( "teamslogin.handlePlayerJoin: " ..teamsLoginPlayerName )
elseif teamsLoginPlayerName == "[2RT]Wojak[PL]" then
	teamlist[5] = createTeam ( "Military Boys", 153, 150, 26 )
	setPlayerTeam ( source, teamlist[5] )
	outputConsole ( "teamslogin.handlePlayerJoin: " ..teamsLoginPlayerName )
elseif teamsLoginPlayerName == "[2RT]Spazz" or teamsLoginPlayerName == "[2RT]Stroow" then
	teamlist[6] = createTeam ( "S&S bRoTHErS", 0, 255, 0 )
	setPlayerTeam ( source, teamlist[6] )
	outputConsole ( "teamslogin.handlePlayerJoin: " ..teamsLoginPlayerName )
elseif teamsLoginPlayerName == "enter" or teamsLoginPlayerName == "[2RT]macwiek" then
	teamlist[8] = createTeam ( "MYsieZIMYnieBOIMY", 64, 0, 128 )
	setPlayerTeam ( source, teamlist[8] )
	outputConsole ( "teamslogin.handlePlayerJoin: " ..teamsLoginPlayerName )
elseif teamsLoginPlayerName == "Alf_PL" then
	teamlist[11] = createTeam ( "Alien Team", 128, 128, 255 )
	setPlayerTeam ( source, teamlist[11] )
	outputConsole ( "teamslogin.handlePlayerJoin: " ..teamsLoginPlayerName )
elseif teamsLoginPlayerName == "[2RT]equlibrium" then
	teamlist[10] = createTeam ( "librium team", 255, 0, 0 )
	setPlayerTeam ( source, teamlist[10] )
	outputConsole ( "teamslogin.handlePlayerJoin: " ..teamsLoginPlayerName )
else
	outputConsole ( "teamslogin.handlePlayerJoin - else: " ..teamsLoginPlayerName )
end
end
addEventHandler('onPlayerJoin', getRootElement(), teamsloginhandlePlayerJoin)
addEventHandler('onResourceStart', getRootElement(), 
function()
teamlist[1] = createTeam ( "White", 255, 255, 255 )
teamlist[2] = createTeam ( "Gray", 129, 129, 129 )
teamlist[3] = createTeam ( "Black", 0, 0, 0 )
--	teamlist[9] = createTeam ( "SerV's TeaM", 255, 140, 0 )
end
)
addEventHandler('onResourceStop', getRootElement(),
function()
	teamlist = nil
end
)
function teamsloginhandlePlayerQuit()
local teamsLoginPlayerName = getPlayerName(source)
if teamsLoginPlayerName == "[2RT]acp___(PL)" then
	destroyElement(teamlist[4])
	teamlist[4] = nil
	outputConsole ( "teamslogin.handlePlayerQuit: " ..teamsLoginPlayerName )
elseif teamsLoginPlayerName == "[2RT]DeTeR.PL" then
	destroyElement(teamlist[7])
	source, teamlist[7] = nil
	outputConsole ( "teamslogin.handlePlayerQuit: " ..teamsLoginPlayerName )
elseif teamsLoginPlayerName == "[2RT]Wojak[PL]" then
	destroyElement(teamlist[5])
	source, teamlist[5] = nil
	outputConsole ( "teamslogin.handlePlayerQuit: " ..teamsLoginPlayerName )
elseif teamsLoginPlayerName == "[2RT]Spazz" or teamsLoginPlayerName == "[2RT]Stroow" then
	destroyElement(teamlist[6])
	source, teamlist[6] = nil
	outputConsole ( "teamslogin.handlePlayerQuit: " ..teamsLoginPlayerName )
elseif teamsLoginPlayerName == "enter" or teamsLoginPlayerName == "[2RT]macwiek" then
	destroyElement(teamlist[8])
	source, teamlist[8] = nil
	outputConsole ( "teamslogin.handlePlayerQuit: " ..teamsLoginPlayerName )
elseif teamsLoginPlayerName == "Alf_PL" then
	destroyElement(teamlist[11])
	source, teamlist[11] = nil
	outputConsole ( "teamslogin.handlePlayerQuit: " ..teamsLoginPlayerName )
elseif teamsLoginPlayerName == "[2RT]equlibrium" then
	destroyElement(teamlist[10])
	source, teamlist[10] = nil
	outputConsole ( "teamslogin.handlePlayerQuit: " ..teamsLoginPlayerName )
else
	outputConsole ( "teamslogin.handlePlayerQuit - else: " ..teamsLoginPlayerName )
end
if getPlayerName(source) == "[2RT]Wojak[PL]" then
  destroyElement(teamlist5)
	end
end
addEventHandler('onPlayerQuit', getRootElement(), teamsloginhandlePlayerQuit)
function teamsloginhandlePlayerChangeNick(oldNick, newNick)
if oldNick == "[2RT]acp___(PL)" then
	destroyElement(teamlist[4])
	teamlist[4] = nil
	outputConsole ( "teamslogin.handlePlayerChangeNick: " ..oldNick )
elseif oldNick == "[2RT]DeTeR.PL" then
	destroyElement(teamlist[7])
	source, teamlist[7] = nil
	outputConsole ( "teamslogin.handlePlayerChangeNick: " ..oldNick )
elseif oldNick == "[2RT]Wojak[PL]" then
	destroyElement(teamlist[5])
	source, teamlist[5] = nil
	outputConsole ( "teamslogin.handlePlayerChangeNick: " ..oldNick )
elseif oldNick == "[2RT]Spazz" or oldNick == "[2RT]Stroow" then
	destroyElement(teamlist[6])
	source, teamlist[6] = nil
	outputConsole ( "teamslogin.handlePlayerChangeNick: " ..oldNick )
elseif oldNick == "enter" or oldNick == "[2RT]macwiek" then
	destroyElement(teamlist[8])
	source, teamlist[8] = nil
	outputConsole ( "teamslogin.handlePlayerChangeNick: " ..oldNick )
elseif oldNick == "Alf_PL" then
	destroyElement(teamlist[11])
	source, teamlist[11] = nil
	outputConsole ( "teamslogin.handlePlayerChangeNick: " ..oldNick )
elseif oldNick == "[2RT]equlibrium" then
	destroyElement(teamlist[10])
	source, teamlist[10] = nil
	outputConsole ( "teamslogin.handlePlayerChangeNick: " ..oldNick )
else
	outputConsole ( "teamslogin.handlePlayerChangeNick - else: " ..oldNick )
end
if newNick == "[2RT]acp___(PL)" then
	teamlist[4] = createTeam ( "2paq Best Drivers", 0, 0, 255 )
	setPlayerTeam ( source, teamlist[4] )
	outputConsole ( "teamslogin.handlePlayerJoinChangeNick: " ..newNick )
elseif newNick == "[2RT]DeTeR.PL" then
	teamlist[7] = createTeam ( "DeTeARm", 255, 255, 0 )
	setPlayerTeam ( source, teamlist[7] )
	outputConsole ( "teamslogin.handlePlayerJoinChangeNick: " ..newNick )
elseif newNick == "[2RT]Wojak[PL]" then
	teamlist[5] = createTeam ( "Military Boys", 153, 150, 26 )
	setPlayerTeam ( source, teamlist[5] )
	outputConsole ( "teamslogin.handlePlayerJoinChangeNick: " ..newNick )
elseif newNick == "[2RT]Spazz" or newNick == "[2RT]Stroow" then
	teamlist[6] = createTeam ( "S&S bRoTHErS", 0, 255, 0 )
	setPlayerTeam ( source, teamlist[6] )
	outputConsole ( "teamslogin.handlePlayerJoinChangeNick: " ..newNick )
elseif newNick == "enter" or newNick == "[2RT]macwiek" then
	teamlist[8] = createTeam ( "MYsieZIMYnieBOIMY", 64, 0, 128 )
	setPlayerTeam ( source, teamlist[8] )
	outputConsole ( "teamslogin.handlePlayerJoinChangeNick: " ..newNick )
elseif newNick == "Alf_PL" then
	teamlist[11] = createTeam ( "Alien Team", 128, 128, 255 )
	setPlayerTeam ( source, teamlist[11] )
	outputConsole ( "teamslogin.handlePlayerJoinChangeNick: " ..newNick )
elseif newNick == "[2RT]equlibrium" then
	teamlist[10] = createTeam ( "librium team", 255, 0, 0 )
	setPlayerTeam ( source, teamlist[10] )
	outputConsole ( "teamslogin.handlePlayerJoinChangeNick: " ..newNick )
else
	outputConsole ( "teamslogin.handlePlayerJoinChangeNick - else: " ..newNick )
end
end
addEventHandler('onPlayerChangeNick', getRootElement(), teamsloginhandlePlayerChangeNick)

errorvw.png

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