NodZen_42 Posted July 10, 2018 Share Posted July 10, 2018 (edited) Hi users. I need your help with my simple script. I'm new with this. I just want to set the player in a random team, but it doesn't work. Any help ? The console says this "Bad argument @ 'setPlayerTeam' [Expected team at argument 2, got string 'Zombies']" Thanks Server local equipos = {"Zombies", "Humanos" } function crear_equipos () createTeam ("Zombies", 255,0,0) createTeam("Humanos", 0, 200,0) end addEventHandler("onResourceStart", getRootElement(), crear_equipos) function setear_equipos () if equipos then setPlayerTeam(source, equipos[math.random(#equipos)]) end end addEventHandler("onPlayerSpawn", root, setear_equipos) Edited July 10, 2018 by NodZen_42 Link to comment
NodZen_42 Posted July 10, 2018 Author Share Posted July 10, 2018 (edited) 1 hour ago, Abdul KariM said: use : getTeamFromName something like this? local equipos = {"Zombies", "Humanos" } function crear_equipos () createTeam ("Zombies", 255,0,0) createTeam("Humanos", 0, 200,0) end addEventHandler("onResourceStart", getRootElement(), crear_equipos) function setear_equipos () local check_team = getTeamFromName("Zombies") if check_team then setPlayerTeam(source, check_team) else local check_team2 = getTeamFromName("Humanos") if check_team2 then setPlayerTeam(source, check_team2) end end end addEventHandler("onPlayerSpawn", root, setear_equipos) Edited July 10, 2018 by NodZen_42 Link to comment
Abdul KariM Posted July 10, 2018 Share Posted July 10, 2018 local equipos = { --{"TeamName",r,b,g}, {"Zombies",255,0,0}, {"Humanos",0, 200,0}, } for _ ,v in ipairs ( equipos ) do createTeam ( v [ 1 ] , v [ 2 ] , v [ 3 ] , v [ 4 ] ) end addEventHandler("onPlayerSpawn", root function ( ) SpawnTeam = getTeamFromName ( equipos [ math.random ( #equipos ) ] ) if not SpawnTeam then return end setPlayerTeam ( source , SpawnTeam ) end ) Link to comment
NodZen_42 Posted July 10, 2018 Author Share Posted July 10, 2018 11 minutes ago, Abdul KariM said: local equipos = { --{"TeamName",r,b,g}, {"Zombies",255,0,0}, {"Humanos",0, 200,0}, } for _ ,v in ipairs ( equipos ) do createTeam ( v [ 1 ] , v [ 2 ] , v [ 3 ] , v [ 4 ] ) end addEventHandler("onPlayerSpawn", root function ( ) SpawnTeam = getTeamFromName ( equipos [ math.random ( #equipos ) ] ) if not SpawnTeam then return end setPlayerTeam ( source , SpawnTeam ) end ) I'll try it. Thanks you Link to comment
Discord Moderators Pirulax Posted July 10, 2018 Discord Moderators Share Posted July 10, 2018 (edited) local equipos = { --{"TeamName",r,b,g}, {"Zombies",255,0,0}, {"Humanos",0, 200,0}, } for _ ,v in ipairs ( equipos ) do createTeam (unpack(v)) end addEventHandler("onPlayerSpawn", root, function () local team = getTeamFromName(equipos[math.random(#equipos)]) if not team then return end setPlayerTeam(source, team) end ) Edited July 10, 2018 by Pirulax Link to comment
NodZen_42 Posted July 11, 2018 Author Share Posted July 11, 2018 On 10/7/2018 at 05:51, Pirulax said: local equipos = { --{"TeamName",r,b,g}, {"Zombies",255,0,0}, {"Humanos",0, 200,0}, } for _ ,v in ipairs ( equipos ) do createTeam (unpack(v)) end addEventHandler("onPlayerSpawn", root, function () local team = getTeamFromName(equipos[math.random(#equipos)]) if not team then return end setPlayerTeam(source, team) end ) The script doesn't work. The console says : Bad argument @ 'getTeamFromName' [Expected string at argument 1, got table] Link to comment
Addlibs Posted July 11, 2018 Share Posted July 11, 2018 Line 13 should be local team = getTeamFromName(equipos[math.random(#equipos)][1]) 1 Link to comment
NodZen_42 Posted July 11, 2018 Author Share Posted July 11, 2018 21 minutes ago, MrTasty said: Line 13 should be local team = getTeamFromName(equipos[math.random(#equipos)][1]) it works perfectly, thanks you. 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