OnPickupSpawn: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (See Also for server events)
(Added an example.)
Line 12: Line 12:
==Example==  
==Example==  
<!-- Explain what the example is in a single sentance -->
<!-- Explain what the example is in a single sentance -->
This example does...
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 -->
<!-- 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">
--This line does...
function outputSpawn ()
blah()
local area = getElementZoneName ( source ) -- Get the area name where the pickup spawned.
--This line does this...
local city = getElementZoneName ( source, true ) -- Get the city name where the pickup spawned.
mooo
outputChatBox ( "A pickup has spawned in " .. area .. " ( " .. city .. " )", getRootElement(), 255, 0, 0 ) -- Output the pickup spawn.
end
addEventHandler ( "onPickupSpawn", getRootElement(), outputSpawn ) -- Trigger the function when a pickup spawns.
</syntaxhighlight>
</syntaxhighlight>


{{See also/Server event|Pickup events}}
{{See also/Server event|Pickup events}}
[[Category:Needs Example]]

Revision as of 16:25, 24 February 2010

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

Parameters

This event has no arguments

Source

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

Example

This example get's 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 .. " )", getRootElement(), 255, 0, 0 ) -- Output the pickup spawn.
end
addEventHandler ( "onPickupSpawn", getRootElement(), outputSpawn ) -- Trigger the function when a pickup spawns.

See Also

Pickup events


Event functions