Skip to content

Add a firearm

A firearm is a melee weapon with the shooting fields filled in. It then fires, reloads round by round or by magazine, jams with wear, takes attachments and sits in a weapon position. The reload ring, the item menu, the counters, the save and co-op all read these fields, so a gun has no list of its own to join. Only its items are registered: the gun, its rounds and boxes, its magazine and its attachments.

Steps

  1. Follow Add a melee weapon: an item and a DA_Weapon_<Name> that point at each other, the item in DA_ItemRegistry_Default, and a place to find it.
  2. On the weapon, tick bIsFirearm and fill the Firearm fields (table below).
  3. Give the held mesh a Barrel socket (the muzzle, for a laser) and a Scope socket (the rail) if it takes those attachments. Model it along +X from the grip or the stock, as the shipped ones are. The tracer and the muzzle flash start at its front end, or at a Muzzle socket if you add one. If your meshes name that socket differently, set MuzzleSocket in the Class Defaults of BP_Survivor.
  4. Make sure its calibre exists and, for a magazine gun, its magazine (sections below).
Field What it does
bIsFirearm Switches the left click from melee to shooting.
FeedType How it is loaded: Magazine (a detachable magazine) or Internal (round by round).
Caliber The PDA_CaliberDef it fires.
CompatibleMagazines For a magazine gun, the PDA_MagazineDef it accepts.
InternalCapacity For an internal magazine, the rounds it holds.
bHasChamber, bRackAfterShot A round in the chamber (the "+1"). Worked after each shot, as a pump or a bolt.
bCanJam, JamChance Whether it jams, and its chance in percent per shot, before wear and the world option.
PelletCount, PelletSpreadDegrees, MaxHitCount Pellets per shot and their cone, and the most targets one shot hits. 1 and 0 for a bullet.
PerRoundSeconds, InsertSeconds, EjectSeconds, RackSeconds The length of each reloading step.
AttachmentSlots The attachments it takes: Scope, Barrel, Sling.
CarryKind Which weapon positions take it: Long for a long gun, Handgun for a handgun.
ShotNoise The noise of its shot, a Noise.* tag of the noise table. The loudness of that row is how far the shot carries to zombie hearing, which makes it the balance dial of the gun.
ConditionMax Its wear. A worn gun jams more often (JamWearFactor).
ReloadSound Played when a reload begins. Each reload step has its own sound.

The numbers shared by every gun are in DataAssets/Weapons/Childs/DA_Firearm_Default, with the click of an empty gun, the sound of a cleared jam and the laser dot (mesh, material, 6 uu).

Field Default What it does
JamWearFactor 4 How much wear raises the jam chance.
UnjamBase, UnjamPerLevel 0.6, 0.04 The chance that a rack clears a jam, and its gain per Firearms level.
ReloadHoldSeconds 0.5 s How long R is held to open the reload ring.
bAutoRack on Inserting a magazine racks the slide.

A calibre

Four calibres ship, for the pistol, the revolver, the shotgun and the rifle, with 50, 50, 25 and 20 rounds a box.

  1. Declare a tag Caliber.<Name> in Edit > Project Settings > Gameplay Tags. It is stored with the project's other gameplay tags, in Config/DefaultGameplayTags.ini.
  2. Create DA_Caliber_<Name>, of the class PDA_CaliberDef, in DataAssets/Weapons/Childs/. Fill CaliberTag, RoundItem, BoxItem, RoundsPerBox, and OpenSeconds and PackSeconds, the time to open a box and to pack one (1.5 s each on the shipped calibres).
  3. Create the round, DA_Item_Ammo_<Name>, with Category on Ammo and a large MaxStack.
  4. Create the box, DA_Item_AmmoBox_<Name>, with MaxStack 1 and about 90 % of the weight of its rounds.
  5. Point CaliberDef of both items back at the calibre, and add both to DA_ItemRegistry_Default.

Calibres have no list to edit. They are found through their items and weapons.

An ammunition magazine

This is the magazine that holds rounds. The one players read is a reading magazine. One ships, for the pistol, with 12 rounds at 0.5 s a round.

  1. Create DA_Magazine_<Name>, of the class PDA_MagazineDef, and fill Caliber, Capacity, CompatibleWeapons and PerRoundSeconds (0.5).
  2. Create its item, DA_Item_<Name>Magazine, with Category on Ammo, MaxStack 1 and MagazineDef pointing at the magazine. Add it to DA_ItemRegistry_Default.
  3. Add the magazine to the weapon's CompatibleMagazines.

An attachment

Three ship, a scope, a laser sight and a sling, which take 3, 2 and 1 s to attach.

  1. Create DA_Attachment_<Name>, of the class PDA_AttachmentDef, and fill its fields (table below).
  2. Create an item whose AttachmentDef points at it, and add the item to DA_ItemRegistry_Default.
  3. Make sure the weapon lists that slot in AttachmentSlots.
Field What it does
Slot Where it goes: Scope, Barrel or Sling.
CompatibleWeapons The guns that take it.
Modifiers One row per stat: a Stat.* tag, add or multiply, a value. The stats read are Stat.Firearm.Range, Stat.Firearm.AimSpread, Stat.Firearm.HipSpread and Stat.WeaponSlot.DrawTime.
RequiredTool The tool needed to mount it. Empty: none.
AttachMesh, AttachSocket The mesh, and the socket on the gun.
bLaser, LaserOrigin For a laser dot.
AttachSeconds The time to attach.

The weapon positions

Each position is a DA_WornSlot_* asset, of the class PDA_WornSlotDef, in DataAssets/Weapons/Childs/. Four ship: the left and the right of the belt, the holster and the back.

Field What it does
Position The position it is.
Label, Icon Its name and picture.
AcceptedKinds The CarryKind values it takes.
AttachSocket, AttachOffset A socket of the character skeleton, and an offset from it.
DrawSeconds The draw time: 0.4 s for each belt, 0.5 s for the holster, 1.0 s for the back.
bRequiresBagOrSling A backpack or a sling must be worn. On for the back.
Refusal texts What the survivor is told when the position cannot be used.

Which positions exist is set in DA_WeaponSlots_Default, in the same folder.

Field What it does
Slots The positions in order, which is the order of the bar and of the keys 1 to 4.
AlwaysActive The positions that need nothing worn.

A piece of clothing gives the other positions while it is worn, through its ProvidedWeaponSlots, as the holster gives the holster position.

A position that is always there

The holster position exists only while a holster is worn. Add DA_WornSlot_Holster to AlwaysActive and every survivor has it from the start. The bar at the bottom of the screen shows it, the right-click menu offers it, key 3 draws from it, and the save carries it.

The keys need no graph either. Each key of IA_WeaponSlot in IMC_Player carries an InputModifierScalar whose value names the position, 1 to 4 in the order of Slots.

A fifth position

A fifth position is a small graph change. It needs a value in E_WeaponSlotPosition and a key. Values 5 and 6 of the same input action are the D-pad steps, read by AC_WeaponSlots.SlotForValue.

Test it

  1. Open Content/ZombieSurvival/Maps/L_World and press Play.
  2. Press T and type /give <ItemSaveId> for the gun, then for its rounds or box.
  3. Press Tab and left-click the gun's row to equip it.
  4. Press R to reload. A short press queues the whole plan. Holding it for 0.5 s opens the reload ring.
  5. Hold Right mouse to aim and press Left mouse to fire. The counter shows the rounds ("11+1", or "JAM" when jammed).

If it does not work

  • The gun, its rounds, its magazine or an attachment is gone after a save and load: that item is not in DA_ItemRegistry_Default.