GetPlayerAmmoInClip: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 18: Line 18:


==Example==
==Example==
This example outputs the amount of ammo a player called ''Someguy'' has in his current weapon's clip.
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">
-- Find the player called 'Someguy'
function showAmmo( player, command, who )
myPlayer = findPlayer ( "Someguy" )
thePlayer = getPlayerFromNick(who)
-- If a player called 'Someguy' was found then
if (thePlayer ~= false) then
if ( myPlayer ~= false )
local ammo = getPlayerAmmoInClip(thePlayer)
-- Retrieve the ammount of ammo in the clip for that player, and store it in a variable called 'ammo'
outputChatBox(who.." has "..ammo.." in his active clip", player)
ammo = getPlayerAmmoInClip ( myPlayer )
else
-- Tell all the players how much ammo 'Someguy' has
outputChatBox("Player '"..who.."' not found.", player)
outputChatBox ( "Someguy's current ammo-in-clip: ", ammo, "." )
end
end
end
addCommandHandler( "ammo", showAmmo )
</syntaxhighlight>
</syntaxhighlight>


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

Revision as of 21:45, 29 July 2007

Dialog-information.png This article needs checking.

Reason(s): Should return false instead of 0 if player's invalid, for consistency

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

Syntax

int getPlayerAmmoInClip ( player thePlayer, [ int weaponSlot = current ] )

Required Arguments

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

Optional Arguments

  • weaponSlot: an integer representing the weapon slot (set to the players current slot if not given)

Returns

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

Example

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

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

See Also