FiveM Docs
Addons

esx_weaponshop

esx_weaponshop adds Ammu-Nation and a black market dealer with a NUI, weapon license, ammo, attachments and tints to ESX Legacy. Setup, config and API.

esx_weaponshop is the official weapon store for ESX Legacy. It adds Ammu-Nation locations and a hidden black market dealer, opens a NUI catalog, and lets players buy weapons, a weapon license, ammo, attachments and tints. All purchases are validated and charged on the server.

Overview

Resourceesx_weaponshop (version 1.0)
SideClient + server, NUI (web/dist)
Dependenciesesx_lib, es_extended, esx_license, OneSync (/onesync)
Optionalox_inventory (detected from ESX.GetConfig().OxInventory)
SQL fileesx_weaponshop.sql (adds the weapon license)
Config filesshared/config/main.lua, shops.lua, upgrades.lua, weapon_images.lua

In-game flow:

  • Legal shops (Legal = true, default GunShop) charge cash. With Config.LicenseEnable, players without the weapon license get a menu to buy it for Config.LicensePrice first.
  • Illegal shops (Legal = false, default BlackWeashop) charge black_money, never need a license and have their blip disabled by default.
  • Players can buy ammo, components and tints for a weapon they own and that the zone sells (when Config.WeaponShopUpgrades.Enabled is on).

Installation

Import the SQL

Run esx_weaponshop.sql. It only inserts the weapon license into the licenses table (from esx_license).

INSERT IGNORE INTO `licenses` (`type`, `label`) VALUES ('weapon', "Weapon licence");

The files in localization/ still create a legacy weashops table. The current version does not read it, prices come from the Lua config.

Ensure the resource

server.cfg
ensure oxmysql
ensure esx_lib
ensure es_extended
ensure esx_license
ensure esx_weaponshop

OneSync must be enabled, the manifest declares /onesync as a dependency.

Configuration

Main config (shared/config/main.lua)

KeyDefaultDescription
Config.LocaleGetConvar('esx:locale', 'en')Locale.
Config.OxInventoryESX.GetConfig().OxInventoryUses ox_inventory for weapons and attachments when true.
Config.FallbackWeaponImage''Image shown when a weapon image cannot be loaded.
Config.WeaponImagesper-weapon mapImage overrides. weapon_images.lua fills this with bundled images.
Config.InitialWeaponAmmo42Ammo given with a weapon bought through the ESX loadout.
Config.LicenseEnabletrueRequire the weapon license in legal shops.
Config.LicensePrice5000Price of the weapon license (cash).
Config.ServerDistanceBuffer3.0Extra meters added to InteractionDistance for the server distance check.
Config.PurchaseCooldown1500Minimum ms between purchases of the same type per player.
Config.LicenseCallbackTimeout5000Timeout for esx_license calls in ms.
Config.ClientCallbackTimeout5000Timeout when asking the client for its ammo state.
Config.DrawDistance10.0Marker draw distance.
Config.Size{ x = 1.5, y = 1.5, z = 0.5 }Marker size.
Config.Color{ r = 0, g = 128, b = 255 }Marker color.
Config.Type1Marker type.
Config.InteractionDistance2.0Distance to open the shop.
Config.InteractionKeyLabel'E'Key label shown in the UI.

Shop zones (shared/config/shops.lua)

shared/config/shops.lua
Config.Zones = {
    GunShop = {
        Legal = true,
        Blip = { Enabled = true, Sprite = 110, Color = 81, Display = 4, Scale = 0.7, ShortRange = true },
        Items = {
            { name = 'WEAPON_PISTOL', price = 500 },
            { name = 'WEAPON_BAT', price = 50 },
        },
        Locations = {
            vector3(-662.1, -935.3, 20.8),
        },
    },
}
FieldDescription
Legaltrue = cash + license check, false = black money, no license.
BlipEnabled, Sprite, Color, Display, Scale, ShortRange.
Items{ name, price } per weapon. Only weapons listed here can be bought or upgraded in this zone.
Locationsvector3 list of counters.

Upgrades (shared/config/upgrades.lua)

KeyDefaultDescription
Config.WeaponShopUpgrades.EnabledtrueMaster switch. With ox_inventory enabled, upgrades also require ox_inventory to be started.
Ammo.EnabledtrueSell ammo.
Ammo.PricePerRound5Price per round.
Ammo.DefaultAmount / MinAmount / MaxAmount30 / 1 / 250Amount limits per purchase.
Ammo.MaxTotal250Maximum ammo a weapon may hold after buying.
Ammo.QuickAmounts{ 30, 60, 120, 250 }Buttons in the UI.
Components.EnabledtrueSell attachments.
Components.DefaultPrice750Price when a component has no entry in Prices.
Components.Blacklisted{ clip_default = true }Components that are never sold.
Components.Pricese.g. suppressor = 1250, scope = 1500Per-component prices.
Components.OxItemsByName / OxItemsByHashmappingESX component name or hash to ox_inventory attachment item.
Tints.EnabledtrueSell weapon tints.
Tints.DefaultPrice350Price when a tint index has no entry.
Tints.Prices[0] = 0 ... [7] = 900Price per tint index.
Tints.Swatcheshex colorsColors shown in the UI.

Developer API

The resource has no exports. Its server callbacks are used by the NUI:

CallbackArgumentsDescription
esx_weaponshop:buyWeaponweaponName, zoneBuys a weapon from a zone.
esx_weaponshop:buyLicensenoneBuys the weapon license near a legal shop.
esx_weaponshop:buyUpgradedata ({ weaponName, action, ... }), zoneaction is 'ammo', 'component' or 'tint'.

The server also sends esx_weaponshop:requestWeaponAmmoState to the client and accepts the answer through the net event esx_weaponshop:receiveWeaponAmmoState (only from the same player, matched by request id).

Client-triggerable

All three callbacks are client-callable. The server validates the zone, the weapon name, the distance to a zone location (InteractionDistance + ServerDistanceBuffer), the license, the price from config, the payment and the inventory, and refunds when adding the weapon fails. Requests are rate-limited per player and action. Never move prices to the client.

To check the weapon license from your own scripts, use esx_license:

server/main.lua
TriggerEvent('esx_license:checkLicense', playerId, 'weapon', function(hasLicense)
    if not hasLicense then
        TriggerClientEvent('esx:showNotification', playerId, 'You need a weapon license.')
    end
end)

Common issues

  • Resource does not start. esx_license is a hard dependency and OneSync must be on.
  • License menu never appears. Config.LicenseEnable is false, or the zone has Legal = false.
  • Purchase fails silently. The player is too far from a Locations entry, is spamming (cooldown), lacks cash / black money, or cannot carry the weapon.
  • Upgrades unavailable. Config.WeaponShopUpgrades.Enabled is off, or Config.OxInventory is true and ox_inventory is not started. The player must own the weapon.
  • Changed prices in weashops have no effect. Edit Config.Zones instead.

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