OnPickupSpawn: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Added an example.)
No edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Server event}}
{{Server event}}
This event is triggered when a pickup is spawned or respawned.
This event is triggered when a [[pickup]] is spawned or respawned.


==Parameters==
==Parameters==
This event has no arguments
No parameters.


<!-- Add the event's source in the section below -->
==Source==
==Source==
The [[event system#Event source|source]] of this event is the [[pickup]] that just spawned or respawned.
The [[event system#Event source|source]] of this event is the [[pickup]] that just spawned or respawned.


==Example==  
==Example==  
<!-- Explain what the example is in a single sentance -->
This example gets the area and city name when a pickup spawns and outputs it to all the players.
This example get's the area and city name when a pickup spawns and outputs it to all the players.
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function outputSpawn ()
function outputSpawn( )
local area = getElementZoneName ( source ) -- Get the area name where the pickup spawned.
    local area = getElementZoneName( source ) -- Get the area name where the pickup spawned
local city = getElementZoneName ( source, true ) -- Get the city name where the pickup spawned.
    local city = getElementZoneName( source, true ) -- Get the city name where the pickup spawned
outputChatBox ( "A pickup has spawned in " .. area .. " ( " .. city .. " )", getRootElement(), 255, 0, 0 ) -- Output the pickup spawn.
    outputChatBox( "A pickup has spawned in " .. area .. " ( " .. city .. " )", root, 255, 0, 0 ) -- Output a message to the chatbox
end
end
addEventHandler ( "onPickupSpawn", getRootElement(), outputSpawn ) -- Trigger the function when a pickup spawns.
addEventHandler( "onPickupSpawn", root, outputSpawn ) -- Trigger the function when a pickup spawns
</syntaxhighlight>
</syntaxhighlight>


{{See also/Server event|Pickup events}}
{{See also/Server event|Pickup events}}

Latest revision as of 02:58, 27 September 2018

This event is triggered when a pickup is spawned or respawned.

Parameters

No parameters.

Source

The source of this event is the pickup that just spawned or respawned.

Example

This example gets the area and city name when a pickup spawns and outputs it to all the players.

function outputSpawn( )
    local area = getElementZoneName( source ) -- Get the area name where the pickup spawned
    local city = getElementZoneName( source, true ) -- Get the city name where the pickup spawned
    outputChatBox( "A pickup has spawned in " .. area .. " ( " .. city .. " )", root, 255, 0, 0 ) -- Output a message to the chatbox
end
addEventHandler( "onPickupSpawn", root, outputSpawn ) -- Trigger the function when a pickup spawns

See Also

Pickup events


Event functions