OnMarkerHit: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Add important note regarding weird behavior)
 
(5 intermediate revisions by 4 users not shown)
Line 2: Line 2:
{{Server event}}
{{Server event}}
This event is triggered when an element enters a marker created using [[createMarker]].
This event is triggered when an element enters a marker created using [[createMarker]].
{{Important Note|The event is not triggered when only the dimension changes of the player. So, if you use the `matchingDimension` when teleporting players into existing markers you should always first set their dimension/interior and only then the position}}


==Parameters==
==Parameters==
Line 19: Line 20:
<!-- 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)


local myMarker = createMarker(-2596.625, 579.358, 15.626, 'cylinder', 2.0, 255, 0, 0, 150) -- create myMarker
function handlePlayerMarker(hitElement)
local elementType = getElementType(hitElement)


function MarkerHit( hitElement, matchingDimension ) -- define MarkerHit function for the handler
outputChatBox("Element ("..elementType..") has entered marker.")
    local elementType = getElementType( hitElement ) -- get the hit element's type
    outputChatBox( elementType.." inside myMarker", getRootElement(), 255, 255, 0 ) -- attach the element's type with the text, and output it
end
end
addEventHandler( "onMarkerHit", myMarker, MarkerHit ) -- attach onMarkerHit event to MarkerHit function</syntaxhighlight>
addEventHandler("onMarkerHit", playerMarker, handlePlayerMarker)
</syntaxhighlight>


==Issues==
==Issues==
{{Issues|
{{Issues|
{{Issue|6098|If a marker was attached to another element, onMarkerHit won't be triggered}}
{{Issue|551|If a marker was attached to another element, onMarkerHit won't be triggered}}
{{Issue|519|onMarkerHit not always triggered in interiors}}
{{Issue|923|Server side markers with size < 1.5 don't trigger event}}
}}
}}


==See Also==
{{See also/Server event|Marker events}}
===Marker events===
{{Marker_events}}
===Event functions===
{{Event functions}}

Latest revision as of 20:40, 20 September 2023

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

[[{{{image}}}|link=|]] Important Note: The event is not triggered when only the dimension changes of the player. So, if you use the `matchingDimension` when teleporting players into existing markers you should always first set their dimension/interior and only then the position

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
#551 If a marker was attached to another element, onMarkerHit won't be triggered
#519 onMarkerHit not always triggered in interiors
#923 Server side markers with size < 1.5 don't trigger event

See Also

Marker events


Event functions