GetSlotFromWeapon: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(9 intermediate revisions by 5 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
This allows you to identify the weapon slot that a weapon belongs to.
{{Server client function}}
This function allows you to identify the weapon slot that a weapon belongs to.


==Syntax==  
==Syntax==  
Line 8: Line 9:


===Required Arguments===  
===Required Arguments===  
*'''weaponid:''' Specify the weapon of which weapon slot you want to know.
*'''weaponid:''' [[Weapon]] to find the weapon slot of.


===Returns===
===Returns===
*Returns the player's current weapon slot ID.
Returns an integer representing the given weapon ID's associated weapon slot, ''false'' if the ID was invalid.
*Returns false if it fails to retrieve current weapon slot or if the weaponid is invalid.


==Example==  
==Example==  
This will output to the chatbox what weapon slot a given weapon number belongs to when entered into the console (ie. 'getWeaponSlot 10').
This will output to the chatbox what weapon slot a given weapon number belongs to when entered into the console (i.e. 'getWeaponSlot 10').
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function outputWeaponSlot ( source, commandName, weaponID )
function outputWeaponSlot ( source, commandName, weaponID )
Line 21: Line 21:
if (weaponSlot) then
if (weaponSlot) then
outputChatBox ( "Weapon ID " .. weaponID ..  " is in weapon slot " .. weaponSlot)
    outputChatBox ( "Weapon ID " .. weaponID ..  " is in weapon slot " .. weaponSlot)
else
else
    outputChatBox ( "Invalid weapon ID" )
    outputChatBox ( "Invalid weapon ID" )
Line 29: Line 29:


==See Also==
==See Also==
<!-- Change FunctionArea to the area that this function is in on the main function list page, e.g. Server, Player, Vehicle etc -->
[[Weapons|Weapon IDs]]
[[Weapons|Weapon IDs]]
{{Weapon_functions}}
{{Weapon_functions}}
[[ru:getSlotFromWeapon]]

Latest revision as of 16:33, 10 January 2010

This function allows you to identify the weapon slot that a weapon belongs to.

Syntax

int getSlotFromWeapon ( int weaponid )

Required Arguments

  • weaponid: Weapon to find the weapon slot of.

Returns

Returns an integer representing the given weapon ID's associated weapon slot, false if the ID was invalid.

Example

This will output to the chatbox what weapon slot a given weapon number belongs to when entered into the console (i.e. 'getWeaponSlot 10').

function outputWeaponSlot ( source, commandName, weaponID )
	local weaponSlot = getSlotFromWeapon ( weaponID )
	
	if (weaponSlot) then
	    outputChatBox ( "Weapon ID " .. weaponID ..  " is in weapon slot " .. weaponSlot)
	else
	    outputChatBox ( "Invalid weapon ID" )
	end
end
addCommandHandler ( "getWeaponSlot", outputWeaponSlot )

See Also

Weapon IDs