Login

russian armor

How to: Infantry Only Mode in a Custom Map

highlight
Basics
In this tutorial you will learn how to add infantry only mode to your custom 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 for free.
Important Note
One thing you should notice and understand before going any further:
Every time you save your map in WorldBuilder, _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!
Map Files
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 .sgb file, which is the main file containing all the data of your map. There are also other files, such as .tga, .info, .options, and _ID.scar.
The one we are interested in this tutorial is _ID.scar.
_ID.scar file
Well, what is this file in particular and why are we so interested about it?
_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 a custom SCAR script with the map. In this tutorial we will use it for a very basic implementation.
Adding the Code
Open _ID.scar in notepad / notepad++. It should look something like this:
Code

function OnInitID()

-- [[ Markers ]]

-- [[ Squad Groups ]]

-- [[ Entity Groups ]]
end


Normally, when no Scar markers are placed nor squad/entity groups assigned (sgroups and egroups) _ID.scar will look exactly like this.

Let's get into adding code which prevents players from producing vehicles:

Add the following code above last occurring "end"-word in the file:
Code

local _vehicleAbilities = {
"mechanized_grenadier_group", "supply_truck", "tiger_tank", "mortar_halftrack", "elefant_unlock", "tiger_tank_ace", "stug_short_barrel", "stug_iii_e", "armor_commander",
"mechanized_assault_group", "cmd_kv-8_unlock_mp", "cmd_advanced_t34_85_medium_tank", "cmd_t34_85_medium_tank", "cmd_isu-152", "cmd_is2_heavy_tank", "cmd_kv-1_unlock", "kv-2",
}

local SBP_IsVehicle = function(sbp)
--Skip problematic squads (pak creates splats, panzer_iii causes an error due to not existing yet)
local _skip_sbp = {
[1] = {
name = "pak43",
isVehcle = false,
},
[2] = {
name = "panzer_iii",
isVehcle = true,
},
}
local isVehcle = false
local pos = World_Pos(-512, -512, -512)
local skipSBP = false

for key, _sbp in ipairs(_skip_sbp) do
if string.find(BP_GetName(sbp), _sbp.name) then
isVehcle = _sbp.isVehcle
skipSBP = true
end
end

if not skipSBP then
local squad = Squad_CreateAndSpawnToward(sbp, World_GetPlayerAt(1), 1, pos, pos)
local entity = Squad_EntityAt(squad, 0)
if Entity_IsOfType(entity, "vehicle") and not Entity_IsOfType(entity, "team_weapon") then
isVehcle = true
else
isVehcle = false
end
Squad_Destroy(squad)
end
return isVehcle
end

for key, race in pairs(SBP) do
for key, sbp in pairs(race) do
if SBP_IsVehicle(sbp) then
for i = 1, World_GetPlayerCount() do
Player_SetSquadProductionAvailability(World_GetPlayerAt(i), sbp, ITEM_REMOVED)
end
end
end
end

for key, abp in ipairs(_vehicleAbilities) do
for i = 1, World_GetPlayerCount() do
Player_SetAbilityAvailability(World_GetPlayerAt(i), BP_GetAbilityBlueprint(abp), ITEM_REMOVED)
end
end


Alternatively you can also obtain this code from this url.

The result should look something like this:
Code


function OnInitID()

-- [[ Markers ]]

-- [[ Squad Groups ]]

-- [[ Entity Groups ]]

local _vehicleAbilities = {
"mechanized_grenadier_group", "supply_truck", "tiger_tank", "mortar_halftrack", "elefant_unlock", "tiger_tank_ace", "stug_short_barrel", "stug_iii_e", "armor_commander",
"mechanized_assault_group", "cmd_kv-8_unlock_mp", "cmd_advanced_t34_85_medium_tank", "cmd_t34_85_medium_tank", "cmd_isu-152", "cmd_is2_heavy_tank", "cmd_kv-1_unlock", "kv-2",
}

local SBP_IsVehicle = function(sbp)
--Skip problematic squads (pak creates splats, panzer_iii causes an error due to not existing yet)
local _skip_sbp = {
[1] = {
name = "pak43",
isVehcle = false,
},
[2] = {
name = "panzer_iii",
isVehcle = true,
},
}
local isVehcle = false
local pos = World_Pos(-512, -512, -512)
local skipSBP = false

for key, _sbp in ipairs(_skip_sbp) do
if string.find(BP_GetName(sbp), _sbp.name) then
isVehcle = _sbp.isVehcle
skipSBP = true
end
end

if not skipSBP then
local squad = Squad_CreateAndSpawnToward(sbp, World_GetPlayerAt(1), 1, pos, pos)
local entity = Squad_EntityAt(squad, 0)
if Entity_IsOfType(entity, "vehicle") and not Entity_IsOfType(entity, "team_weapon") then
isVehcle = true
else
isVehcle = false
end
Squad_Destroy(squad)
end
return isVehcle
end

for key, race in pairs(SBP) do
for key, sbp in pairs(race) do
if SBP_IsVehicle(sbp) then
for i = 1, World_GetPlayerCount() do
Player_SetSquadProductionAvailability(World_GetPlayerAt(i), sbp, ITEM_REMOVED)
end
end
end
end

for key, abp in ipairs(_vehicleAbilities) do
for i = 1, World_GetPlayerCount() do
Player_SetAbilityAvailability(World_GetPlayerAt(i), BP_GetAbilityBlueprint(abp), ITEM_REMOVED)
end
end
end

Alternatively you can also obtain this code from this url.
Testing the code
Save the _ID.scar and close the file. Go to 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 enjoy your map with the infantry only mode!
Conclusions
In this tutorial you learned how to add Infantry only mode to your custom map. I tried to spend some time to explain the important details instead of making this tutorial as short as humanly 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, feedback, or suggestions for future tutorials, please let me know in this thread!
Extra Note
If you find a vehicle that is not blocked, please let me know in the comments and I'll fix it!
1 user is browsing this thread: 1 guest