Weapons Config
How es_extended defines weapons, ammo types, components and tints in shared/config/weapons.lua, and how to add a custom or addon weapon to ESX Legacy.
shared/config/weapons.lua is the weapon catalog of es_extended. It defines which weapons exist in the default loadout system, their labels, ammo type, attachable components and tints. xPlayer weapon methods, the /giveweapon commands and the ESX.GetWeapon* helpers all read from it.
Overview
| Fact | Value |
|---|---|
| File | es_extended/shared/config/weapons.lua |
| Side | Shared |
| Tables | Config.DefaultWeaponTints, Config.MK2WeaponTints, Config.Weapons |
| Entries | 112 weapons and gadgets in 1.16.4 |
| Helpers | ESX.GetWeapon, ESX.GetWeaponFromHash, ESX.GetWeaponList, ESX.GetWeaponLabel, ESX.GetWeaponComponent (shared functions) |
Config.Weapons
An array of weapon definitions, grouped by comments into Melee, Handguns, Shotguns, SMG & LMG, Rifles, Sniper, Heavy / Launchers, Thrown and Tools.
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Upper-case game name, for example WEAPON_PISTOL. Lookups convert input to upper case. |
label | string | Yes | Display name, usually TranslateCap("weapon_pistol"). |
components | table[] | Yes | Attachments, use {} for none. See below. |
ammo | table? | No | { label, hash }. hash is the ammo type hash, for example `AMMO_PISTOL`. Only for weapons that use ammo. |
tints | table? | No | Tint labels by index. Usually Config.DefaultWeaponTints or Config.MK2WeaponTints. xPlayer.setWeaponTint only accepts indexes that exist here. |
throwable | boolean? | No | true for grenades and similar. The weapon is removed from the loadout when its ammo reaches 0. |
Each component is { name, label, hash }:
| Field | Type | Description |
|---|---|---|
name | string | Short ESX name used in code and commands, for example clip_extended, suppressor, flashlight, scope, grip. |
label | string | Display name. |
hash | number | Game component hash, for example `COMPONENT_AT_PI_SUPP`. |
{
name = "WEAPON_COMBATPISTOL",
label = TranslateCap("weapon_combatpistol"),
ammo = { label = TranslateCap("ammo_rounds"), hash = `AMMO_PISTOL` },
tints = Config.DefaultWeaponTints,
components = {
{ name = "clip_default", label = TranslateCap("component_clip_default"), hash = `COMPONENT_COMBATPISTOL_CLIP_01` },
{ name = "clip_extended", label = TranslateCap("component_clip_extended"), hash = `COMPONENT_COMBATPISTOL_CLIP_02` },
{ name = "flashlight", label = TranslateCap("component_flashlight"), hash = `COMPONENT_AT_PI_FLSH` },
{ name = "suppressor", label = TranslateCap("component_suppressor"), hash = `COMPONENT_AT_PI_SUPP` },
},
},A melee weapon only needs the basics:
{ name = "WEAPON_BAT", label = TranslateCap("weapon_bat"), components = {} },Tints
| Table | Indexes | Used by |
|---|---|---|
Config.DefaultWeaponTints | 0 to 7 (Default, Green, Gold, Pink, Army, LSPD, Orange, Platinum) | Regular weapons |
Config.MK2WeaponTints | 0 to 32 (classic, contrast, bold and metallic finishes) | MK II weapons |
xPlayer.setWeaponTint("WEAPON_PISTOL", 2) -- gold, from DefaultWeaponTintsAdding a custom weapon
Add the entry
Append your weapon to Config.Weapons. Use the exact spawn name from the weapon resource, in upper case.
{
name = "WEAPON_M4CUSTOM",
label = "M4 Custom",
ammo = { label = TranslateCap("ammo_rounds"), hash = `AMMO_RIFLE` },
tints = Config.DefaultWeaponTints,
components = {
{ name = "clip_default", label = TranslateCap("component_clip_default"), hash = `COMPONENT_M4CUSTOM_CLIP_01` },
},
},Add a translation (optional)
If you use TranslateCap("weapon_m4custom"), add the key to the locale files in es_extended/locales. A plain string works too.
Restart and test
Restart the server and run /giveweapon me weapon_m4custom 100.
Common issues
Invalid weapon name!assertion: the weapon is not inConfig.Weapons.ESX.GetWeapon,ESX.GetWeaponLabelandESX.GetWeaponComponentall assert on unknown names.- Component cannot be added: the component
namemust exist in that weapon'scomponentslist, and the player must own the weapon. - Weapons from the old config disappeared after an update: loadout entries whose name is no longer in
Config.Weaponsare dropped when the character loads.
Related
Frequently asked questions
Independent documentation
Last updated on
Main Config
Every key in es_extended shared/config/main.lua for ESX Legacy 1.16.4 with type, default value and effect. Accounts, spawns, paychecks, permissions and convars.
Adjustments Config
es_extended adjustments.lua explained. Toggle PvP, wanted level, dispatch, NPC density, HUD components, AI plates and Discord Rich Presence in ESX Legacy.