GetPickupAmmo: Difference between revisions
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		
		
	
mNo edit summary  | 
				No edit summary  | 
				||
| Line 1: | Line 1: | ||
__NOTOC__    | __NOTOC__    | ||
{{Server client function}}  | |||
This function retreives the amount of ammo in a Weapon Pickup  | This function retreives the amount of ammo in a Weapon Pickup  | ||
| Line 15: | Line 16: | ||
==Example==    | ==Example==    | ||
This example outputs a message with the picked up weapon and ammo to the player.  | This example outputs a message with the picked up weapon and ammo to the player.  | ||
<section show="true" name="Server" class="server">  | |||
<syntaxhighlight lang="lua">  | <syntaxhighlight lang="lua">  | ||
function onPickupHitFunction ( thePlayer ) --when a pickup is hit  | function onPickupHitFunction ( thePlayer ) --when a pickup is hit  | ||
| Line 24: | Line 26: | ||
addEventHandler ( "onPickupHit", getRootElement(), onPickupHitFunction ) -- add an event for onPickupHit  | addEventHandler ( "onPickupHit", getRootElement(), onPickupHitFunction ) -- add an event for onPickupHit  | ||
</syntaxhighlight>  | </syntaxhighlight>  | ||
</section>  | |||
==See Also==  | ==See Also==  | ||
{{Pickup functions}}  | {{Pickup functions}}  | ||
Revision as of 22:15, 4 August 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, 0 if it's no weapon pickup.
Example
This example outputs a message with the picked up weapon and ammo to the player.
Click to collapse [-]
Serverfunction onPickupHitFunction ( thePlayer ) --when a pickup is hit
	if (getPickupType(source) ~= 2) then return end -- if the pickup is no weapon, stop
	local ammo = getPickupAmmo ( source ) -- get the amount of ammo
	local weapon = getPickupWeapon ( source ) -- define weapon as the weapon of the pickup
	outputChatBox("You just picked up "..getWeaponNameFromID(weapon).." with "..ammo.." ammo",thePlayer) -- output a message to the player
end
addEventHandler ( "onPickupHit", getRootElement(), onPickupHitFunction ) -- add an event for onPickupHit
See Also