OnPickupHit: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Added new template, improved example a bit.)
No edit summary
 
(9 intermediate revisions by 7 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Server event}}  
{{Server event}}  
This event is triggered when a [[player]] hits a [[pickup]].
This event is triggered when a [[player]] hits a [[pickup]].


Line 9: Line 8:
</syntaxhighlight>  
</syntaxhighlight>  


*'''thePlayer''': a player [[element]] referring to the player who moved over the pickup.
*'''thePlayer''': a [[player]] element referring to the player who moved over the [[pickup]].


==Source==
==Source==
Line 15: Line 14:


==Cancel effect==
==Cancel effect==
If this event is [[Event system#Canceling|canceled]], the pickup does not disappear and the player doesn't receive its bonus.
If this event is [[Event system#Canceling|canceled]], the pickup does not disappear and the player does not receive its bonus.


==Example==  
==Example==  
This example creates a pickup and outputs a message to the chat box when a player walks over it.
This example creates a pickup and outputs a message to the chat box when a player walks over it.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local aPickup = createPickup ( 10.0, 10.0, 10.0, 2, 31, 3000, 50 ) --Create an M4 weapon pickup when script starts
local thePickup = createPickup( 10, 10, 10, 2, 31, 3000, 50 ) -- Create a M4 weapon pickup when the script starts


function pickedUpWeaponCheck ( player )
function pickedUpWeaponCheck( player )
  outputChatBox ( "You have picked up a M4.", player ) --Display this message in the chat box
    outputChatBox( "You have picked up a M4.", player ) -- Output a message to the chatbox
end
end
addEventHandler ( "onPickupHit", aPickup, pickedUpWeaponCheck )
addEventHandler( "onPickupHit", thePickup, pickedUpWeaponCheck )
</syntaxhighlight>
</syntaxhighlight>


==See Also==
{{See also/Server event|Pickup events}}
{{Event_functions}}

Latest revision as of 02:57, 27 September 2018

This event is triggered when a player hits a pickup.

Parameters

player thePlayer
  • thePlayer: a player element referring to the player who moved over the pickup.

Source

The source of this event is the pickup that was hit by the player.

Cancel effect

If this event is canceled, the pickup does not disappear and the player does not receive its bonus.

Example

This example creates a pickup and outputs a message to the chat box when a player walks over it.

local thePickup = createPickup( 10, 10, 10, 2, 31, 3000, 50 ) -- Create a M4 weapon pickup when the script starts

function pickedUpWeaponCheck( player )
    outputChatBox( "You have picked up a M4.", player ) -- Output a message to the chatbox
end
addEventHandler( "onPickupHit", thePickup, pickedUpWeaponCheck )

See Also

Pickup events


Event functions