DODS/Creating Weapon Spawns

From Valve Developer Community
Jump to: navigation, search

While weapons can be placed in your Day of Defeat: Source level, it takes a bit of setup to make them work properly. First the entities must be added to the .FGD, then additional setup is required to keep them from despawning after a few seconds.

Weapon Entities

While they exist in the game, the default FGD is missing all the required entities to place weapons.

You can either find a custom .FGD that has them included, or add them yourself. To add them, copy and paste this into your dod.fgd:

FGD Additions
@BaseClass base(Targetname, Angles, Parentname, RenderFields) color(0 0 200) = WeaponItemBase
[
	input Ignite(void) : "Sets the item on fire."
	output OnIgnite(void) : "Fired when the item is set afire."
]

@BaseClass base(WeaponItemBase) = Weapon
[
	spawnflags(Flags) =
	[
		1 : "Start asleep (don't fall to ground)" : 0
	]

	output OnPlayerUse(void) : "Fires when the player +uses this weapon"
	output OnPlayerPickup(void) : "Fires when the player picks up this weapon"
	// output OnNPCPickup(void) : "Fires when an NPC picks up this weapon"
]

@BaseClass base(WeaponItemBase) = Item
[
	output OnPlayerTouch(void) : "Fires when the player touches this object"
]

@PointClass base(Weapon) studioprop("models/weapons/w_k98_rg.mdl") = weapon_riflegren_ger : "Axis Rifle Grenade" []
@PointClass base(Weapon) studioprop("models/weapons/w_k98_rg_grenade.mdl") = weapon_riflegren_ger_live : "Axis Live Rifle Grenade" []
@PointClass base(Weapon) studioprop("models/weapons/w_garand_gren.mdl") = weapon_riflegren_us : "Allies Rifle Grenade" []
@PointClass base(Weapon) studioprop("models/weapons/w_garand_rg_grenade.mdl") = weapon_riflegren_us_live : "Allies Live Rifle Grenade" []
@PointClass base(Weapon) studioprop("models/weapons/w_stick.mdl") = weapon_frag_ger : "Axis Frag Grenade" []
@PointClass base(Weapon) studioprop("models/weapons/w_stick.mdl") = weapon_frag_ger_live : "Axis Live Frag Grenade" []
@PointClass base(Weapon) studioprop("models/weapons/w_frag.mdl") = weapon_frag_us : "Allies Frag Grenade" []
@PointClass base(Weapon) studioprop("models/weapons/w_frag.mdl") = weapon_frag_us_live : "Allies Live Frag Grenade" []
@PointClass base(Weapon) studioprop("models/weapons/w_30cal.mdl") = weapon_30cal : "Allies Machine Gunner's .30Cal" []
@PointClass base(Weapon) studioprop("models/weapons/w_bar.mdl") = weapon_bar : "Allies Support's BAR" []
@PointClass base(Weapon) studioprop("models/weapons/w_bazooka.mdl") = weapon_bazooka : "Allies Rocket's Bazooka" []
@PointClass base(Weapon) studioprop("models/weapons/w_c96.mdl") = weapon_c96 : "Axis C96 Sidearm" []
@PointClass base(Weapon) studioprop("models/weapons/w_colt.mdl") = weapon_colt : "Allies Colt Sidearm" []
@PointClass base(Weapon) studioprop("models/weapons/w_garand.mdl") = weapon_garand : "Allies Rifleman's M1 Garand" []
@PointClass base(Weapon) studioprop("models/weapons/w_k98.mdl") = weapon_k98 : "Axis Rifleman's K98k" []
@PointClass base(Weapon) studioprop("models/weapons/w_k98s.mdl") = weapon_k98_scoped : "Axis Sniper's K98 Sniper" []
@PointClass base(Weapon) studioprop("models/weapons/w_m1carb.mdl") = weapon_m1carbine : "Allies M1 Carbine" []
@PointClass base(Weapon) studioprop("models/weapons/w_mg42bd.mdl") = weapon_mg42 : "Axis Machine Gunner's MG42" []
@PointClass base(Weapon) studioprop("models/weapons/w_mp40.mdl") = weapon_mp40 : "Axis Assault's MP40" []
@PointClass base(Weapon) studioprop("models/weapons/w_mp44.mdl") = weapon_mp44 : "Axis Support's Stg44" []
@PointClass base(Weapon) studioprop("models/weapons/w_p38.mdl") = weapon_p38 : "Axis Walther P38 Sidearm" []
@PointClass base(Weapon) studioprop("models/weapons/w_pschreck.mdl") = weapon_pschreck : "Axis Rocket's Panzerschreck" []
@PointClass base(Weapon) studioprop("models/weapons/w_smoke_ger.mdl") = weapon_smoke_ger : "Axis Smoke Grenade" []
@PointClass base(Weapon) studioprop("models/weapons/w_smoke_us.mdl") = weapon_smoke_us : "Allies Smoke Grenade" []
@PointClass base(Weapon) studioprop("models/weapons/w_spade.mdl") = weapon_spade : "Axis Melee Spade" []
@PointClass base(Weapon) studioprop("models/weapons/w_spring.mdl") = weapon_spring : "Allies Sniper's Springfield" []
@PointClass base(Weapon) studioprop("models/weapons/w_thompson.mdl") = weapon_thompson : "Allies Assault's Thompson" []
@PointClass base(Weapon) studioprop("models/weapons/w_amerk.mdl") = weapon_amerknife : "Allies Melee Knife" []

If done correctly, you should now be able to select all the games' weapons from the entity list.

Building a Weapon Spawner

If you just place a weapon in your map, unlike in other Valve games, it will just disappear after a few seconds. To avoid having our weapons get cleaned up before the player can reach them, we need to use point_template to create the weapon on demand. The exact implementation will depend on how you want to use the weapon spawner.

Standard Weapon Pickup

This is for creating a weapon that stays in the same spot and respawns after a set time. (If you don't want the respawning ability, just use a trigger_once instead of a trigger_multiple)

While we want the weapon to appear to always be present in the level when available, dropped weapon cleanup means we're going to have to fake it a bit.

You will need 4 entities: The weapon entity, a prop_dynamic with the same model, a point_template, and a trigger.

- Place the weapon entity and the prop_dynamic in the same position, and give your weapon a name. For the purposes of this guide, we'll assume your weapon is a Bazooka, and we'll simply call the entity "bazooka_wp". Under flags, check "Start Asleep".

- Place a point_template. We'll name it "bazooka_template". Under "Template 1", select "bazooka wp"

- Build a brush around your weapon, large enough that the player has to be inside it to pick up the weapon.

- Press Ctrl-T, and assign it to trigger_multiple. Set "Delay before Reset" to your desired value if you want it to have a cooldown before another player can pick it up.

- Go to outputs and add the following

My Output Target Entity Target Input Parameter Delay Only Once
Io11.png OnStartTouch bazooka_template ForceSpawn <none> 0.00 No


- If you want the weapon model to disappear until it's ready to be picked up again, name your prop_dynamic, then add the following to your weapon entity's outputs:

My Output Target Entity Target Input Parameter Delay Only Once
Io11.png OnPlayerPickup bazooka_prop TurnOff <none> 0.00 No
Io11.png OnPlayerPickup bazooka_prop TurnOn <none> 15.00 No

Make sure TurnOn delay matches the value you used for your trigger's "Delay before Reset".


Weapon Crate

Day of Defeat also lacks item_item_crate, but we can put together our own. This process will be similar to what we did before, with the addition of an env_entity_maker so we can create the weapon wherever its box is opened.


For this example we'll use the Springfield (weapon_spring) as it's the right size to fit in a weapon crate.


You will need a total of 4 entities for this.

weapon_spring - call it spring_wp. Leave all settings at defaults.

prop_physics_multiplayer - call it spring_box. Set model to supply_crate02.mdl

point_template - call it spring_template. Set Template 1 to spring_wp.

env_entity_maker - call it spring_spawner. Set Parent to spring_box and "Point_template to Spawn" to template_spring.


Set the Outputs of spring_box to the following:

My Output Target Entity Target Input Parameter Delay Only Once
Io11.png OnPlayerUse spring_spawner ForceSpawn <none> 0.00 No


If done correctly, when you press E on the box it should break open and the rifle should fall out.