ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Shared functions
  3. getPedWeapon

Function

getPedWeapon

Server and clientPedsIdentical to MTA:SA

Returns 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.

Syntax

int getPedWeapon(ped ped [, int slot = nil])

Arguments

pedped
A player or an NPC.
slotint, optional = nil
Slot 0-12. Omitted = the weapon in hand. Ignored on the client.

Returns

Weapon ID (0 = none / fists), or false on a bad argument.

Example

addCommandHandler("bron", function(player)
    local id = getPedWeapon(player)
    outputChatBox("Trzymasz: " .. (getWeaponNameFromID(id) or "nic"), player)
end)

See also