|
| 06 Aug 2014 02:51 PM |
On how to make a randomize team script?
So, there is two teams which I can define with a variable
Then it checks how many players are in the game If it's even, then randomize evenly between the two teams If its uneven, take out me personally and then randomize everyone else evenly? |
|
|
| Report Abuse |
|
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 06 Aug 2014 03:14 PM |
-You would make a function that accepts 2 arguments (the 2 teams) [if you want you can even it out between all teams]
-If you're in the game, make sure the amount of players is event, if not, remove yourself from the table (which you will use the loop)
-You would loop through players and for each iteration, get a random player and set his/her team as team 1 or team 2, depending if the key is odd or even. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 06 Aug 2014 03:15 PM |
| amount of players is even* |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 06 Aug 2014 03:15 PM |
| Also, for part 3, remove that random player so he won't be selected and cause any problems. |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2014 03:17 PM |
| I don't know how to randomly select a player |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 06 Aug 2014 03:19 PM |
When you have your players table (full of all the players, and if uneven, you excluded) you select a random number between 1 and the length of the table. Then you assign a variable to index the table with that key and remove the value also. Lua's table.remove function luckily returns the value when removing it from the table so you can do all that in 1 line. |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2014 03:27 PM |
I'm stuck
players = game.Players:GetPlayers() for i,v in pairs(game.Players:GetPlayers()) do if v%2 == 0 then for a = 1,#players do
end end end |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2014 03:29 PM |
t1 = game.Teams.Red.TeamColor t2 = game.Teams.Blue.TeamColor for i,v in pairs(game.Players:GetPlayers()) do if v%2 == 0 then v.TeamColor == t1
end end end |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 06 Aug 2014 03:36 PM |
I'll give you what I worked out: local balanceTeams = function(teamA, teamB) local players = Game.Players:GetPlayers(); if #players % 2 == 1 then --There is probably a more efficient way to do the code in this scope. for key = 1, #players do if players[key].Name == "DarkheartSkillz" then table.remove(players, key); break; end end end for key = 1, #players do local value = table.remove(players, math.random(#players)); value.TeamColor = key % 2 == 1 and teamA or teamB; end end; |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2014 03:39 PM |
| How do I define teamA and teamB? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 06 Aug 2014 03:40 PM |
| As a BrickColor (Game.Teams.Whatever.TeamColor) |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2014 03:51 PM |
| Utterly confused. I'm not used to parameters. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 06 Aug 2014 03:53 PM |
Just do:
balanceTeams(BrickColor.new("TeamColorHere"), BrickColor.new("TeamColorHere"))
|
|
|
| Report Abuse |
|
|
|
| 06 Aug 2014 03:57 PM |
local balanceTeams = function(teamA, teamB) local players = Game.Players:GetPlayers(); if #players % 2 == 1 then --There is probably a more efficient way to do the code in this scope. for key = 1, #players do if players[key].Name == "DarkheartSkillz" then table.remove(players, key); break; end end end
for key = 1, #players do local value = table.remove(players, math.random(#players)); value.TeamColor = key % 2 == 1 and teamA or teamB; end end; balanceTeams(BrickColor.new("Bright red"), BrickColor.new("Bright blue"))
?? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 06 Aug 2014 03:58 PM |
| Yeah, that should work if not post the output |
|
|
| Report Abuse |
|
|
| |
|