# How to add new weapon and ammo

Files & folders needed:

> assets/gameplay/items.json
>
> assets/gameplay/weapons.json
>
> assets/texts/lang\_\*.json

In previous tutorial we created obrez weapon hud:

{% content-ref url="how-to-add-weapon-hud-image" %}
[how-to-add-weapon-hud-image](https://picnic-in-the-oblivion.gitbook.io/assets/modding/how-to-add-weapon-hud-image)
{% endcontent-ref %}

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

<figure><img src="https://944141123-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuMONzcWE3AZUdxqlF6bS%2Fuploads%2F8ZAXMlkFeUCv9ge1VCrD%2Fimage.png?alt=media&#x26;token=279636c2-5ee8-49c0-a0fb-cb563e090fea" alt="" width="207"><figcaption><p>Buckshot ammo 12x70mm</p></figcaption></figure>

Save it to <mark style="color:orange;">assets/ui/items/</mark>.

Open <mark style="color:orange;">assets/gameplay/items.json</mark> and create new duplicate ammo structure and change it's ID to new one:

{% code title="items.json" %}

```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"
}
```

{% endcode %}

Add name and caption texts to the <mark style="color:orange;">assets/texts/lang\_\*.json</mark> (\* - means any language available there)

{% code title="lang\_\*.json" %}

```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."
```

{% endcode %}

Create duplacate copy of existing weapon item in <mark style="color:orange;">assets/gameplay/items.json</mark>:

{% code title="items.json" %}

```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"
}
```

{% endcode %}

Then open <mark style="color:orange;">assets/gameplay/weapons.json</mark> to create new weapon JSON structure profile:

{% code title="weapons.json" %}

```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
}
```

{% endcode %}

{% hint style="info" %} <mark style="color:blue;">fire\_sound</mark> use sound name from <mark style="color:orange;">assets/sounds/</mark> folder.

<mark style="color:blue;">sparkle\_position</mark> and <mark style="color:blue;">hud\_position</mark> 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"`](https://drive.google.com/file/d/17LyQq3jh5bwuFZaBhi3xPXRxUK870Jln/view?usp=sharing).
{% endhint %}

To connect [`"HUD Coordinator"`](https://drive.google.com/file/d/17LyQq3jh5bwuFZaBhi3xPXRxUK870Jln/view?usp=sharing)  to the game, open <mark style="color:orange;">assets/scripts/p\_game.gd</mark> script and type this code into \_ready() function:

```gdscript
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:

```json
"sparkle_position": [0.019, -0.031, -0.109],
"hud_position": [-0.018, 0.001, -0.054]
```

<figure><img src="https://944141123-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuMONzcWE3AZUdxqlF6bS%2Fuploads%2FYB0NRRzfSUQ6BENoWhyz%2Fimage.png?alt=media&#x26;token=29a56eb0-d601-47a0-a10c-bf912993d70f" alt=""><figcaption><p>HUD Coordinator utility script</p></figcaption></figure>

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

<figure><img src="https://944141123-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuMONzcWE3AZUdxqlF6bS%2Fuploads%2FmVBMcLGqOtNTY5UVSQE3%2Fimage.png?alt=media&#x26;token=e3335356-5178-4e63-b614-c6124e534a1b" alt=""><figcaption><p>New weapon item</p></figcaption></figure>

<figure><img src="https://944141123-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuMONzcWE3AZUdxqlF6bS%2Fuploads%2F6EOJEEmMMMIWybCDwW71%2Fimage.png?alt=media&#x26;token=55b9455f-f2fe-4885-aecb-1e90fe39d22e" alt=""><figcaption><p>New weapon</p></figcaption></figure>
