- Documentation
- Server functions
- getPedWeapons
Function
getPedWeapons
Returns every weapon a ped owns, together with its ammo. The first value is a list of weapon IDs (one per occupied slot), the second is a table "weapon ID → ammo count". Useful for saving a player's inventory to a database before they leave.
Syntax
table, table getPedWeapons(ped ped)Arguments
pedped- A player or an NPC.
Returns
A list of weapon IDs and a table of ammo by weapon ID.
Example
addEventHandler("onPlayerQuit", root, function()
local list, ammo = getPedWeapons(source)
for _, weapon in ipairs(list) do
outputServerLog(getPlayerName(source) .. ": " .. weapon .. " x" .. ammo[weapon])
end
end)
See also
getPedWeaponReturns the ID of the weapon a ped is holding (0 = fists), or of the weapon in the given inventory slot. Slots are weapon groups: 0 fists, 1 melee, 2 handguns, 3 shotguns, 4 sub-machine guns, 5 assault rifles, 6 rifles, 7 heavy weapons, 8 grenades, 9 sprays and extinguishers, 10 gifts, 11 goggles and parachute, 12 detonator. On the client it returns only the weapon in hand.getPedTotalAmmoReturns all ammo for a weapon (clip plus reserve). Without a slot it refers to the weapon in hand; with a slot, to the weapon in that inventory slot. On the client it always refers to the weapon in hand.giveWeaponGives a ped a weapon with ammo. If the ped already has a weapon in that slot, it is replaced.