TakeWeapon: Difference between revisions
Jump to navigation
Jump to search
m (→Example) |
No edit summary |
||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Server function}} | {{Server function}} | ||
This function removes a specified weapon from a certain player's inventory. | This function removes a specified weapon or ammo from a certain player's inventory. | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua">bool takeWeapon ( player thePlayer, int weaponId )</syntaxhighlight> | <syntaxhighlight lang="lua">bool takeWeapon ( player thePlayer, int weaponId [, int ammo ] )</syntaxhighlight> | ||
===Required Arguments=== | ===Required Arguments=== | ||
*'''thePlayer''': A player object referencing the specified player. | *'''thePlayer''': A player object referencing the specified player. | ||
*'''weaponId''': An integer that refers to a [[weapon]] that you wish to remove. | *'''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=== | ||
Returns a ''true'' if the weapon was removed successfully, ''false'' otherwise. | Returns a ''true'' if the weapon/ammo was removed successfully, ''false'' otherwise. | ||
==Example== | ==Example== | ||
Line 20: | Line 23: | ||
outputChatBox ( "Weapon 28 removed from " .. getPlayerName ( thePlayer ) .. "." ) | outputChatBox ( "Weapon 28 removed from " .. getPlayerName ( thePlayer ) .. "." ) | ||
end</syntaxhighlight> | end</syntaxhighlight> | ||
This example will give the player an M4 weapon with 200 ammo followed by taking 5 ammo | |||
<syntaxhighlight lang="lua"> | |||
giveWeapon ( thePlayer, 31, 200 ) -- Gives the M4 weapon with 200 ammo | |||
takeWeapon ( thePlayer, 31, 5 ) -- Takes 5 ammo from the player's M4 | |||
</syntaxhighlight> | |||
==See Also== | ==See Also== | ||
{{Weapon functions}} | {{Weapon functions}} | ||
[[ru:takeWeapon]] | [[ru:takeWeapon]] |
Revision as of 23:08, 21 October 2011
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 weapon 28 from player ID 1. If successful, it displays a message in the chat box.
thePlayer = getPlayerFromID ( 1 ) if ( takeWeapon ( thePlayer, 28 ) ) outputChatBox ( "Weapon 28 removed from " .. getPlayerName ( thePlayer ) .. "." ) end
This example will give the player an M4 weapon with 200 ammo followed by taking 5 ammo
giveWeapon ( thePlayer, 31, 200 ) -- Gives the M4 weapon with 200 ammo takeWeapon ( thePlayer, 31, 5 ) -- Takes 5 ammo from the player's M4