FiveM Docs
es_extendedConfig

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

FactValue
Filees_extended/shared/config/weapons.lua
SideShared
TablesConfig.DefaultWeaponTints, Config.MK2WeaponTints, Config.Weapons
Entries112 weapons and gadgets in 1.16.4
HelpersESX.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.

FieldTypeRequiredDescription
namestringYesUpper-case game name, for example WEAPON_PISTOL. Lookups convert input to upper case.
labelstringYesDisplay name, usually TranslateCap("weapon_pistol").
componentstable[]YesAttachments, use {} for none. See below.
ammotable?No{ label, hash }. hash is the ammo type hash, for example `AMMO_PISTOL`. Only for weapons that use ammo.
tintstable?NoTint labels by index. Usually Config.DefaultWeaponTints or Config.MK2WeaponTints. xPlayer.setWeaponTint only accepts indexes that exist here.
throwableboolean?Notrue for grenades and similar. The weapon is removed from the loadout when its ammo reaches 0.

Each component is { name, label, hash }:

FieldTypeDescription
namestringShort ESX name used in code and commands, for example clip_extended, suppressor, flashlight, scope, grip.
labelstringDisplay name.
hashnumberGame component hash, for example `COMPONENT_AT_PI_SUPP`.
shared/config/weapons.lua
{
    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

TableIndexesUsed by
Config.DefaultWeaponTints0 to 7 (Default, Green, Gold, Pink, Army, LSPD, Orange, Platinum)Regular weapons
Config.MK2WeaponTints0 to 32 (classic, contrast, bold and metallic finishes)MK II weapons
xPlayer.setWeaponTint("WEAPON_PISTOL", 2) -- gold, from DefaultWeaponTints

Adding 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 in Config.Weapons. ESX.GetWeapon, ESX.GetWeaponLabel and ESX.GetWeaponComponent all assert on unknown names.
  • Component cannot be added: the component name must exist in that weapon's components list, 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.Weapons are dropped when the character loads.

Frequently asked questions

Independent documentation

esx-fivem.com is a community project and is not affiliated with the ESX Framework team. Facts on this page were checked against the upstream source. Official resources: docs.esx-framework.org and github.com/esx-framework.
Edit on GitHub

Last updated on

On this page