TakeWeapon: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(13 intermediate revisions by 8 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
==Description==
{{Server function}}
This function removes a specified weapon from a certain player's inventory. It returns a boolean value (true or false) depending on whether the function passed or failed.
This function removes a specified weapon or ammo from a certain player's inventory.


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">TakeWeapon ( player, weaponid )</syntaxhighlight>
<syntaxhighlight lang="lua">bool takeWeapon ( player thePlayer, int weaponId [, int ammo ] )</syntaxhighlight>


===Required Arguments===
===Required Arguments===
*'''player''': A player object referencing the specified player.
*'''thePlayer''': A player object referencing the specified player.
*'''weaponid''': An integer (whole number) that refers to a [[Weapon]] that you wish to remove. Click weapon for a page with weapon ID listings.
*'''weaponId''': An integer that refers to a [[weapon]] that you wish to remove.
 
===Optional Arguments===
*'''ammo''': If used, this amount of ammo will be taken instead and the weapon will not be removed.
 
===Returns===
Returns a ''true'' if the weapon/ammo was removed successfully, ''false'' otherwise.


==Example==
==Example==
<syntaxhighlight lang="lua">player = getPlayerFromID ( 1 )
This example removes teargas from player.
if ( TakeWeapon ( player, 1 ) )
<syntaxhighlight lang="lua">
   outputChatBox ( "Weapon 1 removed from ", getPlayerName ( player ), "." )
addCommandHandler( 'rtear',
end</syntaxhighlight>
   function( thePlayer )
    takeWeapon( thePlayer, 17 )
  end
)</syntaxhighlight>


==See Also==
==See Also==
{{Weapon functions}}
{{Weapon functions|server}}
[[pl:takeWeapon]]
[[ru:takeWeapon]]

Latest revision as of 22:39, 6 September 2024

This function removes a specified weapon or ammo from a certain player's inventory.

Syntax

bool takeWeapon ( player thePlayer, int weaponId [, int ammo ] )

Required Arguments

  • thePlayer: A player object referencing the specified player.
  • weaponId: An integer that refers to a weapon that you wish to remove.

Optional Arguments

  • ammo: If used, this amount of ammo will be taken instead and the weapon will not be removed.

Returns

Returns a true if the weapon/ammo was removed successfully, false otherwise.

Example

This example removes teargas from player.

addCommandHandler( 'rtear',
  function( thePlayer )
    takeWeapon( thePlayer, 17 )
  end
)

See Also