GetPickupWeapon: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
m (Removed leading whitespace from syntax)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
__NOTOC__  
{{Server client function}}
This function retrieves the Weapon ID of the Weapon Pickup
__NOTOC__
This function retrieves the weapon ID of a weapon pickup.
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
int getPickupWeapon ( pickup thePickup )        
int getPickupWeapon ( pickup thePickup )
</syntaxhighlight>  
</syntaxhighlight>  


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


===Returns===
===Returns===
Returns an integer of the [[Weapons|Weapon ID]] of the pickup, ''false'' if it's an invalid pickup.
Returns the [[Weapons|Weapon ID]] of the pickup, or ''false'' if the pickup is invalid.


==Example==  
==Example==  
This example gives extra ammo to a player if a pickup only has a small amount of ammo.
This example gives extra ammo to a player if a pickup only has a small amount of ammo.
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function onPickupHitFunc ( player ) --when a pickup is hit
function onPickupHitFunc ( thePlayer )                 -- when a pickup is hit
     if (getPickupType(source) == 2) then -- check if it's a weapon pickup
     if getPickupType ( source ) == 2 then               -- check if it's a weapon pickup
local ammo = getPickupAmmo(source) -- get ammo
        local ammo = getPickupAmmo ( source )           -- get the pickup ammo
if (ammo < 50) then -- if ammo is less than 50
        if ammo < 50 then                               -- if ammo is less than 50
local weapon = getPickupWeapon(source) -- store pickup weapon
            local weapon = getPickupWeapon ( source )   -- store pickup weapon
giveWeaponAmmo(player,weapon,50) -- give an extra 50 ammo
            giveWeaponAmmo ( thePlayer, weapon, 50 )   -- give an extra 50 ammo
end
        end
end
    end
end
end
addEventHandler ( "onPickupHit", getRootElement(), onPickupHitFunc ) -- add an event for onPickupHit
addEventHandler ( "onPickupHit", root, onPickupHitFunc )   -- add the function as handler for onPickupHit
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==

Latest revision as of 20:23, 22 January 2022

This function retrieves the weapon ID of a weapon pickup.

Syntax

int getPickupWeapon ( pickup thePickup )

Required Arguments

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

Returns

Returns the Weapon ID of the pickup, or false if the pickup is invalid.

Example

This example gives extra ammo to a player if a pickup only has a small amount of ammo.

Click to collapse [-]
Server
function onPickupHitFunc ( thePlayer )                  -- when a pickup is hit
    if getPickupType ( source ) == 2 then               -- check if it's a weapon pickup
        local ammo = getPickupAmmo ( source )           -- get the pickup ammo
        if ammo < 50 then                               -- if ammo is less than 50
            local weapon = getPickupWeapon ( source )   -- store pickup weapon
            giveWeaponAmmo ( thePlayer, weapon, 50 )    -- give an extra 50 ammo
        end
    end
end
addEventHandler ( "onPickupHit", root, onPickupHitFunc )    -- add the function as handler for onPickupHit

See Also

GTASA IDs (vehicles, weapons, weathers, characters, colors): http://info.vces.net/ (Special thanks to Brophy and Ratt for making these lists)