How-To: Abandoned vehicles in a custom map
In this tutorial you will learn how to add vehicle of your choice as abandoned to 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.
<yourmapname>_ID.scar file
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.
To begin with, place a vehicle of your choice to your map. For example, you could use panther, which is located in
sbps/races/german/vehicles/panther_squad/
Select it and Press
Control + U to create a new squad group. Alternatively you can goto "
Groups" and select "
Create Squad Group".
Give the new squad group a name. I would recommend using "
sg_" prefix for squad groups. In this case you could name the panther squad group as "
sg_panther". Click OK and save the map.
Adding code to apply vehicle abandon actions
Open
<yourmapname>_ID.scar in notepad / notepad++. It should look something like this (notice the "sg_panther" squad group appearing in the list):
function OnInitID()
-- [[ Markers ]]
-- [[ Squad Groups ]]
sg_panther = SGroup_CreateIfNotFound("sg_panther")
-- [[ 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.
However, you should be able to see the panther squad group definition below "-- [[ Squad Groups ]]"
Let's get into adding code which applies the abandon action to the panther squad:
Add the following code above last occurring "end"-word in the file:
local t_AbandondedVehicles = {sg_panther}
local player = World_GetPlayerAt(1)
for key, sgroup in ipairs(t_AbandondedVehicles) do
Command_PlayerSquadCriticalHit(player, sgroup, PCMD_CriticalHit, BP_GetCriticalBlueprint("vehicle_abandon"), 1, false)
end
The result should look something like this:
function OnInitID()
-- [[ Markers ]]
-- [[ Squad Groups ]]
sg_panther = SGroup_CreateIfNotFound("sg_panther")
-- [[ Entity Groups ]]
-- List all vehicles to abandon in this table. Use comma as separator.
local t_AbandondedVehicles = {sg_panther}
local player = World_GetPlayerAt(1)
for key, sgroup in ipairs(t_AbandondedVehicles) do
Command_PlayerSquadCriticalHit(player, sgroup, PCMD_CriticalHit, BP_GetCriticalBlueprint("vehicle_abandon"), 1, false)
end
end
Double-check t_AbandondedVehicles = {sg_panther}
so it matches your squad group name(s).
In case of multiple squad groups, use comma (",") as a separator.
e.g.
t_AbandondedVehicles = {sg_panther, sg_stug, sg_halftrack}
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 enjoy your freshly abandoned vehicle!
Configuring the code to match your needs
Adding and removing squad groups from the list should be easy. You can always take a look at the list in WorldBuilder by selecting "Groups" -> "Squad Group List".
In this tutorial you learned how to add abandoned vehicles to 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!