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 » Scripters
Home Search
 

Re: Team Scramble.

Previous Thread :: Next Thread 
sonicboy01 is not online. sonicboy01
Joined: 22 Nov 2008
Total Posts: 923
28 Nov 2015 04:13 PM
Hello, does anyone know any good methods to make a team scramble.
-I need it for a one time thing, so it goes through this other piece of code then scrambles the team, not every time a player joins.
-Team's even.

Any help would be gratefully appreciated.. :D
Report Abuse
wonderful72pike is not online. wonderful72pike
Joined: 13 Jul 2010
Total Posts: 7009
28 Nov 2015 04:15 PM
- Move all players to one team
- Run an auto-balance script that chooses random players to balance out the teams

It scrambles them and evens them out at the same time.
Report Abuse
Programmix is not online. Programmix
Joined: 07 Dec 2014
Total Posts: 99
28 Nov 2015 04:21 PM
This is the script my game uses to scramble teams. However, it uses a custom team system and some methods are not shown. The purpose of this code is to help you understand how the general system might work.

function TeamUtil:PickTeams()
local players = game.Players:GetPlayers()

local function shufflePlayers()
for i = 1, #players do
for p, player in pairs(players) do
local s = math.random(1, #players)

players[p] = players[s]
players[s] = player
end
end
end

local function getSmallestTeams()
local smallestTeams = {}

local teams = {}

for t, team in ipairs(self.Teams) do
teams[t] = team:MemberCount()
end

local lowestValue = math.min(unpack(teams))

for t, team in ipairs(self.Teams) do
if (team:MemberCount() == lowestValue) then
table.insert(smallestTeams, team)
end
end

return smallestTeams
end

local function getWeakestTeam()
local smallestTeams = getSmallestTeams()

return smallestTeams[math.random(1, #smallestTeams)]
end

shufflePlayers()

for _, player in ipairs(players) do
local team = getWeakestTeam()
team:AddMember(player)
end
end


/e tips_fedora | Developer | RBXDev Member
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
28 Nov 2015 04:24 PM
local function balanceTeams(players, teams, randomize)
for key = 1, #players do
local player = table.remove(players, randomize and math.random(#players) or 1);
player.TeamColor = teams[key % teams + 1].TeamColor;
end
end
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
28 Nov 2015 04:25 PM
key % #teams + 1 *
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
28 Nov 2015 04:35 PM
local function Scramble(players,teams)
local players,teams=players and players or game.Players:GetPlayers(),teams and teams or game.Teams:GetChildren()--Not really necessary, just for default arguments.
for i=1,#players do
table.remove(players,math.random(#players)).TeamColor=teams[i%#teams+1].TeamColor
end
end



That should work, call it like this:

Scramble()
Report Abuse
sonicboy01 is not online. sonicboy01
Joined: 22 Nov 2008
Total Posts: 923
28 Nov 2015 04:36 PM
Thanks :D
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
28 Nov 2015 04:37 PM
Lol cnt I just realized how methods were nearly the exact same. Kinda surprises me though because the last time we posted on a thread about randomizing teams you criticized this method because of how it goes 2 3 4 1 instead of 1 2 3 4. (Assuming 4 teams of course)
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
28 Nov 2015 04:47 PM
I know and I still think that it's gross but it's shorter so I did it anyways.
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
28 Nov 2015 04:49 PM
Makes sense
Report Abuse
GooeyChopsticks is not online. GooeyChopsticks
Joined: 25 Nov 2015
Total Posts: 632
28 Nov 2015 04:58 PM
@cnt

I am stealing your function, lol
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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