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.
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.
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 event | Use |
|---|---|
weaponDamageEvent | Inspect damage reports; cancel impossible ones |
giveWeaponEvent | Block client-to-client weapon gives |
explosionEvent | Block 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.
PlayerOwnsWeaponin the example stands for your own inventory lookup, such as ox_inventorySearch.
Server-wide hardening, including sv_pureLevel and sv_entityLockdown, is in the security chapter of the Server Handbook.