Introduction to Weapons in FiveM Development

When you start creating scripts for FiveM servers, one of the most exciting elements you’ll work with is weapons. From handguns and rifles to melee weapons and explosives, weapons are central to GTA V gameplay and play a huge role in roleplay servers, combat systems, and custom game modes.

In this post, we’ll break down how weapons work in FiveM, how to manage them in scripts, and why mastering weapon handling is an essential skill for FiveM developers.


What Are Weapons in FiveM?

Weapons in FiveM are game entities that players can equip, use, and interact with. They can be:

  • Firearms – pistols, rifles, shotguns, SMGs, snipers
  • Melee weapons – bats, knives, crowbars, hammers
  • Explosives – grenades, RPGs, sticky bombs
  • Special items – parachutes, fire extinguishers, flares

Each weapon in GTA V has a unique hash (identifier), which is what we use in scripts to give, remove, or modify weapons for players.


Giving and Removing Weapons

The most common task in FiveM scripting is giving or removing a weapon from a player.

Example: Giving a Weapon

-- Give player a pistol with 250 ammo
GiveWeaponToPed(PlayerPedId(), GetHashKey("WEAPON_PISTOL"), 250, false, true)

Example: Removing a Weapon

-- Remove a pistol from the player
RemoveWeaponFromPed(PlayerPedId(), GetHashKey("WEAPON_PISTOL"))

These functions let you build features like loadouts, shops, job kits (e.g., police officers receiving tasers), or custom weapon systems.


Weapon Components and Attachments

Weapons in FiveM also support components such as scopes, suppressors, extended magazines, and flashlights.

Example: Adding a Suppressor

GiveWeaponComponentToPed(PlayerPedId(), GetHashKey("WEAPON_PISTOL"), GetHashKey("COMPONENT_AT_PI_SUPP"))

This allows you to customize weapons for different jobs, roles, or progression systems on your server.


Detecting Weapon Usage

Sometimes you’ll want to detect when a player is using a weapon—for example, to log gunfire, restrict certain weapons in safe zones, or trigger custom scripts.

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        if IsPedShooting(PlayerPedId()) then
            local weapon = GetSelectedPedWeapon(PlayerPedId())
            print("Player fired: " .. weapon)
        end
    end
end)

This can be used for systems like:

  • Police alerts when a gunshot is fired
  • Anti-cheat checks for restricted weapons
  • Custom game modes like battle royale or deathmatch

Weapon Hashes

Every weapon in GTA V has a weapon hash, which is a unique code that identifies it. Examples include:

  • WEAPON_PISTOL
  • WEAPON_SMG
  • WEAPON_ASSAULTRIFLE
  • WEAPON_CARBINERIFLE
  • WEAPON_KNIFE

You’ll use these hashes whenever you want to give, remove, or detect weapons in FiveM. A full list can be found in the FiveM documentation.


Best Practices for Weapon Scripting

When working with weapons in FiveM, keep these tips in mind:

  1. Balance gameplay – Don’t overload players with powerful weapons unless it fits the server’s design.
  2. Secure weapon giving – Always validate on the server side to prevent players from giving themselves unauthorized weapons.
  3. Use components wisely – Attachments can enhance immersion but should match your server’s roleplay or gameplay style.
  4. Combine with events – Trigger events when weapons are given or used, so other systems (like logging or UI) stay in sync.
Scroll to Top