How to add new weapon and ammo

Tutorial help you to understand how to add new weapons and ammo to the game

Files & folders needed:

assets/gameplay/items.json

assets/gameplay/weapons.json

assets/texts/lang_*.json

In previous tutorial we created obrez weapon hud:

How to add weapon HUD image

Now lets create in any image editor ammo icon for this obrez weapon:

Buckshot ammo 12x70mm

Save it to assets/ui/items/.

Open assets/gameplay/items.json and create new duplicate ammo structure and change it's ID to new one:

items.json
"ammo_obrez": {
    "name": "itm.ammo.obrez.name",
    "caption": "itm.ammo.obrez.caption",
    "icon": "assets/ui/items/ammo_obrez.png",
    "price": 30,
    "weight": 0.1,
    "type": "item"
}

Add name and caption texts to the assets/texts/lang_*.json (* - means any language available there)

lang_*.json
"itm.ammo.obrez.name": "12x70mm buckshot",
"itm.ammo.obrez.caption": "A common 12-gauge cartridge loaded with 6mm buckshot. At close ranges, it has a huge killing effect.",
"itm.obrez.name": "Sawed-off shotgun",
"itm.obrez.caption": "A sawn-off BM-17 rifle. It is lighter and more compact than the original two-barrel rifle, but it is effective only at a close range. One of the weapons most commonly used by beginners."

Create duplacate copy of existing weapon item in assets/gameplay/items.json:

items.json
"w_obrez": {
    "name": "itm.obrez.name",
    "caption": "itm.obrez.caption",
    "icon": "assets/ui/items/w_obrez.png",
    "price": 400,
    "weight": 1.9,
    "slot": "rifle",
    "type": "weapon",
    "profile": "w_obrez_profile"
}

Then open assets/gameplay/weapons.json to create new weapon JSON structure profile:

weapons.json
"w_obrez_profile": {
  "clip_ammo_max": 2,
  "damage": 3.9,
  "accuracy": 0.10,
  "fire_sound": "pistol_sound",
  "hud": "assets/ui/w_obrez_hud.png",
  "sparkle_position": [0.026,-0.025, -0.109],
  "hud_position": [-0.015, 0, -0.054],
  "ammo_type": "ammo_obrez",
  "reload_anim": "reload",
  "speed": 0.38,
  "shoot_count": 1
}

fire_sound use sound name from assets/sounds/ folder.

sparkle_position and hud_position is [X, Y, Z] position on screen. Actually HUD and sparkle is 3D planes that very close to camera. You can use my utility script "HUD Coordinator".

To connect "HUD Coordinator" to the game, open assets/scripts/p_game.gd script and type this code into _ready() function:

func _ready():
    GameAPI.RunOutsideScript("HUD_Coordinator")._ready() #don't forget to place script file near p_game.gd

Tool can move HUD and muzzle flash on screen by arrow keys. Basic controls is F3 for enable/disable in-game utility, UP, DOWN, LEFT, RIGHT, hold SHIFT to move muzzle flash instead HUD, press SPACE to copy positions in ready-to-use JSON properties to clipboard, then after you can Ctrl+V to paste values in weapons.json:

"sparkle_position": [0.019, -0.031, -0.109],
"hud_position": [-0.018, 0.001, -0.054]
HUD Coordinator utility script

Now that's all. Add new weapon to the traders or add to inventory at the game start with scripts.

New weapon item
New weapon

Last updated