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¶
- Follow Add a melee weapon: an item and a
DA_Weapon_<Name>that point at each other, the item inDA_ItemRegistry_Default, and a place to find it. - On the weapon, tick
bIsFirearmand fill theFirearmfields (table below). - Give the held mesh a
Barrelsocket (the muzzle, for a laser) and aScopesocket (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 aMuzzlesocket if you add one. If your meshes name that socket differently, setMuzzleSocketin the Class Defaults ofBP_Survivor. - 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.
- Declare a tag
Caliber.<Name>in Edit > Project Settings > Gameplay Tags. It is stored with the project's other gameplay tags, inConfig/DefaultGameplayTags.ini. - Create
DA_Caliber_<Name>, of the classPDA_CaliberDef, inDataAssets/Weapons/Childs/. FillCaliberTag,RoundItem,BoxItem,RoundsPerBox, andOpenSecondsandPackSeconds, the time to open a box and to pack one (1.5 s each on the shipped calibres). - Create the round,
DA_Item_Ammo_<Name>, withCategoryon Ammo and a largeMaxStack. - Create the box,
DA_Item_AmmoBox_<Name>, withMaxStack1 and about 90 % of the weight of its rounds. - Point
CaliberDefof both items back at the calibre, and add both toDA_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.
- Create
DA_Magazine_<Name>, of the classPDA_MagazineDef, and fillCaliber,Capacity,CompatibleWeaponsandPerRoundSeconds(0.5). - Create its item,
DA_Item_<Name>Magazine, withCategoryon Ammo,MaxStack1 andMagazineDefpointing at the magazine. Add it toDA_ItemRegistry_Default. - 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.
- Create
DA_Attachment_<Name>, of the classPDA_AttachmentDef, and fill its fields (table below). - Create an item whose
AttachmentDefpoints at it, and add the item toDA_ItemRegistry_Default. - 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¶
- Open
Content/ZombieSurvival/Maps/L_Worldand press Play. - Press T and type
/give <ItemSaveId>for the gun, then for its rounds or box. - Press Tab and left-click the gun's row to equip it.
- Press R to reload. A short press queues the whole plan. Holding it for 0.5 s opens the reload ring.
- 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.