Call a function to make everyone switch teams

Hey, i am trying to work this out, i have been trying to get player.GetAll() to work and i have checked all over google, and nothing works
Basically, when the function restart_round is called, i would like it to set everyone to team 2

Thanks!

http://wiki.garrysmod.com/favicon.ico - team.GetPlayers()

How do i make it so, that it sets everyone in team 1 to team 2, and sets everyone in team 3 to team 2?

[LUA]for k,v in pairs(team.GetPlayers(1)) do
v:SetTeam(2) end[/LUA]

Something like that. Same for team 3 to team 2. I didn’t test that but, basically for loops and the function I linked you up there.

I can’t test this right now sorry pal. (SCRIPT UNTESTED)
[LUA]function teamchange()
for _,v in pairs(team.GetPlayers(1)) do
v:SetTeam(2)
end
for _,v in pairs(team.GetPlayers(3)) do
v:SetTeam(2)
end
end
concommand.Add(“changeteam”, “chageteams”, teamchange)[/LUA]

Why making “v:Team() == 2” on first for loop and “v:SetTeam(2)” on the second one?

When i use this, it breaks the gamemode :confused:

Sorry about that I made a mistake I edited it now. Thank you Tenrys for pointing me out.

I’ll test it out again

EDIT: Doesn’t seem to do anything, the command runs, then nothing, in console this is the error

] changeteam

[ERROR] lua/includes/modules/concommand.lua:69: attempt to call a string value

  1. unknown - lua/includes/modules/concommand.lua:69

[editline]14th July 2013[/editline]

That’s what i was already trying, expect with player.GetAll
Still doesn’t work?

His code looks correct, the issues with it is that he is giving concommand.Add three arguments when it only takes two.

Change


 concommand.Add("changeteam", "chageteams", teamchange) 

to


 concommand.Add("changeteam", teamchange ) 

That seems to work but, it won’t respawn them back to original places, and give them there loadout

EDIT: I made a spawn function to fix it, thanks for the help everyone :slight_smile: greatly appreciated

I’m really sorry for making so many errors on your post I don’t know what I was doing. Here’s a tested script.
[LUA]function teamchange()
for _,v in pairs(team.GetPlayers(1)) do
v:SetTeam(2)
v:Spawn()
end
for _,v in pairs(team.GetPlayers(3)) do
v:SetTeam(2)
v:Spawn()
end
end
concommand.Add(“changeteam”, teamchange)[/LUA]