Basics
Function of Script
With this script you will be able to block any units from being produced or called in. This script has an optional built-in feature that blocks all vehicle units without the need for listing them all manually. In a basic level this script is an improved version of my previous tutorial: Infantry Only. The example scripts comes with the following settings:
Code
-- List of units to block
_block_list = {
_zis_3_at_gun_squad, _t_70_squad,
_conscript_squad, _katyusha_squad,
}
-- Method of blocking units.
-- ITEM_REMOVED = The production icon/ability icon of the unit is removed.
-- ITEM_LOCKED = The production icon/ability icon of the unit is visible but locked
_block_method = ITEM_LOCKED
-- Block all vehicles by default, true/false
_disable_vehicles = true
-- Free text, displayed as a reason if the blocking method is ITEM_LOCKED
_block_message = "You are not allowed to use this unit."
Tools Needed
In this tutorial you will have to edit simple text files. To do this, you will need a basic text editor. Microsoft Notepad is suitable for this job and you already have it. For those looking to use a better more advanced tool, you can look towards getting Notepad++. You can download this for free at notepad-plus-plus.org
How to enable Lua syntax highlight for .scar files in Notepad++
How to enable Lua syntax highlight for .scar files in Notepad++
- Click "Settings" in the main tool bar and select "Style Configurator"
- Select Lua from the list in the left side of the window. (You can press the key L in your keyboard to quickly jump where the "Lua" is)
- Add "scar" without quotation marks to the text field below label "User ext.:"
- Make sure to leave one space between multiple extensions. By default this textbox should be empty.
- Close the window, restart Notepad++. You should now have Lua syntax highlighting enabled in your _ID.scar file.
Important Note
There is one vital thing that you should all take note of and understand before venturing 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 have noticed that there are a 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 [b]_ID.scar. The file we are concerned with in this tutorial is the _ID.scar file.
_ID.scar File
Firstly, what is this file, and why are we so interested in it? _ID.scar contains the list of SCAR markers, entity groups, or otherwise known as egroups, and squad groups, further more noted as 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 bit more advanced implementation.
Adding the Code
Open _ID.scar in Notepad / Notepad++. It should look something like this:
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:
Add the following code above last occurring "end"-word in the file:
Alternatively you can also obtain this code from pastebin.com.
The result 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:
Add the following code above last occurring "end"-word in the file:
Code
-- List of available units, stored as variables for easy access
_grenadier_squad = {squad = "grenadier_squad_mp"}
_assault_grenadier_squad = {ability = "assault_grenadiers"}
_hmg42_team = {squad = "mg42_heavy_machine_gun_squad_mp"}
_mortar_team = {squad = "mortar_team_81mm_mp"}
_officer_squad = {ability = "assault_field_officer"}
_osttruppen_squad = {ability = "ostruppen"}
_panzer_grenadier_squad = {squad = "panzer_grenadier_squad_mp"}
_urban_assault_panzer_grenadier_squad = {ability = "urban_assault_grenadiers"}
_pioneer_squad = {squad = "pioneer_squad_mp"}
_sniper_squad = {squad = "sniper_squad_mp"}
_stormtrooper_squad = {ability = "stormtroopers"}
_pak40_at_gun_squad = {squad = "pak40_75mm_at_gun_squad_mp", isvehicle = true}
_pak43_at_gun_squad = {ability = "pak_43_emplacement_unlock", entity = "pak43_88mm_at_gun_mp", isvehicle = true}
_brummbar_squad = {squad = "brummbar_squad_mp", isvehicle = true}
_elefant_squad = {ability = "elefant_unlock", isvehicle = true}
_mechanized_250_halftrack_grenadiers_squad = {ability = "mechanized_grenadier_group", isvehicle = true}
_mortar_250_halftrack_squad = {ability = "mortar_halftrack", isvehicle = true}
_sdkfz_251_halftrack_squad = {squad = "sdkfz_251_halftrack_squad_mp", isvehicle = true}
_le_fh18_howitzer_squad = {ability = "howitzer_105mm_emplacement_unlock", entity = "howitzer_105mm_le_fh18_mp", isvehicle = true}
_opel_blitz_supply_truck_squad = {ability = "supply_truck", isvehicle = true}
_ostwind_squad = {squad = "ostwind_squad_mp", isvehicle = true}
_panther_squad = {squad = "panther_squad_mp", isvehicle = true}
_panzer_iv_squad = {squad = "panzer_iv_squad_mp", isvehicle = true}
_panzer_iv_command_squad = {ability = "armor_commander", isvehicle = true}
_panzerwerfer_squad = {squad = "panzerwerfer_squad_mp", isvehicle = true}
_scoutcar_222_squad = {squad = "scoutcar_sdkfz222_mp", isvehicle = true}
_stug_3_e_squad = {ability = "stug_iii_e", isvehicle = true}
_stug_3_squad = {squad = "stug_iii_squad_mp", isvehicle = true}
_tiger_ace_squad = {ability = "tiger_tank_ace", isvehicle = true}
_tiger_squad = {ability = "tiger_tank", isvehicle = true}
_puma_squad = {ability = "puma_dispatch", isvehicle = true}
_combat_engineer_squad = {squad = "combat_engineer_squad_mp"}
_conscript_squad = {squad = "conscript_squad_mp"}
_dshk_38_hmg_squad = {ability = "dshk_mp"}
_maxim_hmg_squad = {squad = "m1910_maxim_heavy_machine_gun_squad_mp"}
_mortar_squad = {squad = "pm-82_41_mortar_squad_mp"}
_mortar_120mm_squad = {ability = "cmd_120mm_mortar_crew"}
_partisan_squad = {ability = "partisans_commander_anti_infantry"}
_partisan_at_squad = {ability = "partisans_commander_anti_vehicle"}
_sniper_squad = {squad = "sniper_team_mp"}
_guards_troops_squad = {ability = "cmd_guard_troops"}
_penal_battalion_squad = {squad = "penal_battalion_mp"}
_shock_troop_squad = {ability = "cmd_shock_troops"}
_is_2_squad = {ability = "cmd_is2_heavy_tank", isvehicle = true}
_isu_152_squad = {ability = "cmd_isu-152", isvehicle = true}
_katyusha_squad = {squad = "katyusha_bm-13n_squad_mp", isvehicle = true}
_kv_1_squad = {ability = "cmd_kv-1_unlock", isvehicle = true}
_kv_2_squad = {ability = "kv-2", isvehicle = true}
_kv_8_squad = {ability = "cmd_kv-8_unlock_mp", isvehicle = true}
_m3a1_squad = {squad = "m3a1_scout_car_squad_mp", isvehicle = true}
_m5_squad = {squad = "m5_halftrack_squad_mp", isvehicle = true}
_howitzer_203mm_squad = {ability = "b4_203mm_howitzer", entity = "artillery_203mm_b4", isvehicle = true}
_howitzer_152mm_squad = {ability = "cmd_ml_20", entity = "m1937_152mm_ml_20_artillery_mp", isvehicle = true}
_zis_3_at_gun_squad = {squad = "m1942_zis-3_76mm_at_gun_squad_mp", isvehicle = true}
_k_45mm_at_gun_squad = {ability = "m-42_at_gun", isvehicle = true}
_su_76_squad = {squad = "su-76m_mp", isvehicle = true}
_su_85_squad = {squad = "su-85_mp", isvehicle = true}
_t_34_squad = {squad = "t_34_76_squad_mp", isvehicle = true}
_t_34_85_squad = {ability = "cmd_t34_85_medium_tank", isvehicle = true}
_t_34_85_one_squad = {ability = "cmd_advanced_t34_85_medium_tank", isvehicle = true}
_t_70_squad = {squad = "t-70m_mp", isvehicle = true}
_m4c_sherman_squad = {ability = "sherman_soviet_dispatch", isvehicle = true}
-- List of units in a table
_unitList = {
_panzer_iv_command_squad,_dshk_38_hmg_squad,_conscript_squad,_sdkfz_251_halftrack_squad,_stormtrooper_squad,_tiger_ace_squad,_t_70_squad,
_partisan_at_squad,_tiger_squad,_t_34_85_squad,_kv_2_squad,_mortar_squad,_penal_battalion_squad,_le_fh18_howitzer_squad,_su_76_squad,_sniper_squad,
_m5_squad,_zis_3_at_gun_squad,_isu_152_squad,_is_2_squad,_mortar_team,_pak43_at_gun_squad,_howitzer_203mm_squad,_osttruppen_squad,_maxim_hmg_squad,
_k_45mm_at_gun_squad,_grenadier_squad,_brummbar_squad,_combat_engineer_squad,_panzer_grenadier_squad,_assault_grenadier_squad,_officer_squad,
_howitzer_152mm_squad,_t_34_squad,_katyusha_squad,_kv_1_squad,_scoutcar_222_squad,_kv_8_squad,_pioneer_squad,_su_85_squad,_pak40_at_gun_squad,
_t_34_85_one_squad,_elefant_squad,_partisan_squad,_guards_troops_squad,_mortar_120mm_squad,_m3a1_squad,_stug_3_squad,_stug_3_e_squad,_panzerwerfer_squad,
_panzer_iv_squad,_shock_troop_squad,_ostwind_squad,_opel_blitz_supply_truck_squad,_mortar_250_halftrack_squad,_mechanized_250_halftrack_grenadiers_squad,
_hmg42_team,_panther_squad,_urban_assault_panzer_grenadier_squad,
}
-- List of units to block
_block_list = {
_zis_3_at_gun_squad, _t_70_squad,
_conscript_squad, _katyusha_squad,
}
-- Method of blocking units.
-- ITEM_REMOVED = The production icon/ability icon of the unit is removed.
-- ITEM_LOCKED = The production icon/ability icon of the unit is visible but locked
_block_method = ITEM_LOCKED
-- Block all vehicles by default, true/false
_disable_vehicles = true
-- Free text, displayed as a reason if the blocking method is ITEM_LOCKED
_block_message = "You are not allowed to use this unit."
-- String converstion to a loc string
local _loc = LOC(_block_message)
_loc[1] = _block_message
_block_message = _loc
-- Helper function for applying unit restrictions
local _blockItem = function(item)
for i = 1, World_GetPlayerCount() do
local player = World_GetPlayerAt(i)
if item.squad then
Player_SetSquadProductionAvailabilityInternal(player, BP_GetSquadBlueprint(item.squad), _block_method, _block_message)
end
if item.entity then
Player_SetEntityProductionAvailabilityInternal(player, BP_GetEntityBlueprint(item.entity), _block_method, _block_message)
end
if item.ability then
Player_SetAbilityAvailabilityInternal(player, BP_GetAbilityBlueprint(item.ability), _block_method, _block_message)
end
end
end
-- Apply unit restrictions based on the table _block_list
for key, item in ipairs(_block_list) do
_blockItem(item)
end
-- Block all vehicles if _disable_vehicles set to true
if _disable_vehicles then
for key, item in pairs(_unitList) do
if item.isvehicle then
_blockItem(item)
end
end
end
Alternatively you can also obtain this code from pastebin.com.
The result should look something like this:
Code
function OnInitID()
-- [[ Markers ]]
-- [[ Squad Groups ]]
-- [[ Entity Groups ]]
-- List of available units, stored as variables for easy access
_grenadier_squad = {squad = "grenadier_squad_mp"}
_assault_grenadier_squad = {ability = "assault_grenadiers"}
_hmg42_team = {squad = "mg42_heavy_machine_gun_squad_mp"}
_mortar_team = {squad = "mortar_team_81mm_mp"}
_officer_squad = {ability = "assault_field_officer"}
_osttruppen_squad = {ability = "ostruppen"}
_panzer_grenadier_squad = {squad = "panzer_grenadier_squad_mp"}
_urban_assault_panzer_grenadier_squad = {ability = "urban_assault_grenadiers"}
_pioneer_squad = {squad = "pioneer_squad_mp"}
_sniper_squad = {squad = "sniper_squad_mp"}
_stormtrooper_squad = {ability = "stormtroopers"}
_pak40_at_gun_squad = {squad = "pak40_75mm_at_gun_squad_mp", isvehicle = true}
_pak43_at_gun_squad = {ability = "pak_43_emplacement_unlock", entity = "pak43_88mm_at_gun_mp", isvehicle = true}
_brummbar_squad = {squad = "brummbar_squad_mp", isvehicle = true}
_elefant_squad = {ability = "elefant_unlock", isvehicle = true}
_mechanized_250_halftrack_grenadiers_squad = {ability = "mechanized_grenadier_group", isvehicle = true}
_mortar_250_halftrack_squad = {ability = "mortar_halftrack", isvehicle = true}
_sdkfz_251_halftrack_squad = {squad = "sdkfz_251_halftrack_squad_mp", isvehicle = true}
_le_fh18_howitzer_squad = {ability = "howitzer_105mm_emplacement_unlock", entity = "howitzer_105mm_le_fh18_mp", isvehicle = true}
_opel_blitz_supply_truck_squad = {ability = "supply_truck", isvehicle = true}
_ostwind_squad = {squad = "ostwind_squad_mp", isvehicle = true}
_panther_squad = {squad = "panther_squad_mp", isvehicle = true}
_panzer_iv_squad = {squad = "panzer_iv_squad_mp", isvehicle = true}
_panzer_iv_command_squad = {ability = "armor_commander", isvehicle = true}
_panzerwerfer_squad = {squad = "panzerwerfer_squad_mp", isvehicle = true}
_scoutcar_222_squad = {squad = "scoutcar_sdkfz222_mp", isvehicle = true}
_stug_3_e_squad = {ability = "stug_iii_e", isvehicle = true}
_stug_3_squad = {squad = "stug_iii_squad_mp", isvehicle = true}
_tiger_ace_squad = {ability = "tiger_tank_ace", isvehicle = true}
_tiger_squad = {ability = "tiger_tank", isvehicle = true}
_puma_squad = {ability = "puma_dispatch", isvehicle = true}
_combat_engineer_squad = {squad = "combat_engineer_squad_mp"}
_conscript_squad = {squad = "conscript_squad_mp"}
_dshk_38_hmg_squad = {ability = "dshk_mp"}
_maxim_hmg_squad = {squad = "m1910_maxim_heavy_machine_gun_squad_mp"}
_mortar_squad = {squad = "pm-82_41_mortar_squad_mp"}
_mortar_120mm_squad = {ability = "cmd_120mm_mortar_crew"}
_partisan_squad = {ability = "partisans_commander_anti_infantry"}
_partisan_at_squad = {ability = "partisans_commander_anti_vehicle"}
_sniper_squad = {squad = "sniper_team_mp"}
_guards_troops_squad = {ability = "cmd_guard_troops"}
_penal_battalion_squad = {squad = "penal_battalion_mp"}
_shock_troop_squad = {ability = "cmd_shock_troops"}
_is_2_squad = {ability = "cmd_is2_heavy_tank", isvehicle = true}
_isu_152_squad = {ability = "cmd_isu-152", isvehicle = true}
_katyusha_squad = {squad = "katyusha_bm-13n_squad_mp", isvehicle = true}
_kv_1_squad = {ability = "cmd_kv-1_unlock", isvehicle = true}
_kv_2_squad = {ability = "kv-2", isvehicle = true}
_kv_8_squad = {ability = "cmd_kv-8_unlock_mp", isvehicle = true}
_m3a1_squad = {squad = "m3a1_scout_car_squad_mp", isvehicle = true}
_m5_squad = {squad = "m5_halftrack_squad_mp", isvehicle = true}
_howitzer_203mm_squad = {ability = "b4_203mm_howitzer", entity = "artillery_203mm_b4", isvehicle = true}
_howitzer_152mm_squad = {ability = "cmd_ml_20", entity = "m1937_152mm_ml_20_artillery_mp", isvehicle = true}
_zis_3_at_gun_squad = {squad = "m1942_zis-3_76mm_at_gun_squad_mp", isvehicle = true}
_k_45mm_at_gun_squad = {ability = "m-42_at_gun", isvehicle = true}
_su_76_squad = {squad = "su-76m_mp", isvehicle = true}
_su_85_squad = {squad = "su-85_mp", isvehicle = true}
_t_34_squad = {squad = "t_34_76_squad_mp", isvehicle = true}
_t_34_85_squad = {ability = "cmd_t34_85_medium_tank", isvehicle = true}
_t_34_85_one_squad = {ability = "cmd_advanced_t34_85_medium_tank", isvehicle = true}
_t_70_squad = {squad = "t-70m_mp", isvehicle = true}
_m4c_sherman_squad = {ability = "sherman_soviet_dispatch", isvehicle = true}
-- List of units in a table
_unitList = {
_panzer_iv_command_squad,_dshk_38_hmg_squad,_conscript_squad,_sdkfz_251_halftrack_squad,_stormtrooper_squad,_tiger_ace_squad,_t_70_squad,
_partisan_at_squad,_tiger_squad,_t_34_85_squad,_kv_2_squad,_mortar_squad,_penal_battalion_squad,_le_fh18_howitzer_squad,_su_76_squad,_sniper_squad,
_m5_squad,_zis_3_at_gun_squad,_isu_152_squad,_is_2_squad,_mortar_team,_pak43_at_gun_squad,_howitzer_203mm_squad,_osttruppen_squad,_maxim_hmg_squad,
_k_45mm_at_gun_squad,_grenadier_squad,_brummbar_squad,_combat_engineer_squad,_panzer_grenadier_squad,_assault_grenadier_squad,_officer_squad,
_howitzer_152mm_squad,_t_34_squad,_katyusha_squad,_kv_1_squad,_scoutcar_222_squad,_kv_8_squad,_pioneer_squad,_su_85_squad,_pak40_at_gun_squad,
_t_34_85_one_squad,_elefant_squad,_partisan_squad,_guards_troops_squad,_mortar_120mm_squad,_m3a1_squad,_stug_3_squad,_stug_3_e_squad,_panzerwerfer_squad,
_panzer_iv_squad,_shock_troop_squad,_ostwind_squad,_opel_blitz_supply_truck_squad,_mortar_250_halftrack_squad,_mechanized_250_halftrack_grenadiers_squad,
_hmg42_team,_panther_squad,_urban_assault_panzer_grenadier_squad,
}
-- List of units to block
_block_list = {
_zis_3_at_gun_squad, _t_70_squad,
_conscript_squad, _katyusha_squad,
}
-- Method of blocking units.
-- ITEM_REMOVED = The production icon/ability icon of the unit is removed.
-- ITEM_LOCKED = The production icon/ability icon of the unit is visible but locked
_block_method = ITEM_LOCKED
-- Block all vehicles by default, true/false
_disable_vehicles = true
-- Free text, displayed as a reason if the blocking method is ITEM_LOCKED
_block_message = "You are not allowed to use this unit."
-- String converstion to a loc string
local _loc = LOC(_block_message)
_loc[1] = _block_message
_block_message = _loc
-- Helper function for applying unit restrictions
local _blockItem = function(item)
for i = 1, World_GetPlayerCount() do
local player = World_GetPlayerAt(i)
if item.squad then
Player_SetSquadProductionAvailabilityInternal(player, BP_GetSquadBlueprint(item.squad), _block_method, _block_message)
end
if item.entity then
Player_SetEntityProductionAvailabilityInternal(player, BP_GetEntityBlueprint(item.entity), _block_method, _block_message)
end
if item.ability then
Player_SetAbilityAvailabilityInternal(player, BP_GetAbilityBlueprint(item.ability), _block_method, _block_message)
end
end
end
-- Apply unit restrictions based on the table _block_list
for key, item in ipairs(_block_list) do
_blockItem(item)
end
-- Block all vehicles if _disable_vehicles set to true
if _disable_vehicles then
for key, item in pairs(_unitList) do
if item.isvehicle then
_blockItem(item)
end
end
end
end
Configuration
The default configuration for this script will look like this:
Conscripts are not allowed to use.
Code
-- List of units to block
_block_list = {
_zis_3_at_gun_squad, _t_70_squad,
_conscript_squad, _katyusha_squad,
}
-- Method of blocking units.
-- ITEM_REMOVED = The production icon/ability icon of the unit is removed.
-- ITEM_LOCKED = The production icon/ability icon of the unit is visible but locked
_block_method = ITEM_LOCKED
-- Block all vehicles by default, true/false
_disable_vehicles = true
-- Free text, displayed as a reason if the blocking method is ITEM_LOCKED
_block_message = "You are not allowed to use this unit."
- _block_list is a list of units to block, picked from the long list above it.
- _block_method is the way how blocking the usage of a unit is handled. Setting it to ITEM_LOCKED will result the unit icon being visible but disabled. Setting it to ITEM_REMOVED will result the icon to be completely removed.
- _disable_vehicles does what it says. Set it to true to disable all vehicles. If you'd like to mark mortars as vehicles and don't want to add them to the _block_list, you can mark them in the unit list with attribute "isvehicle = true". See other vehicles in the list for examples.
- _block_message is the text which is displayed above the blocked unit.
Conscripts are not allowed to use.
Concluding Notes
With this custom map script you are able to restrict usage of the units in 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!