OnMarkerHit: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Improve example.)
Line 19: Line 19:
<!-- 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">
local playerMarker = createMarker(0, 0, 2, "cylinder", 5, 10, 244, 23, 200, root)


playerMarker = createMarker(1601, 1212, 12.434, "cylinder", 15, 10, 244, 23, 2)
function handlePlayerMarker(hitElement)
local elementType = getElementType(hitElement)


addEventHandler("onMarkerHit", playerMarker, function(hitElement)
outputChatBox("Element ("..elementType..") has entered marker.")
local tps = getPlayerFromName("MR Mariusz")
end
if tps then
addEventHandler("onMarkerHit", playerMarker, handlePlayerMarker)
local x, y, z, = getElementPosition(hitElement)
veh = createVehicle(416, x, y-2, z)
outputChatBox("You create vehicle!", hitElement)
else
outputChatBox("No, no!", hitElement)
end
end)
</syntaxhighlight>
</syntaxhighlight>



Revision as of 13:44, 24 February 2021

This event is triggered when an element enters a marker created using createMarker.

Parameters

element hitElement, bool matchingDimension

Source

The source of this event is the marker that got hit by the element.

Example

This example will output a message what type of element has entered a marker.

local playerMarker = createMarker(0, 0, 2, "cylinder", 5, 10, 244, 23, 200, root)

function handlePlayerMarker(hitElement)
	local elementType = getElementType(hitElement)

	outputChatBox("Element ("..elementType..") has entered marker.")
end
addEventHandler("onMarkerHit", playerMarker, handlePlayerMarker)

Issues

Issue ID Description
#6098 If a marker was attached to another element, onMarkerHit won't be triggered

See Also

Marker events


Event functions