How-To: Custom Population Cap
In this tutorial you will learn how to set a custom population cap limit for your map. To do this, you will need a basic text editor. Microsoft Notepad is suitable for this job and you already have it. In case you'd like to consider getting a bit better tool for this, I would recommend using notepad++, which you can download from
notepad-plus-plus.org
One thing you should notice and understand before going any further:
Every time you save your map in WorldBuilder,
yourMapname_ID.scar will be re-generated by the WorldBuilder. This means you have to add the code
every time after saving the map if you wish to export the package. If you haven't saved your map yet, do it now!
Have you ever looked into your map folder? Perhaps you have and you know there are bunch of files laying around related to your map. For example the
yourMapname.sgb file, which is the main file containing all the data of your map. There are also other files, such as
yourMapname.tga,
yourMapname.info,
yourMapname.options, and
yourMapname_ID.scar.
The one we are interested in this tutorial is
yourMapname_ID.scar.
Well, what is this file in particular and why are we so interested about it?
yourMapname_ID.scar contains the list of
Scar markers, entity groups aka.
egroups, and squad groups aka.
sgroups from your map. This file is sort of a directory of items listed above. This file also gives us the ability to include custom SCAR script to the map. In this tutorial we will use it for a very basic implementation.
Adding code to edit population cap
Open
yourMapname_ID.scar in notepad / notepad++. It should look something like this:
function OnInitID()
-- [[ Markers ]]
-- [[ Squad Groups ]]
-- [[ Entity Groups ]]
end
Normally, when no Scar markers are placed nor squad/entity groups assigned (sgroups and egroups)
yourMapname_ID.scar will look exactly like this. Let's get into adding the custom population cap code!
Add the following code below the line
function OnInitID():
--Population cap override value
g_popCapOverRide = 200
for i = 1, World_GetPlayerCount() do
local player = World_GetPlayerAt(i)
Player_SetPopCapOverride(player, g_popCapOverRide)
end
The result should look something like this:
function OnInitID()
--Population cap override value
g_popCapOverRide = 200
for i = 1, World_GetPlayerCount() do
local player = World_GetPlayerAt(i)
Player_SetPopCapOverride(player, g_popCapOverRide)
end
-- [[ Markers ]]
-- [[ Squad Groups ]]
-- [[ Entity Groups ]]
end
Save the
yourMapname_ID.scar and close the file. Goto WorldBuilder and
DO NOT SAVE the map! You should have done that earlier. Just do
File -> Export Package, run the game, start a match with your map. You should now be able to see the population cap of 200 in your map.
Configuring the code to match your needs
I assume you are not happy with the population cap of 200. Perhaps you'd like to make it 300? Well, doing that is quite easy. I assume you already know how to do it if you spent some time reading the code you pasted into
yourMapname_ID.scar. You can edit the population cap by changing the value of
popCapOverRide, e.g. change it to 300 by doing following:
g_popCapOverRide = 300
Hit save, Export package, run your map and voilà!
In this tutorial you learned how to set a custom population cap for your map. I tried to spend some time to explain stuff a bit more briefly instead of making this tutorial as humanly short as possible. Hopefully this will give you a better understanding of what you did instead of just adding the code to a file and getting results without knowing why. If you have any additional questions, feed back, or suggestions for future tutorials, please let me know in this thread!