GetPickupAmmo: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(One intermediate revision by one other user not shown) | |||
Line 19: | Line 19: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function onPickupHitFunction ( thePlayer ) | function onPickupHitFunction ( thePlayer ) | ||
if getPickupType ( source ) ~= 2 then return end | if getPickupType ( source ) ~= 2 then return end -- if the pickup is no weapon, stop | ||
local ammo = getPickupAmmo ( source ) -- get the amount of ammo | local ammo = getPickupAmmo ( source ) -- get the amount of ammo | ||
local weapon = getPickupWeapon ( source ) -- get the weapon of the pickup | local weapon = getPickupWeapon ( source ) -- get the weapon of the pickup | ||
outputChatBox ( "You just picked up a " .. getWeaponNameFromID(weapon) .. " with " .. ammo .. " ammo", thePlayer ) -- output a message to the player | outputChatBox ( "You just picked up a " .. getWeaponNameFromID(weapon) .. " with " .. ammo .. " ammo", thePlayer ) -- output a message to the player | ||
end | end | ||
addEventHandler ( "onPickupHit", | addEventHandler ( "onPickupHit", root, onPickupHitFunction ) -- add an event handler for onPickupHit | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> |
Latest revision as of 08:09, 4 November 2020
This function retrieves 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 ) 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 ) -- get the weapon of the pickup outputChatBox ( "You just picked up a " .. getWeaponNameFromID(weapon) .. " with " .. ammo .. " ammo", thePlayer ) -- output a message to the player end addEventHandler ( "onPickupHit", root, onPickupHitFunction ) -- add an event handler for onPickupHit
See Also