GetPickupAmount: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
This function retreives the amount of health or armour given from a pickup.
{{Server client function}}
This function retrieves the amount of health or armor given from a pickup.


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
float getPickupAmount ( pickup pickup )         
int getPickupAmount ( pickup thePickup )         
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
*'''pickup:''' The pickup you wish to retrieve the amount from.
*'''thePickup:''' The pickup you wish to retrieve the amount from.


===Returns===
===Returns===
Returns an integer of the amount the pickup is set to.
Returns an ''integer'' of the amount the pickup is set to, ''false'' if it's invalid, 0 if it's no health or amor pickup.


==Example==  
==Example==  
This example takes a player's money appropriately according to the amount of health he 'buys'.
This example outputs the amount of health a player picked up.
<section show="true" name="Server" class="server">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler ( "onPickupHit", root, "onPickupHit" ) --add an event handler for onPickupHit
function onPickupHitFunction ( thePlayer )
function onPickupHit ( player ) --when someone hits a pickup
     if getPickupType ( source ) == 0 then     -- check the type of pickup, if it is a health pickup then
     if getPickupType ( source ) == 0 then --check the type of pickup, if it is a health pickup then
         amount = getPickupAmount ( source )
         amount = getPickupAmount ( source )
         takePlayerMoney ( player, amount ) -- take the player's money according to the amount in the pickup
         outputChatBox ( "You picked up " .. amount .. " health", thePlayer)
     end
     end
end
end
addEventHandler ( "onPickupHit", root, onPickupHitFunction )  -- add an event handler for onPickupHit
</syntaxhighlight>
</syntaxhighlight>
</section>


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

Latest revision as of 09:57, 15 December 2023

This function retrieves the amount of health or armor given from a pickup.

Syntax

int getPickupAmount ( pickup thePickup )        

Required Arguments

  • thePickup: The pickup you wish to retrieve the amount from.

Returns

Returns an integer of the amount the pickup is set to, false if it's invalid, 0 if it's no health or amor pickup.

Example

This example outputs the amount of health a player picked up.

Click to collapse [-]
Server
function onPickupHitFunction ( thePlayer )
    if getPickupType ( source ) == 0 then      -- check the type of pickup, if it is a health pickup then
        amount = getPickupAmount ( source )
        outputChatBox ( "You picked up " .. amount .. " health", thePlayer)
    end
end
addEventHandler ( "onPickupHit", root, onPickupHitFunction )   -- add an event handler for onPickupHit 

See Also