On this page
Add a vehicle
We build mymod_jeep, a tougher, heavier variant of Battlefield 2's HMMWV, and make it
spawn at a control point. The same steps work for 2142 and Heroes vehicles.
1. Know what you are copying#
The HMMWV lives in BF2's Objects_server.zip (logic) and Objects_client.zip (meshes, textures, sounds) under Vehicles/Land/USJEP_HMMWV/:
Vehicles/Land/USJEP_HMMWV/
USJEP_HMMWV.con creates the templates (geometry, collision, the root and its children)
USJEP_HMMWV.tweak every tunable property (armor, physics, seats, sounds)
ai/Objects.ai what bots know about it
Meshes/USJEP_HMMWV.collisionMesh
(client) Meshes/*.bundledmesh, Textures/*.dds, Sounds/*.ogg|wavThe root of the vehicle is a PlayerControlObject (anything a player can sit in and drive). Its .con builds the tree; this is the start of the shipped file:
GeometryTemplate.create BundledMesh usjep_hmmwv
CollisionManager.createTemplate usjep_hmmwv
ObjectTemplate.create PlayerControlObject usjep_hmmwv
ObjectTemplate.collisionMesh usjep_hmmwv
ObjectTemplate.hasCollisionPhysics 1
ObjectTemplate.physicsType 3
ObjectTemplate.hasMobilePhysics 1
ObjectTemplate.geometry usjep_hmmwv
ObjectTemplate.addTemplate USJEP_HMMWV_Steeringwheel
ObjectTemplate.setPosition -0.6993/0.3424/0.5893
ObjectTemplate.addTemplate USJEP_HMMWV_CupolaBase
ObjectTemplate.setPosition 0/-0.2991/-0.1348
ObjectTemplate.addTemplate USJEP_HMMWV_Drivetrain_RF
ObjectTemplate.setPosition 0.6298/-0.3998/1.7659The children are the steering wheel (RotationalBundle), the gunner's cupola (another PlayerControlObject), four drivetrains (Spring + wheel), the Engine, entry points, seats, sounds and effects. See how templates form a tree.
2. Copy and rename#
- Create your mod (
mods/mymod/) with its ownServerArchives.con/ClientArchives.conmounting your archives (copy BF2's and add yours before the base ones so your files win), or work in a loose folder while you test. - Copy the folder to
Vehicles/Land/mymod_jeep/and rename the files tomymod_jeep.con/.tweak. - Rename every template name you want to change. The root must get a new name; children you do not modify can keep pointing at the original templates (that saves copying meshes):
rem the mesh and collision stay the HMMWV's: no new art needed
ObjectTemplate.create PlayerControlObject mymod_jeep
ObjectTemplate.collisionMesh usjep_hmmwv
ObjectTemplate.geometry usjep_hmmwv
ObjectTemplate.hasCollisionPhysics 1
ObjectTemplate.physicsType 3
ObjectTemplate.hasMobilePhysics 1
ObjectTemplate.addTemplate USJEP_HMMWV_Steeringwheel
ObjectTemplate.setPosition -0.6993/0.3424/0.5893
rem ... the rest of the children exactly as in USJEP_HMMWV.con ...
include mymod_jeep.tweakTwo templates with the same name: the last one created wins, for every level and every vehicle that uses it. Always rename the root (and any child whose properties you change).
3. Tune it#
mymod_jeep.tweak starts by re-activating the template, then sets the properties. Here we double the armor, make it heavier and keep the HMMWV's damage effects:
ObjectTemplate.activeSafe PlayerControlObject mymod_jeep
ObjectTemplate.setNetworkableInfo BasicInfo
ObjectTemplate.createComponent Armor
ObjectTemplate.armor.maxHitPoints 2000
ObjectTemplate.armor.hitPoints 2000
ObjectTemplate.armor.defaultMaterial 71
ObjectTemplate.armor.hpLostWhileUpSideDown 125
ObjectTemplate.armor.addArmorEffect 50 e_dstate_land_lightsmoke 0.93/0.63/1.63 0/0/0
ObjectTemplate.armor.addArmorEffect 0 e_vexp_armoredcar_small 0/0/0 0/0/0
ObjectTemplate.createComponent VehicleHud
ObjectTemplate.vehicleHud.hudName "KILLMESSAGE_VEHICLE_hmmwv"
ObjectTemplate.vehicleHud.vehicleType 3
ObjectTemplate.mass 2400
ObjectTemplate.gravityModifier 1.5
ObjectTemplate.drag 1
ObjectTemplate.centerOfCollisionOffset 0/0.5/0
ObjectTemplate.setSoldierExitLocation -2/-0.2/0 0/0/0
ObjectTemplate.exitSpeedMod 0.5What the important properties do (all are in the PlayerControlObject and Armor references, with their defaults):
| Property | Effect |
|---|---|
armor.maxHitPoints / armor.hitPoints | health; damage from weapons is scaled by the material table |
armor.hpLostWhileUpSideDown, ...InWater, ...InDeepWater | damage per second in those states |
armor.addArmorEffect <hp> <effect> <pos> <rot> | effect bundles that start below a health threshold (smoke, fire, the wreck explosion at 0) |
mass, drag, gravityModifier, centerOfCollisionOffset | the rigid body; heavier means slower acceleration with the same engine |
setNetworkableInfo BasicInfo | how the object is replicated to clients (the ghost type) |
setSoldierExitLocation, exitSpeedMod | where and how fast soldiers leave it |
Speed, gears and torque live on the Engine child (USJEP_HMMWV_Engine); grip and suspension on the Spring children. To change them, copy those child templates too and point your root at the copies.
4. Make it spawn#
Vehicles appear through an ObjectSpawner in a game mode's GamePlayObjects.con (levels/<map>/gamemodes/gpm_cq/<size>/GamePlayObjects.con). The shipped Strike at Karkand jeep spawner, with our jeep for team 2:
ObjectTemplate.create ObjectSpawner CPNAME_SK_16_gasstation_Jeep
ObjectTemplate.activeSafe ObjectSpawner CPNAME_SK_16_gasstation_Jeep
ObjectTemplate.isNotSaveable 1
ObjectTemplate.hasMobilePhysics 0
ObjectTemplate.setObjectTemplate 1 JEP_VODNIK
ObjectTemplate.setObjectTemplate 2 mymod_jeep
ObjectTemplate.minSpawnDelay 20
ObjectTemplate.maxSpawnDelay 50
Object.create CPNAME_SK_16_gasstation_Jeep
Object.absolutePosition -133.487/161.298/-291.850
Object.rotation -90.000/0.000/0.000
Object.setControlPointId 45
Object.layer 5setObjectTemplate <team> <template> picks the vehicle per team (the spawner follows the owner of control point setControlPointId); minSpawnDelay / maxSpawnDelay set the respawn time in seconds. The spawner's properties are in the ObjectSpawner reference.
5. Test it#
- Run a local bf2-rs server with your mod root and join with the client (see running a server and a client).
- A typo in a property silently does nothing: compare with the reference and watch the server log.
- Bots need
ai/Objects.aifor the new template name (copy the HMMWV's and renameaiTemplate).
In the other games#
- 2142: the same files and steps; vehicles add properties such as pods and shields (see the cross-game table), and walkers use the same
PlayerControlObjectroot. - Heroes: vehicles are fewer and simpler (jeeps, tanks, planes) and are spawned by the same
ObjectSpawner; the game's data lives undermods/bfheroes/in its own archives.
How it is tested#
What this page tells a modder to write is read by the same template host the shipped vehicles go through, so its lines are held by the tests that run the game's own vehicle scripts (objects) and by the physics tests those vehicles drive (physics, the drivetrain). The example on this page was not built and driven by a test: it is a recipe, checked by reading.
In the code#
| What your new vehicle's lines reach | Where |
|---|---|
| template properties and components | crates/bf2-objects |
| engine, gearbox, wheels | crates/bf2-gameplay/src/vehicle/, crates/bf2-physics/src/vehicle.rs (drivetrain) |
| floats, wings, rotors | boats and aircraft |
| seats, entry points, cameras | seats and cameras |
| the armor block | crates/bf2-gameplay/src/health (damage and armor) |
| the spawner that places it | crates/bf2-gameplay/src/vehicle/spawner.rs (spawners and wrecks) |
docs/dev/modding/add-vehicle.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.