Forts: How To Make Truly Random Forts Placement

Forts maps do not assign random fort positions, but instead give a fort order, which can be defined as a variable in the map script. This guide will show how to make that code variable.

 

Introduction
When you play a lobby in forts in matches larger than a 1v1, forts assigns players to an order of bases. However this is not truly random. It is very easy to get the same fort over and over again if you play several matches in a row.

This guide will teach you how to drastically lower the chances of this happening in the future.

How to define Fort Order
In order to define a Fort order, after you create your map, go to the windows file directory and find your map name like in the image below:

Then open the highlighted file in a text editor. It should be something like mapname.lua

The syntax to define a Fort order is:

FortOrder =
    {
        { 1, 2, 3, 4 }, -- Team 1
        { 1, 2, 3, 4 }, -- Team 2
    }
the numbers in the brackets are the assigned fort ID you get when making the map that shows up next to the fort. This shows the fort order for a 4v4 map. You can add or subtract to this depending on how many forts are on each team.

Make sure that you use this exact syntax otherwise the code will not work.

How to randomize fort order.
Currently, there is only one good way to randomize fort orders. That is to go through all the permutations of fort assignments. Then get a random number from a range of the possible permutations, and then create a list of if and else if statements for the different permutations.

It’s recommended to keep T1 and T2 orders synchronized otherwise it will get even more messy than it already is.

An example for a 4v4 map is given below (feel free to just copy/paste this for ease of use:

i = 0
if GetRandomInteger then
    i = GetRandomInteger(0, 22)
end
    
if i == 0 then
    FortOrder =
    {
        { 1, 2, 3, 4 },
        { 1, 2, 3, 4 },
    }
elseif i == 1 then
    FortOrder =
        {
            { 1, 3, 2, 4 },
            { 1, 3, 2, 4 },
        }
elseif i == 2 then
    FortOrder =
        {
            { 1, 3, 4, 2 },
            { 1, 3, 4, 2 },
        }
elseif i == 3 then 
    FortOrder =
        {
            { 1, 4, 3, 2 },
            { 1, 4, 3, 2 },
        }
elseif i ==4 then  
    FortOrder =
        {
            { 1, 4, 2, 3 },
            { 1, 4, 2, 3 },
        }
elseif i ==5 then
    FortOrder =
        {
            { 1, 2, 4, 3 },
            { 1, 2, 4, 3 },
        }
elseif i ==5 then
    FortOrder =
        {
            { 1, 2, 4, 3 },
            { 1, 2, 4, 3 },
        }
elseif i ==6 then
    FortOrder =
        {
            { 2, 1, 3, 4 },
            { 2, 1, 3, 4 },
        }
elseif i ==7 then
    FortOrder =
        {
            { 2, 1, 4, 3 },
            { 2, 1, 4, 3 },
        }
elseif i ==8 then
    FortOrder =
        {
            { 2, 3, 1, 4 },
            { 2, 3, 1, 4 },
        }
elseif i ==9 then
    FortOrder =
        {
            { 2, 3, 4, 1 },
            { 2, 3, 4, 1 },
        }
elseif i ==10 then
    FortOrder =
        {
            { 2, 4, 3, 1 },
            { 2, 4, 3, 1 },
        }
elseif i ==11 then
    FortOrder =
        {
            { 2, 4, 1, 3 },
            { 2, 4, 1, 3 },
        }
elseif i ==12 then
    FortOrder =
        {
            { 3, 1, 2, 4 },
            { 3, 1, 2, 4 },
        }
elseif i ==13 then
    FortOrder =
        {
            { 3, 1, 4, 2 },
            { 3, 1, 4, 2 },
        }
elseif i ==14 then
    FortOrder =
        {
            { 3, 2, 4, 1 },
            { 3, 2, 4, 1 },
        }
elseif i ==15 then
    FortOrder =
        {
            { 3, 4, 1, 2 },
            { 3, 4, 1, 2 },
        }
elseif i ==16 then
    FortOrder =
        {
            { 3, 4, 2, 1 },
            { 3, 4, 2, 1 },
        }
elseif i ==17 then
    FortOrder =
        {
            { 4, 1, 2, 3 },
            { 4, 1, 2, 3 },
        }
elseif i ==18 then
    FortOrder =
        {
            { 4, 1, 3, 2 },
            { 4, 1, 3, 2 },
        }
elseif i ==19 then
    FortOrder =
        {
            { 4, 2, 3, 1 },
            { 4, 2, 3, 1 },
        }
elseif i ==20 then
    FortOrder =
        {
            { 4, 2, 1, 3 },
            { 4, 2, 1, 3 },
        }
elseif i ==21 then
    FortOrder =
        {
            { 4, 3, 1, 2 },
            { 4, 3, 1, 2 },
        }
elseif i ==22 then
    FortOrder =
        {
            { 4, 3, 2, 1 },
            { 4, 3, 2, 1 },
        }
end
This can be modified for any number of forts on each team, and they don’t have to be even. Keep in mind though that the permutations grow exponentially the more forts you have.

Possible way of condensing the code
Right now, the method above is the only possible way to randomize fort order, because FortOrder can only take integer values.

However, if at some point FordOrder can take integer variables, code could be easily condensed into something like this:

x = 0
y = 0 
a = 0 
b = 0

if GetRandomInteger then
    x = GetRandomInteger(1, 4)
    y = GetRandomInteger(1, 4)
    a = GetRandomInteger(1, 4)
    b = GetRandomInteger(1, 4)
end
if x == y or x == a or x == b or y == a or y == b or a == b then 
    y = GetRandomInteger(1, 4)
    y = GetRandomInteger(1, 4)
    a = GetRandomInteger(1, 4)
    b = GetRandomInteger(1, 4)
end
FortOrder = 
{
      {x, y, a, b},
      {x, y, a, b},
 }

By mnmwert

Related Posts:

About Robins Chew

I'm Robins, who love to play the mobile games from Google Play, I will share the gift codes in this website, if you also love mobile games, come play with me. Besides, I will also play some video games relresed from Steam.

Leave a Comment