# Register Weapon

### 📤 Export: `CreateWeaponInfo`

#### **Description**

The `CreateWeaponInfo` function exports weapon data to the `mdt_weapons` table in the database. It is used to associate a weapon serial number with a citizen, weapon model, and optionally an image. If the weapon serial already exists, it updates the relevant fields.

***

#### ✅ **Function Signature**

```lua
exports['kartik-mdt']:CreateWeaponInfo(serial, imageurl, citizenid, weaponname)
```

***

#### 📥 **Parameters**

| Parameter    | Type   | Required | Description                                                                 |
| ------------ | ------ | -------- | --------------------------------------------------------------------------- |
| `serial`     | string | ✅ Yes    | The unique serial number of the weapon.                                     |
| `imageurl`   | string | ❌ No     | Optional image URL of the weapon. If not provided, a default image is used. |
| `citizenid`  | string | ✅ Yes    | The citizen ID of the owner of the weapon.                                  |
| `weaponname` | string | ✅ Yes    | The model name or type of the weapon.                                       |

***

#### 🗂️ **Database Table: `mdt_weapons`**

| Column Name    | Type    | Description                           |
| -------------- | ------- | ------------------------------------- |
| `serialNumber` | VARCHAR | Primary key, unique weapon serial.    |
| `citizenId`    | VARCHAR | The citizen ID linked to the weapon.  |
| `weaponName`   | VARCHAR | Name/model of the weapon.             |
| `image`        | TEXT    | URL of the image representing weapon. |

***

#### ⚙️ **Function Logic**

1. Checks if a weapon with the given serial number already exists.
2. If not, inserts a new record with the provided details.
3. If it exists, updates the existing record with the latest `citizenId`, `weaponName`, and `image`.

***

#### 🖼️ **Default Image**

If no `imageurl` is provided, the following default image URL is used:

```
https://kappa.lol/hObsm7
```

***

#### 🔁 **Example Usage**

```lua
local serial = "WEAPON123456"
local imageurl = "https://example.com/images/pistol.png"
local citizenid = "CIT1234"
local weaponname = "Pistol"

exports['kartik-mdt']:CreateWeaponInfo(serial, imageurl, citizenid, weaponname)
```

> 💡 If `imageurl` is `nil`, the function will automatically use the default image.

***
