SetPickupType: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
(4 intermediate revisions by 2 users not shown)
Line 5: Line 5:
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool setPickupType ( pickup thePickup, int type, int amount/weapon, [ int ammo ] )           
bool setPickupType ( pickup thePickup, int theType, int amount/weapon/model [, int ammo ] )           
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
*'''thePickup:''' The pickup which you wish to change the settings of
*'''thePickup:''' The pickup which you wish to change the settings of
* '''type''': An integer representing the type of pickup. You can choose from:
* '''theType''': 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''': 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.
** '''3''': Custom Pickup
* '''amount''': This is an integer representing the amount of Health points or Armour points a pickup has.
'''OR'''
* '''weapon''': If the type is a Weapon pickup, then it represents the [[Weapon|weapon ID]] of the weapon pickup the 'ammo' field must be entered if the type is Weapon Pickup.
'''OR'''
* '''model''': If the pickup is a custom model, this is the model id to use. Many non-pickup models can be used, though some may cause crashes. The following is a list of models designed to be used as pickups.
** '''370:''' Jetpack
** '''1240:''' Health (heart)
** '''1242:''' Armour
** '''1272:''' House (blue)
** '''1273:''' House (green)
** '''1274:''' Money (dollar symbol)
** '''1277:''' Save (floppy disk)


===Optional Arguments===  
===Optional Arguments===  
Line 26: Line 38:
This example changes the pickup time every time someone hits it
This example changes the pickup time every time someone hits it


<section name="Server" class="server" show="false">
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function onPickupHit ( )                          -- when a pickup is hit
function onPickupHit ( )                          -- when a pickup is hit
Line 43: Line 55:


This example changes a local player's pickup every time the spacebar key is pressed down
This example changes a local player's pickup every time the spacebar key is pressed down
<section name="Client" class="client" show="false">
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">function changeMyPickupType ( key, keyState )
<syntaxhighlight lang="lua">function changeMyPickupType ( key, keyState )
     local currenttype = getPickupType ( myPickup )  -- get the current type of the pickup and store it in 'currenttype'
     local currenttype = getPickupType ( myPickup )  -- get the current type of the pickup and store it in 'currenttype'
Line 59: Line 71:
bindKey ( "space", "down", changeMyPickupType ) --bind spacebar to changeMyPickupType function
bindKey ( "space", "down", changeMyPickupType ) --bind spacebar to changeMyPickupType function
end
end
addEventHandler ( "onClientResourceStart", getRootElement(), clientsideResourceStart )</syntaxhighlight>
addEventHandler ( "onClientResourceStart", resourceRoot, clientsideResourceStart )</syntaxhighlight>
</section>
</section>


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

Revision as of 09:54, 21 June 2019

This function allows changing the type of a pickup to a Weapon, Armour or Health pickup, and allows you to set the health points or the weapon and ammo that the pickup will give.

Syntax

bool setPickupType ( pickup thePickup, int theType, int amount/weapon/model [, int ammo ] )          

Required Arguments

  • thePickup: The pickup which you wish to change the settings of
  • theType: An integer representing the type of pickup. You can choose from:
    • 0: Health Pickup
    • 1: Armour Pickup
    • 2: Weapon Pickup
    • 3: Custom Pickup
  • amount: This is an integer representing the amount of Health points or Armour points a pickup has.

OR

  • weapon: 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.

OR

  • model: If the pickup is a custom model, this is the model id to use. Many non-pickup models can be used, though some may cause crashes. The following is a list of models designed to be used as pickups.
    • 370: Jetpack
    • 1240: Health (heart)
    • 1242: Armour
    • 1272: House (blue)
    • 1273: House (green)
    • 1274: Money (dollar symbol)
    • 1277: Save (floppy disk)

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.

Returns

Returns true if successful, false otherwise.

Example

This example changes the pickup time every time someone hits it

Click to collapse [-]
Server
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

This example changes a local player's pickup every time the spacebar key is pressed down

Click to collapse [-]
Client
function changeMyPickupType ( key, keyState )
    local currenttype = getPickupType ( myPickup )  -- get the current type of the pickup and store it in 'currenttype'
    if currenttype == 0 then                      -- if it is currently a health pickup
        setPickupType ( myPickup, 1, 100 )          -- change it to an armour pickup with 100 hp
    elseif currenttype == 1 then                  -- else, if it is currently an armour pickup
        setPickupType ( myPickup, 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 ( myPickup, 0, 100 )          -- change it to a health pickup
    end
end

function clientsideResourceStart ()
	myPickup = createPickup ( 10.0, 10.0, 3.11, 0, 100 ) -- create myPickup at resource start
	bindKey ( "space", "down", changeMyPickupType ) --bind spacebar to changeMyPickupType function
end
addEventHandler ( "onClientResourceStart", resourceRoot, clientsideResourceStart )

See Also