GetPickupAmmo: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 4: Line 4:
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
int getPickupAmmo ( pickup pickup )         
int getPickupAmmo ( pickup thePickup )         
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
*'''pickup:''' The pickup in which you wish to retrieve the ammo of
*'''thePickup:''' The pickup in which you wish to retrieve the ammo of


===Returns===
===Returns===
Returns an integer of the amount of ammo in the pickup.
Returns an ''integer'' of the amount of ammo in the pickup, ''false'' if the pickup element is invalid.


==Example==  
==Example==  
This example gives extra ammo to a player if a pickup only has a small amount of ammo.
This example outputs a message with the picked up weapon and ammo to the player.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler ( "onPickupHit", root, "onPickupHit" ) -- add an event for onPickupHit
function onPickupHitFunction ( player ) --when a pickup is hit
function onPickupHit ( player ) --when a pickup is hit
if (getPickupType(source) ~= 2) then return end
    ammo == getPickupAmmo ( source )  
local ammo = getPickupAmmo ( source )  
    weapon == getPickupWeapon ( source ) -- define weapon as the weapon of the pickup
local weapon = getPickupWeapon ( source ) -- define weapon as the weapon of the pickup
    if ammo < 50 then -- the ammo of the pickup is less that 50
outputChatBox("You just picked up "..getWeaponNameFromID(weapon).." with "..ammo.." ammo",player) -- output a message to the player
        giveWeaponAmmo ( player, weapon, 50 ) --then give an extra 50 ammo
    end
end
end
addEventHandler ( "onPickupHit", getRootElement(), onPickupHitFunction ) -- add an event for onPickupHit
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Pickup functions}}
{{Pickup functions}}

Revision as of 14:09, 28 July 2007

This function retreives the amount of ammo in a Weapon Pickup

Syntax

int getPickupAmmo ( pickup thePickup )         

Required Arguments

  • thePickup: The pickup in which you wish to retrieve the ammo of

Returns

Returns an integer of the amount of ammo in the pickup, false if the pickup element is invalid.

Example

This example outputs a message with the picked up weapon and ammo to the player.

function onPickupHitFunction ( player ) --when a pickup is hit
	if (getPickupType(source) ~= 2) then return end
	local ammo = getPickupAmmo ( source ) 
	local weapon = getPickupWeapon ( source ) -- define weapon as the weapon of the pickup
	outputChatBox("You just picked up "..getWeaponNameFromID(weapon).." with "..ammo.." ammo",player) -- output a message to the player
end
addEventHandler ( "onPickupHit", getRootElement(), onPickupHitFunction ) -- add an event for onPickupHit

See Also