Skip to main content
Server Client Proxied to ug-core. Weapons are inventory items. The inventory is the only source of weapons: the server gives the equipped one to the ped, and takes away any other.

How it works

  • Items. A weapon is a non-stackable item in config/items.lua, mapped to a game weapon in config/weapons.lua. Its state lives in the item’s metadata, so it moves with the item: give it, stash it, drop it.
  • Serials. Every new weapon item gets a unique serial, recorded with the character it was created for. See GetBySerial.
  • Equipping. Using a weapon item equips it. Using it again puts it away. The server calls the weapon natives, so a client cannot equip what it does not own.
  • Ammo. Ammo is an item. Reload moves ammo items into the weapon, up to its capacity. Using an ammo item reloads the equipped weapon.
  • Shots and wear. The client reports its ammo count as it shoots. The server only accepts the count going down. Each shot wears the weapon by wear out of 100 durability. At 0 it breaks: it is put away and cannot be equipped until repaired.
  • Attachments and tints. Attachment and tint items are used up into the weapon’s metadata. Components come back off, tints do not. Using an attachment fits it on the equipped weapon.
  • Out of hands. A weapon is put away when its item leaves the player’s inventory, and when the player goes down, dies or unloads the character.
Two natives have no server version: reading ammo and setting tints. The core client does both and reports to the server, which checks every report. See Security.

Config

config/weapons.lua
Every item named here MUST exist in config/items.lua, and weapon items MUST have stack = false. Otherwise boot stops with the item name. The default config comes with weapon_pistol, ammo_9mm, pistol_suppressor and weapon_tint_gold, which config/items.lua also defines by default.

Metadata

New weapons get ammo = 0, durability = 100 and a serial. Pass metadata to AddItem to start from other values, such as a loaded weapon for a shop. Ammo and durability updates do not write audit rows. Attaching, detaching and repairing do.

Server

Equip / Unequip

Equipping the equipped weapon puts it away. Broken weapons and other items return invalid_args. Downed and dead players get no_permission. Weapons:BeforeEquip MAY cancel.

GetEquipped

Reload

Moves ammo items from the player’s inventory into the equipped weapon, up to its capacity. Returns insufficient_items without ammo, not_found without an equipped weapon.

Unload

Takes the loaded rounds out, back into the inventory. Returns cannot_carry when they do not fit.

Attach / Detach

Attach uses one attachment or tint item from itemSlot on the weapon in weaponSlot. Items that do not fit that weapon, or are already fitted, return invalid_args. Detach gives a component back, by item name.

Repair

Sets durability, 100 by default. target is a player source or an inventory id, so a gunsmith can repair weapons in a stash.

GetBySerial

MUST run in a thread. record is { serial, item, characterId?, createdAt }, or nil for unknown serials. characterId is the character the weapon was created for, such as the buyer.

IsWeapon / GetDefinition

Client

Actions ask the server. They MUST run in a thread and return ok, errorCode:
Client events ug-core:Weapons:Equipped with (hash, ammo) and ug-core:Weapons:Unequipped let a HUD show the weapon.
client.lua

Security

The server reads the weapon in hand and gives weapons through OneSync natives. Test them on your artifact before going live, and keep enforce on.

Events

reason is toggle, switch, moved, removed, down, unload, broken or request.

Hooks

It allows or cancels. A safe zone can refuse every equip: