GetPlayerAmmoInClip: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
m (Changed "DeprecatedWithAlt" template to "Deprecated")
 
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{Needs_Checking|Should return ''false'' instead of 0 if player's invalid, for consistency}}
__NOTOC__
__NOTOC__
{{Server client function}}
{{Deprecated|getPedAmmoInClip|}}
This function returns an integer that contains the ammo in a specified [[player]]'s weapon. See [[weapon|Weapon Info]]
This function returns an integer that contains the ammo in a specified [[player]]'s weapon. See [[weapon|Weapon Info]]


==Syntax==
==Syntax==
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
int getPlayerAmmoInClip ( player thePlayer, [ int weaponSlot = current ] )
int getPlayerAmmoInClip ( player thePlayer )
</syntaxhighlight>
</syntaxhighlight>


===Required Arguments===
===Required Arguments===
*'''thePlayer''': The [[player]] whose ammo you want to check.
*'''thePlayer:''' The [[player]] whose ammo you want to check.
 
===Returns===
Returns an [[int]] containing the amount of ammo in the player's currently selected clip, or 0 if the player specified is invalid.
</section>


===Optional Arguments===
<section name="Client" class="client" show="true">
*'''weaponSlot''': an integer representing the weapon slot (set to the players current slot if not given). Please note this argument is only relevant when using the function '''clientside'''.
<syntaxhighlight lang="lua">
int getPlayerAmmoInClip ( player thePlayer, int weaponSlot )
</syntaxhighlight>
 
===Required Arguments===
*'''thePlayer:''' The [[player]] whose ammo you want to check.
*'''weaponSlot:''' an integer representing the weapon slot.


===Returns===
===Returns===
Returns an [[int]] containing the ammount of ammo in the specified player's clip, or 0 if the player specified is invalid.
Returns an [[int]] containing the amount of ammo in the specified player's currently selected or specified clip, or 0 if the player specified is invalid.
</section>


==Example==
==Example==
<section name="Server" class="server" show="true">
This example outputs the amount of ammo the specified player has in his current slot. For example: 'ammo someguy'.
This example outputs the amount of ammo the specified player has in his current slot. For example: 'ammo someguy'.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function showAmmo( player, command, who )
function showAmmo( thePlayer, command, who )
thePlayer = getPlayerFromNick(who)
local targetPlayer = getPlayerFromNick ( who )
if (thePlayer ~= false) then
if ( thePlayer ) then
local ammo = getPlayerAmmoInClip(thePlayer)
local ammo = getPlayerAmmoInClip ( targetPlayer )
outputChatBox(who.." has "..ammo.." in his active clip", player)
outputChatBox ( who .. " has " .. ammo .. " ammo in his active clip", thePlayer )
else
else
outputChatBox("Player '"..who.."' not found.", player)
outputChatBox ( "Player '" .. who .. "' not found.", thePlayer )
end
end
end
end
addCommandHandler( "ammo", showAmmo )
addCommandHandler( "ammo", showAmmo )
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Player functions}}
{{Player functions}}

Latest revision as of 16:24, 13 February 2015

Emblem-important.png This function is deprecated. This means that its use is discouraged and that it might not exist in future versions.

Please use getPedAmmoInClip instead.


This function returns an integer that contains the ammo in a specified player's weapon. See Weapon Info

Syntax

Click to collapse [-]
Server
int getPlayerAmmoInClip ( player thePlayer )

Required Arguments

  • thePlayer: The player whose ammo you want to check.

Returns

Returns an int containing the amount of ammo in the player's currently selected clip, or 0 if the player specified is invalid.

Click to collapse [-]
Client
int getPlayerAmmoInClip ( player thePlayer, int weaponSlot )

Required Arguments

  • thePlayer: The player whose ammo you want to check.
  • weaponSlot: an integer representing the weapon slot.

Returns

Returns an int containing the amount of ammo in the specified player's currently selected or specified clip, or 0 if the player specified is invalid.

Example

Click to collapse [-]
Server

This example outputs the amount of ammo the specified player has in his current slot. For example: 'ammo someguy'.

function showAmmo( thePlayer, command, who )
	local targetPlayer = getPlayerFromNick ( who )
	if ( thePlayer ) then
		local ammo = getPlayerAmmoInClip ( targetPlayer )
		outputChatBox ( who .. " has " .. ammo .. " ammo in his active clip", thePlayer )
	else
		outputChatBox ( "Player '" .. who .. "' not found.", thePlayer )
	end
end
addCommandHandler( "ammo", showAmmo )

See Also