generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Can anyone help me get the general idea..

Previous Thread :: Next Thread 
DarkheartSkillz is not online. DarkheartSkillz
Joined: 30 Sep 2011
Total Posts: 5125
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
DarkheartSkillz is not online. DarkheartSkillz
Joined: 30 Sep 2011
Total Posts: 5125
06 Aug 2014 03:13 PM
Bump
Report Abuse
cntkillme is not online. 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 is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
06 Aug 2014 03:15 PM
amount of players is even*
Report Abuse
cntkillme is not online. 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
DarkheartSkillz is not online. DarkheartSkillz
Joined: 30 Sep 2011
Total Posts: 5125
06 Aug 2014 03:17 PM
I don't know how to randomly select a player
Report Abuse
cntkillme is not online. 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
DarkheartSkillz is not online. DarkheartSkillz
Joined: 30 Sep 2011
Total Posts: 5125
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
DarkheartSkillz is not online. DarkheartSkillz
Joined: 30 Sep 2011
Total Posts: 5125
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 is not online. 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
DarkheartSkillz is not online. DarkheartSkillz
Joined: 30 Sep 2011
Total Posts: 5125
06 Aug 2014 03:39 PM
How do I define teamA and teamB?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
06 Aug 2014 03:40 PM
As a BrickColor (Game.Teams.Whatever.TeamColor)
Report Abuse
DarkheartSkillz is not online. DarkheartSkillz
Joined: 30 Sep 2011
Total Posts: 5125
06 Aug 2014 03:51 PM
Utterly confused. I'm not used to parameters.
Report Abuse
cntkillme is not online. 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
DarkheartSkillz is not online. DarkheartSkillz
Joined: 30 Sep 2011
Total Posts: 5125
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 is not online. 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
DarkheartSkillz is not online. DarkheartSkillz
Joined: 30 Sep 2011
Total Posts: 5125
06 Aug 2014 04:05 PM
Works! :D
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image