GetPedWeapon: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(New page: __NOTOC__ {{Client function}} This function tells you which weapon type is in a certain weapon slot of a ped. See Weapon Info ==Syntax== <syntaxhighlight lang="lua"> int getPedWeapon ( ped th...)
 
No edit summary
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Client function}}
{{Server client function}}
{{New feature|4|1.0.4|
This function is added server-side in 1.0.4. This means this function will only be available client-side for non-1.0.4 servers.
}}
This function tells you which weapon type is in a certain weapon slot of a ped. See [[weapon|Weapon Info]]
This function tells you which weapon type is in a certain weapon slot of a ped. See [[weapon|Weapon Info]]



Revision as of 18:04, 30 April 2010

ADDED/UPDATED IN VERSION 1.0.4 :

This function is added server-side in 1.0.4. This means this function will only be available client-side for non-1.0.4 servers.

This function tells you which weapon type is in a certain weapon slot of a ped. See Weapon Info

Syntax

int getPedWeapon ( ped thePed, [ int weaponSlot = current ] )

Required Arguments

  • thePed: the ped you want to get the weapon type from.

Optional Arguments

  • weaponSlot: an integer representing the weapon slot (set to the ped's current slot if not given).

Returns

Returns an int indicating the type of the weapon the ped has in the specified slot.

It should be noted that if a ped runs out of ammo for a weapon, it will still return the ID of that weapon in the slot (even if it appears as if the ped does not have a weapon at all), though getPedTotalAmmo will return 0. Therefore, getPedTotalAmmo should be used in conjunction with getPedWeapon in order to check if a ped has a weapon.

Example

This serverside example will display a player's current weapon type. In this case, it is hard coded to use the player called someguy.

-- Find a player called someguy and find his current weapon id.
local weaponType = getPedWeapon ( getPlayerFromNick ( "someguy" ) )
-- If a weapon type was returned then
if ( weaponType ) then
    outputChatBox ( "someguy's current Weapon-type: " .. weaponType .. "." ) -- Display the weapon type in the chat box
end

See Also