• Rounds
    11 replies, posted
In my gamemode im designing im trying to get it so when there is no one on team 2 it will detect and move everyone to team 3. Then from there it needs to randomly pick two people from team two and move them to team 1 and then the rest of them go to team 2. I have this so far... clearly its not complete! [lua] function GM:Think() if team:NumPlayers( 2 ) == 0 then for ply in team.GetPlayers(1) do ply:SetTeam( 3 ) end PlayerTable={} i = 0 for ply in team.GetPlayers(3) do i = i + 1 PlayerTable[i]=ply:GetName() end end end [/lua] My questions are these: 1) Any suggestions on how to do this teams thing? 2) How can I make it so when I player touches a certain trigger in a map that it will switch them to a different team?
You need to read more about loops: for ply in team.GetPlayers(1) do should be for k, ply in pairs(team.GetPlayers(1)) do Same with the other line, short explaintion: you need to use pairs becuse for wants a interiator, i dont want to explain what that does but team.GetPlayers returns a table, pairs gives the for something that it can use And you need to use k, ply becuse of: if i say k, v then k would be key, the index of the table v would be value, the value
I highly suggest not doing that on Think. Just find the place where you move the player off of team 2, and do the same check there.
Think works just fine
Think would work, it would be easier to work with at least.
When I run this code: [lua] for k, ply in team.GetPlayers(1) do ply:PrintMessage( HUD_PRINTCENTER, "All the Minnows have been eliminated!" ) ply:SetTeam( 3 ) end [/lua] I get that an error saying that it attemped to call a table value...
[QUOTE=Tobba;22447716]You need to read more about loops: for ply in team.GetPlayers(1) do should be for k, ply in pairs(team.GetPlayers(1)) do [/QUOTE]
Oh yah I totally misread that. Haha my bad [editline]11:59PM[/editline] Ummm.... lua/includes/extensions/table.lua:177: bad argument #2 to 'random' (interval is empty) I don't see what is wrong with this code... [lua] ply1 = table.Random(player.GetAll()) [/lua]
I don't think it accepted player.GetAll, I think it has to be a table you defined earlier on.
It does accept player.GetAll(), make sure there are people in the server before running that
Maybe he wasn't running multiplayer with bots? that's the best way to test it.
Yeah I just tried running the server with no people in it. So should I have it do a check to see if the number of players in the server is greater than 3-5 before starting the round?
Sorry, you need to Log In to post a reply to this thread.