Santa & Christmas Edition36 maps, limited runlimited runShop the drop
Chapter 07 of 10The Weapon Skins Handbook for FiveM

PvP zones, death drops and weapon anti-cheat

In short

A combat mode needs rules of its own: where shooting is allowed, what players receive, what they lose and how quickly they are back. Behind all of it, the server treats whatever a client says about weapons as a claim to check.

client — no shooting inside a safe zone (ox_lib)
local inSafe = false

lib.zones.sphere({
    coords = vec3(-265.0, -963.0, 31.2),
    radius = 60.0,
    onEnter = function() inSafe = true end,
    onExit = function() inSafe = false end,
    inside = function()
        DisablePlayerFiring(PlayerId(), true)
    end,
})
  • Put each arena in its own routing bucket so that matches cannot see one another.
  • Death drops: exports.ox_inventory:CustomDrop('Weapons', items, coords), passed each item’s metadata, keeps serials and attachments.
  • Shooting range: spawn the targets locally, count hits with HasEntityBeenDamagedByEntity, and have the server validate the score.
  • Validate kills and loot on the server. A client’s report of a death or a score is never proof.

The server owns the inventory, so the basic check is to compare the weapon a player is holding with the weapons that player owns.

server — log weapons the inventory never gave out
CreateThread(function()
    while true do
        for _, id in ipairs(GetPlayers()) do
            local src = tonumber(id)
            local weapon = GetSelectedPedWeapon(GetPlayerPed(src))
            if weapon ~= `WEAPON_UNARMED` and not PlayerOwnsWeapon(src, weapon) then
                print(('[weapons] %s holds %s without owning it'):format(GetPlayerName(src), weapon))
            end
        end
        Wait(5000)
    end
end)

AddEventHandler('giveWeaponEvent', function(sender)
    CancelEvent()  -- players never give weapons to others through the game
end)
Server eventUse
weaponDamageEventInspect damage reports; cancel impossible ones
giveWeaponEventBlock client-to-client weapon gives
explosionEventBlock explosion types players should never cause
  • ox_inventory hooks, registerHook('createItem' | 'swapItems' | 'buyItem', …), enforce rules for the whole server.
  • Log first and punish later: lag and other scripts both produce false positives.
  • PlayerOwnsWeapon in the example stands for your own inventory lookup, such as ox_inventory Search.

Server-wide hardening, including sv_pureLevel and sv_entityLockdown, is in the security chapter of the Server Handbook.

The Weapon Skins Handbook for FiveM

This chapter is one of 10. The handbook also carries the native, control and data-file cheat sheets, a glossary and the official references behind every chapter.

Open the handbook