ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Server functions
  3. getPedWeapons

Function

getPedWeapons

ServerPedsTrilogy Hub only

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