# 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="/pages/aNNd1MJ7H1QiQzmWpWjo" %}
[How to add weapon HUD image](/assets/modding/how-to-add-weapon-hud-image.md)
{% endcontent-ref %}

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

<figure><img src="/files/dzD6kXiOfED3efZ7l22o" 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="/files/3NCgiqTDy8AJEHZ1fZYG" 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="/files/OBA3lCo1eLqe2qD8S5lL" alt=""><figcaption><p>New weapon item</p></figcaption></figure>

<figure><img src="/files/vAdhl5TyhXmH9Ee3AmQH" alt=""><figcaption><p>New weapon</p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://picnic-in-the-oblivion.gitbook.io/assets/modding/how-to-add-new-weapon-and-ammo.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
