OnPlayerContact: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(New page: __NOTOC__ This event is triggered when the player hits an element. ==Syntax== <syntaxhighlight lang="lua"> void onPlayerContact ( element previous, element current ) </syntaxhighlight> ==Parameters== *The ...)
 
No edit summary
 
(6 intermediate revisions by 6 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__
This event is triggered when the player hits an [[element]].
{{Server event}}
This event is triggered when a player stands on a different element than before.


==Syntax==  
==Parameters==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
void onPlayerContact ( element previous, element current )
element previousElement, element currentElement
</syntaxhighlight>  
</syntaxhighlight>  


==Parameters==
*'''previousElement''': the [[element]] [[player]] was standing on before. ''nil'' if none.
*The '''source''' of this event refers to the [[player]] who hit an element.
*'''currentElement''': the new [[element]] that the [[player]] is standing on now. ''nil'' if none.
*'''previous''': the [[element]] player was standing on before.
 
*'''current''': the element that was hit.
==Source==
The [[event system#Event source|source]] of this event is the [[player]] who hit an element.


==Example==  
==Example==  
This example outputs the element you have hit
This example outputs the element type of an element you have hit
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function onPlayerContact ( prev, current )
function outputElementType ( prev, current )
if ( current ~= nil ) then
if ( current ) then
outputChatBox ( "You have hit an "..getElementType ( current ) )
outputChatBox ( "You have hit an "..getElementType ( current ) )
end
end
end
end
addEventHandler ( "onPlayerContact", getRootElement(), onPlayerContact )
addEventHandler ( "onPlayerContact", getRootElement(), outputElementType )
</syntaxhighlight>
</syntaxhighlight>


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

Latest revision as of 03:01, 27 September 2018

This event is triggered when a player stands on a different element than before.

Parameters

element previousElement, element currentElement
  • previousElement: the element player was standing on before. nil if none.
  • currentElement: the new element that the player is standing on now. nil if none.

Source

The source of this event is the player who hit an element.

Example

This example outputs the element type of an element you have hit

function outputElementType ( prev, current )
	if ( current ) then
		outputChatBox ( "You have hit an "..getElementType ( current ) )
	end
end
addEventHandler ( "onPlayerContact", getRootElement(), outputElementType )

See Also

Player events


Event functions

Shared