acp___(PL) Posted October 6, 2009 Share Posted October 6, 2009 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
Gamesnert Posted October 6, 2009 Share Posted October 6, 2009 It's probably even more annoying to see the cause... addEventHandler('onPlayerJoin', getRootElement(), teamslogin.handlePlayerJoin) -- Move this line to AFTER the function is defined Link to comment
XetaQuake Posted October 6, 2009 Share Posted October 6, 2009 You can move a Player inside a Team while spawning - using the last spawnPlayer() argument. Possible, this would save your some codelines. Link to comment
acp___(PL) Posted October 7, 2009 Author Share Posted October 7, 2009 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 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
acp___(PL) Posted October 13, 2009 Author Share Posted October 13, 2009 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
zorrigas Posted October 15, 2009 Share Posted October 15, 2009 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 Link to comment
acp___(PL) Posted November 5, 2009 Author Share Posted November 5, 2009 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) Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now