GetPickupType: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(10 intermediate revisions by 7 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
This function retreives the type of a pickup, either a health, armour or weapon pickup.
{{Server client function}}
This function retrieves the type of a pickup, either a health, armour or weapon pickup.


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


===Required Arguments===  
===Required Arguments===  
*'''pickup:''' The pickup you wish to retrieve the type of
*'''thePickup:''' The pickup you wish to retrieve the type of.


===Returns===
===Returns===
Returns an integer of the type of the pickup, which include:
Returns ''false'' if the pickup is invalid, or an integer of the type of the pickup, which include:
*'''0:''' Health pickup
*'''0:''' Health pickup
*'''1:''' Armour pickup
*'''1:''' Armour pickup
*'''2:''' Weapon pickup
*'''2:''' Weapon pickup
*'''3:''' Custom Pickup


==Example==  
==Example==  
This example takes a player's money appropriately according to the amount of health he 'buys'.
This example outputs a text according on the pickup type and it's contents to the player who picks it 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 onPickupHitShow ( thePlayer )                       -- when someone hits a pickup
function onPickupHit ( player ) --when someone hits a pickup
local message = nil                                  -- define the 'message' variable
    if getPickupType ( source ) == 0 then --check the type of pickup, if it is a health pickup then
local pickupType = getPickupType ( source )           -- get the pickup type and save it to the variable 'pickupType'
        health = getPickupHealth ( source )
if (pickupType == 0) then                             -- check the type of pickup, if it is a health pickup then...
         takePlayerMoney ( player, health ) -- take the player's money according to the amount of hp points in the pickup
amount = getPickupAmount ( source )              -- get the amount of health in the pickup
    end
message = "You picked up " .. amount .. " health" -- save the message in the 'message' variable
elseif (pickupType == 1) then                        -- if its a armour pickup then...
amount = getPickupAmount(source)                 -- get the amount of amour in the pickup
message = "You picked up " .. amount .. " armor"  -- save the message in the 'message' variable
elseif (pickupType == 2) then                        -- if its a weapon pickup then..
local weapon = getPickupWeapon ( source )         -- get the weapon id of the pickup
local ammo = getPickupAmmo ( source )            -- get the ammo in the pickup
message = "You picked up " .. getWeaponNameFromID(weapon) .. " with " .. ammo .. " ammo" -- save the message in the 'message' variable
else
message = "Unknown pickup type"      -- if it's neither of the above types, set the 'message' variable accordingly
end
outputChatBox ( message, thePlayer )            -- output the message to the player in the chatbox
end
end
addEventHandler ( "onPickupHit", root, onPickupHitShow ) -- add an event handler for onPickupHit
</syntaxhighlight>
</syntaxhighlight>
</section>


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

Latest revision as of 07:58, 4 November 2020

This function retrieves the type of a pickup, either a health, armour or weapon pickup.

Syntax

int getPickupType ( pickup thePickup )        

Required Arguments

  • thePickup: The pickup you wish to retrieve the type of.

Returns

Returns false if the pickup is invalid, or an integer of the type of the pickup, which include:

  • 0: Health pickup
  • 1: Armour pickup
  • 2: Weapon pickup
  • 3: Custom Pickup

Example

This example outputs a text according on the pickup type and it's contents to the player who picks it up.

Click to collapse [-]
Server
function onPickupHitShow ( thePlayer )                        -- when someone hits a pickup
	local message = nil                                   -- define the 'message' variable
	local pickupType = getPickupType ( source )           -- get the pickup type and save it to the variable 'pickupType'
	if (pickupType == 0) then                             -- check the type of pickup, if it is a health pickup then...
		amount = getPickupAmount ( source )               -- get the amount of health in the pickup
		message = "You picked up " .. amount .. " health" -- save the message in the 'message' variable
	elseif (pickupType == 1) then                         -- if its a armour pickup then...
		amount = getPickupAmount(source)                  -- get the amount of amour in the pickup
		message = "You picked up " .. amount .. " armor"  -- save the message in the 'message' variable
	elseif (pickupType == 2) then                         -- if its a weapon pickup then..
		local weapon = getPickupWeapon ( source )         -- get the weapon id of the pickup
		local ammo = getPickupAmmo ( source )             -- get the ammo in the pickup
		message = "You picked up " .. getWeaponNameFromID(weapon) .. " with " .. ammo .. " ammo" -- save the message in the 'message' variable
	else
		message = "Unknown pickup type"      -- if it's neither of the above types, set the 'message' variable accordingly
	end
	outputChatBox ( message, thePlayer )             -- output the message to the player in the chatbox
end
addEventHandler ( "onPickupHit", root, onPickupHitShow ) -- add an event handler for onPickupHit

See Also