Random Mixed Neutrals on any map by Asheera

In this tutorial I’ll give you (the map makers especially) the possibility to place random mixed neutrals on any map. I’ll use the script for this.

First, add this piece of code to “scripts/common.lua” file (my creation):

– Function for handling the generation of neutrals function CreateCreeps(creeps, creep_groups) local additional_stacks = {} local x = 1

– go through all creeps for i, creep in creeps do

1. - get current creep properties

local creep_name = “Creep_” .. i

``` local groups = creep_groups[creep.group]
local group = groups[random(length(groups))+1]```
1. - create the monster on the map with the first stack

local stack = group

` CreateMonster(creep_name, stack.type, stack.min+random(stack.max-stack.min+1), creep.x, creep.y, creep.u or 0, creep.mood or 1, creep.courage or 2, creep.rot)`
1. - the additional stacks need to be created later, because it seems the engine doesn’t create the creeps immediately when CreateMonster is called
2. - this means that an object with the name ‘creep_name’ doesn’t exist yet, and AddObjectCreatures will thus fail
3. - so for now we just store the additional stack information in our temporary array

local numStacks = length(group)

``` for j = 2, numStacks do
stack = group[j]
additional_stacks[x] = {Name = creep_name, Id = stack.type, Num = stack.min+random(stack.max-stack.min+1)}
x = x + 1
end```

end

– pause the script so the engine can place the neutrals on the map sleep(2)

– add additional stacks (NOTE: only the first stack’s size is adjusted by the difficulty of the game, we need to do it here manually) x = GetDifficulty(); local y = 1.0 if x == 0 then y = 0.5 elseif x == 2 then y = 1.12 elseif x == 3 then y = 1.4 end

for i, v in additional_stacks do

` AddObjectCreatures(v.Name, v.Id, v.Num*y)`

end end

Now for each map you want random mixed neutrals, you’ll need to place a map script in it. And also, don’t place any neutrals on the map, the script will handle that for you.

The Map script should look like the following (this is only an example - the possibilities are endless)

– define neutrals NeutralGroups = { – group 1  = {

```  =
{
 = {min = 50, max = 60, type =   1}, -- Peasants
},
 =
{
 = {min = 20, max = 30, type =   2}, -- Conscripts
 = {min = 15, max = 35, type = 106}, -- Brutes
},```

},

– group 2  = {

```  =
{
 = {min =  7, max = 11, type =   3}, -- Archers
 = {min =  5, max =  8, type =   5}, -- Footmen
 = {min =  1, max =  2, type = 108}, -- Vindicators
},
 =
{
 = {min =  5, max =  7, type = 108}, -- Vindicators
 = {min = 13, max = 19, type = 106}, -- Brutes
},
 =
{
 = {min = 14, max = 20, type =  43}, -- Pixies
},
 =
{
 = {min =  7, max = 11, type = 146}, -- Wind Dancers
},
 =
{
 = {min =  7, max =  9, type =  93}, -- Shield Guards
 = {min =  2, max =  4, type = 167}, -- Harpooners
},
 =
{
 = {min = 16, max = 24, type =  57}, -- Gremlins
 = {min =  6, max =  9, type = 159}, -- Gremlin Saboteurs
},
 =
{
 = {min = 10, max = 15, type =  71}, -- Scouts
},
 =
{
 = {min =  3, max =  6, type =  73}, -- Blood Maidens
 = {min =  3, max =  3, type = 139}, -- Blood Sisters
},
 =
{
 = {min = 12, max = 17, type =  16}, -- Familiars
},
 =
{
 = {min = 17, max = 27, type =  29}, -- Skeletons
 = {min =  9, max = 12, type = 152}, -- Skeleton Warriors
},```

},

– group 3  = {

```  =
{
 = {min = 30, max = 50, type =  3}, -- Archers
},
 =
{
 = {min =  6, max = 20, type = 71}, -- Scouts
},```

},

– group 4  = {

```  =
{
 = {min = 30, max = 50, type = 4}, -- Marksmen
},```

},

– group 5  = {

```  =
{
 = {min = 20, max = 40, type = 5}, -- Footmen
},```

},

– group 6  = {

```  =
{
 = {min = 10, max = 15, type = 7}, -- Griffins
},```

},

– group 7  = {

```  =
{
 = {min = 10, max = 15, type = 8}, -- Imperial Griffins
},```

},

– group 8  = {

```  =
{
 = {min = 6, max = 9, type = 10}, -- Inquisitors
},```

},

– group 9  = {

```  =
{
 = {min = 4, max = 6, type = 11}, -- Cavaliers
},```

},

– group 10  = {

```  =
{
 = {min = 4, max = 6, type = 111}, -- Champions
},```

},

– group 11  = {

```  =
{
 = {min = 1, max = 3, type = 14}, -- ArchAngels
},```

}, } MapNeutrals = {  = {group = 1, x = 5, y = 76, rot = 90},  = {group = 2, x = 17, y = 83, rot = 0},  = {group = 3, x = 26, y = 91, rot = 0},  = {group = 4, x = 76, y = 90, rot = 90, u=1},  = {group = 1, x = 80, y = 99, rot = 0},  = {group = 1, x = 55, y = 1, rot = 270, u=1},  = {group = 3, x = 32, y = 44, rot = 0},  = {group = 8, x = 11, y = 37, rot = 180},  = {group = 5, x = 4, y = 82, rot = 90, u=1}, }

– place neutrals on the map CreateCreeps(MapNeutrals, NeutralGroups)

The MapNeutrals table holds the neutral “objects” on the map. You have to specify the position (x, y), if it is underground (u=1 means it’s underground) and the group of the neutrals. The group is a look up in the NeutralGroups table. For example, we see that group 1 spawns two possible neutrals (chosen randomly with equal chance at the start of the map):

1. 50-60 Peasants not mixed with anything 2. 20-30 Conscripts AND 15-35 Brutes mixed neutral stack

The same for the other groups (group 2 is an interesting one, it has a lot of possible “choices” at the start of the map to choose from - some mixed, some not)

(yes, type is the creature ID)

NOTE: it takes some time to generate the neutrals at the start of the map (if there are a lot) - please be patient and wait until you can enter the town - that’s a sign that the neutrals have been successfully added

I hope Map Makers will like to create maps with mixed neutrals from now on (no more Garrisons mixed neutrals only, etc) 