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

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:


πŸ” Example Usage

πŸ’‘ If imageurl is nil, the function will automatically use the default image.


Last updated