SetPickupType: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 1: Line 1:
__NOTOC__  
__NOTOC__
{{Server client function}}
This function allows the setting of a pickup to a Weapon, Armour or Health pickup, and allows you to set the health points '''or''' the weapon and ammo
This function allows the setting of a pickup to a Weapon, Armour or Health pickup, and allows you to set the health points '''or''' the weapon and ammo


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
setPickupType ( pickup, type, int amount/weapon, [ int ammo ] )           
setPickupType ( pickup thePickup, int type, int amount/weapon, [ int ammo ] )           
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
*'''pickup:''' The pickup in which you wish to change the settings of
*'''thePickup:''' The pickup which you wish to change the settings of
* '''type''': This is an integer representing the type of pickup, representing the following types:
* '''type''': An integer representing the type of pickup. You can choose from:
** '''0''': Health Pickup
** '''0''': Health Pickup
** '''1''': Armour Pickup
** '''1''': Armour Pickup
** '''2''': Weapon Pickup
** '''2''': Weapon Pickup
* '''amount/weapon''': This is an integer representing the amount of Health points or Armour points a pickup has. If the type is a Weapon pickup, then it represents the Weapon ID of the weapon pickup the 'ammo' field must be entered if the type is Weapon Pickup.
* '''amount/weapon''': An integer representing the amount of Health points or Armour points a pickup has. If the type is a Weapon pickup, then it represents the Weapon ID of the weapon pickup. The 'ammo' field must be specified if the type is Weapon Pickup.


===Optional Arguments===  
===Optional Arguments===  
{{OptionalArg}}  
{{OptionalArg}}  
*'''ammo''': An integer representing the amount of ammo a pickup contains. This is only valid when the pickup type is a Weapon Pickup, and must be entered.
*'''ammo''': An integer representing the amount of ammo a pickup contains. This argument is only valid when the pickup type is a Weapon Pickup, and must be specified in that case.


==Example==  
==Example==  
This example changes the pickup time every time someone hits it
This example changes the pickup time every time someone hits it
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler ( "onPickupHit", root, "onPickupHit" ) --add an event handler for onPickupHit
function onPickupHit ( )                         -- when a pickup is hit
function onPickupHit --when a pickup is hit
     local currenttype = getPickupType ( source ) -- get the current type of the pickup and store it in 'currenttype'
     currenttype = getPickupType ( source ) --define the current type of pickup as currenttype
     if currenttype == 0 then                     -- if it is currently a health pickup
     if currenttype == 0 then --if it is currently a health pickup
         setPickupType ( source, 1, 100 )         -- change it to an armour pickup with 100 hp
         setPickupType ( source, 1, 100 ) --change it to an armour pickup with 100 hp
     elseif currenttype == 1 then                 -- else, if it is currently an armour pickup
     elseif currenttype == 1 then --else, if it is currently an armour pickup
         setPickupType ( source, 2, 29, 100 )     -- change it to an mp5 weapon pickup with 100 ammo
         setPickupType ( source, 2, 29, 100 ) --change it to an mp5 weapon pickup with 100 ammo
     elseif currenttype == 2 then                 -- lastly, if it is already a weapon
     elseif currenttype == 2 then --lastly, if it is already a weapon
         setPickupType ( source 0, 100 )           -- change it to a health pickup
         setPickupType ( source 0, 100 ) --change it to a health pickup
     end
     end
end
end
addEventHandler ( "onPickupHit", getRootElement ( ), onPickupHit ) -- add an event handler for onPickupHit
</syntaxhighlight>
</syntaxhighlight>


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

Revision as of 10:27, 16 August 2007

This function allows the setting of a pickup to a Weapon, Armour or Health pickup, and allows you to set the health points or the weapon and ammo

Syntax

setPickupType ( pickup thePickup, int type, int amount/weapon, [ int ammo ] )          

Required Arguments

  • thePickup: The pickup which you wish to change the settings of
  • type: An integer representing the type of pickup. You can choose from:
    • 0: Health Pickup
    • 1: Armour Pickup
    • 2: Weapon Pickup
  • amount/weapon: An integer representing the amount of Health points or Armour points a pickup has. If the type is a Weapon pickup, then it represents the Weapon ID of the weapon pickup. The 'ammo' field must be specified if the type is Weapon Pickup.

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • ammo: An integer representing the amount of ammo a pickup contains. This argument is only valid when the pickup type is a Weapon Pickup, and must be specified in that case.

Example

This example changes the pickup time every time someone hits it

function onPickupHit ( )                          -- when a pickup is hit
    local currenttype = getPickupType ( source )  -- get the current type of the pickup and store it in 'currenttype'
    if currenttype == 0 then                      -- if it is currently a health pickup
        setPickupType ( source, 1, 100 )          -- change it to an armour pickup with 100 hp
    elseif currenttype == 1 then                  -- else, if it is currently an armour pickup
        setPickupType ( source, 2, 29, 100 )      -- change it to an mp5 weapon pickup with 100 ammo
    elseif currenttype == 2 then                  -- lastly, if it is already a weapon
        setPickupType ( source 0, 100 )           -- change it to a health pickup
    end
end
addEventHandler ( "onPickupHit", getRootElement ( ), onPickupHit ) -- add an event handler for onPickupHit

See Also