- Documentation
- Shared functions
- getPedWeapon
Function
getPedWeapon
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
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.getPedWeaponSlotReturns the slot number (0-12) of the weapon a ped is currently holding. The slot follows from the weapon type: e.g. handguns are slot 2, assault rifles slot 5. When the ped is holding fists it returns 0.giveWeaponGives a ped a weapon with ammo. If the ped already has a weapon in that slot, it is replaced.getWeaponNameFromIDReturns the GTA San Andreas weapon name for an ID (0-46).