[Post has been deleted]

[Post has been deleted]___________

Usually, I utilize a weight system of choices. If a choice won, a portion of its weight will be removed and distributed to other maps’ weights. This creates more balance between all maps available. Or you can just completely remove it from the list for one round and re-add it afterwards.

I can also see that math.randomseed() was not used here. It would increase randomness, but does not solve the case of probability between maps.

To create this system, it requires a table and numbers.

1 Like

Ok, so I have a really good idea.

Here’s what it does

  • Choses the map based on the weight the map has
  • Decreases the chances after it is removed.

What you need

  • A weight value in each map
    • This is a IntValue
    • Called Weight
    • The higher the value is, the more common the map is!
  • That’s it!

The code

local weightedMaps = {} -- a table, this is EXTREMELY useful for iterating through objects.  :GetChildren() returns one of these.

-- Function to get the weight and put it in a table
local function getMaps(mapFolder, tableToAdd)
	for _, map in pairs(mapFolder:GetChildren()) do -- an extremely useful loop used for iteration, what I talked about earlier.
		local weightValue = map:WaitForChild("Weight")
		for i = 1, #weightValue.Value do -- another type of for loop, lets you repeat for a certain number of times "1" is the start, "#weightValue.Value" is where it ends.  However much you make the value called weight is how many times it gets added.
			table.insert(tableToAdd, map)
		end
	end
end

-- call the function!  you must do this or it won't work!
getMaps(mapFolder, weightedMaps)

...
-- Put it in the while loop!
local randomMapKey = math.random(1, #weightedMaps) -- This is the key!  When you do maps[math.random(1, #maps)] you are calling the key!
local randomMap = weightedMaps[randomMapKey] -- you are getting the map value!

-- check to see if there are more than # of those maps!
local tempTable = {}
for _, map in pairs(weightedMaps) do
	if map == randomMap then -- if statement checks if maps exist!
		table.insert(tempTable, map)
	end
end

-- checks if that map isn't getting completely removed from the selection!
if #tempTable > 1 then
	table.remove(weightedMaps, randomMapKey)
end
Side note

Some things you might need to know

  • Indent your code
    • Please do this! It makes the code much more readable.

And that’s it! If you have any questions feel free to ask me! :slight_smile:

3 Likes