<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Icensow</id>
	<title>Multi Theft Auto: Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Icensow"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/wiki/Special:Contributions/Icensow"/>
	<updated>2026-04-25T06:41:30Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=AddEventHandler&amp;diff=78830</id>
		<title>AddEventHandler</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=AddEventHandler&amp;diff=78830"/>
		<updated>2024-02-16T15:20:37Z</updated>

		<summary type="html">&lt;p&gt;Icensow: Fixed misinfo about sourceResourceRoot on client&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__ &lt;br /&gt;
{{Server client function}} &lt;br /&gt;
{{Important Note|Do '''NOT''' use the same name for your handler function as the event name, as this can lead to confusion if multiple handler functions are used. On the same note, for multiple reasons, it is '''NOT''' a good idea to export the same functions that you use locally as remote event handlers.}}&lt;br /&gt;
This function will add an [[event]] handler. An event handler is a function that will be called when the event it's attached to is triggered. See [[event system]] for more information on how the event system works.&lt;br /&gt;
{{Important Note|See code for this note below}}&lt;br /&gt;
&lt;br /&gt;
Event handlers are functions that are called when a particular event happens. Each event specifies a specific set of variables that are passed to the event handler and can be read by your function. The following global variables are available for use in handler functions:&lt;br /&gt;
*'''source''': the element that triggered the event&lt;br /&gt;
*'''this''': the element that the event handler is attached to&lt;br /&gt;
*'''sourceResource''': the resource that triggered the event.&lt;br /&gt;
*'''sourceResourceRoot''': the root element ([[getResourceDynamicElementRoot|dynamic element root]] on client) of the resource that triggered the event.&lt;br /&gt;
*'''client''': the client that triggered the event using [[triggerServerEvent]]. Not set if the event was not triggered from a client.&lt;br /&gt;
{{New_feature|3|1.0|&lt;br /&gt;
*'''eventName''': the name of the event which triggered the handler function.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
It is important to remember that events pass up and down the [[element tree]]. An event triggered on the root element is triggered on every element in the tree. An event triggered on any other element is triggered on its ancestors (its parent element and its parent's parent etc) and its children, grandchildren and great-grandchildren. You can use the ''propagate'' argument to specify if you wish your handler to receive events that have propagated up or down the tree.&lt;br /&gt;
&lt;br /&gt;
The order in which event handlers are triggered is undefined, you should not rely on one event handler being executed before another.&lt;br /&gt;
{{Note|See [[Script security]] for tips on preventing cheaters when using events and element data}}&lt;br /&gt;
{{Note|See [[Event_Source_Element|Event Source Element]] for a descriptive visualization of the event system handling an event trigger.}}&lt;br /&gt;
&lt;br /&gt;
Each function closure can only be added once to each event. On the second attempt to add the function closure to the same event a warning will be emitted to the debug console and the call to addEventHandler will fail.&lt;br /&gt;
==Syntax== &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
bool addEventHandler ( string eventName, element attachedTo, function handlerFunction [, bool propagate = true, string priority = &amp;quot;normal&amp;quot; ] )    &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
===Required Arguments=== &lt;br /&gt;
*'''eventName:''' The name of the [[event]] you want to attach the handler function to. '''Note: The maximum allowed length is 100 ASCII characters (that is, English letters and numerals)'''&lt;br /&gt;
*'''attachedTo:''' The [[element]] you wish to attach the handler to. The handler will only be called when the event it is attached to is triggered for this element, or one of its children. Often, this can be the root element (meaning the handler will be called when the event is triggered for ''any'' element).&lt;br /&gt;
*'''handlerFunction:''' The handler function you wish to call when the event is triggered. This function will be passed all of the event's parameters as arguments, but it isn't required that it takes all of them.&lt;br /&gt;
&lt;br /&gt;
===Optional Arguments===&lt;br /&gt;
*'''propagate:''' A boolean representing whether the handler will be triggered if the event was propagated down or up the [[element tree]] (starting from the source), and not triggered directly on attachedTo (that is, handlers attached with this argument set to ''false'' will only be triggered if ''source == this''). In GUI events you will probably want to set this to ''false''.&lt;br /&gt;
{{New_feature|3.0131|1.3.1|&lt;br /&gt;
*'''priority :''' A string representing the trigger order priority relative to other event handlers of the same name. Possible values are:&lt;br /&gt;
**'''&amp;quot;high&amp;quot;'''&lt;br /&gt;
**'''&amp;quot;normal&amp;quot;'''&lt;br /&gt;
**'''&amp;quot;low&amp;quot;'''&lt;br /&gt;
''It is also possible to add finer priority control by appending a positive or negative number to the priority string. For example (in priority order for reference): &amp;quot;high+4&amp;quot; &amp;quot;high&amp;quot; &amp;quot;high-1&amp;quot; &amp;quot;normal-6&amp;quot; &amp;quot;normal-7&amp;quot; &amp;quot;low+1&amp;quot; &amp;quot;low&amp;quot; &amp;quot;low-1&amp;quot;''&lt;br /&gt;
{{Important Note|Anything bound to a specific element will be run before other handlers that are bound to something higher in the element tree (like root) This means that &amp;quot;high+10&amp;quot; bound to root '''won't''' trigger before &amp;quot;normal&amp;quot; bound directly to an element.}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns ''true'' if the event handler was attached successfully. Returns ''false'' if the specified event could not be found or any parameters were invalid.&lt;br /&gt;
&lt;br /&gt;
==Remarks==&lt;br /&gt;
Due to the additional set of global variables, the event-trigger specific variables it is '''NOT a good idea to use the same function locally as well as directly as an event handler'''. Event handlers often make use of the source element variable which would often find no use in generic functions. Inside of server-side remote event handlers it is important to add protections against exploits due to unexpected client event triggers or network-based load situations while generic functions, due to being part of a controlled call-stack, do not in general face the same issues. It is recommended to adapt a '''good-natured distancing''' principle between code meant to run from local logic in separation to code meant to run from remote logic.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
&amp;lt;!-- This code is wrong. It WILL crash the server eventually because it is registering a new event handler every time &amp;quot;eventName&amp;quot; event is called.&lt;br /&gt;
&amp;lt;section name=&amp;quot;Code for important note above&amp;quot; class=&amp;quot;Important&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
This code might not work as you expect: The handler added here won't be called until the next time the event is triggered. On the other hand, removing events works as expected.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
addEvent(&amp;quot;eventName&amp;quot;)&lt;br /&gt;
addEventHandler(&amp;quot;eventName&amp;quot;, root, function()&lt;br /&gt;
    print(&amp;quot;Existing called&amp;quot;)&lt;br /&gt;
    addEventHandler(&amp;quot;eventName&amp;quot;, root, function()&lt;br /&gt;
        print(&amp;quot;newly added called&amp;quot;)&lt;br /&gt;
    end)&lt;br /&gt;
end)&lt;br /&gt;
-- first time calling the event&lt;br /&gt;
triggerEvent(&amp;quot;eventName&amp;quot;, root) -- prints &amp;quot;Existing called&amp;quot;&lt;br /&gt;
-- second time - now both handlers are called&lt;br /&gt;
triggerEvent(&amp;quot;eventName&amp;quot;, root) -- prints &amp;quot;Existing called&amp;quot;, &amp;quot;newly added called&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section name=&amp;quot;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
This serverside example sends a message to everyone in the server when a player spawns.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- define our handler function&lt;br /&gt;
function onPlayerSpawnHandler ( )&lt;br /&gt;
	-- get the player's name, source is the player because he was spawned&lt;br /&gt;
	local playerName = getPlayerName( source )&lt;br /&gt;
	-- output in the chat box that they've spawned&lt;br /&gt;
	outputChatBox ( playerName .. &amp;quot; has spawned!&amp;quot; )&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
addEventHandler( &amp;quot;onPlayerSpawn&amp;quot;, root, onPlayerSpawnHandler ) -- root is a predefined global variable for getRootElement()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Changelog==&lt;br /&gt;
{{ChangelogHeader}}&lt;br /&gt;
{{ChangelogItem|1.3.0-9.03795|Added priority argument}}&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Event_functions}}&lt;br /&gt;
[[ru:addEventHandler]]&lt;/div&gt;</summary>
		<author><name>Icensow</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=AddElementDataSubscriber&amp;diff=76308</id>
		<title>AddElementDataSubscriber</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=AddElementDataSubscriber&amp;diff=76308"/>
		<updated>2023-03-18T10:25:30Z</updated>

		<summary type="html">&lt;p&gt;Icensow: Notes about using the function&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server function}}&lt;br /&gt;
__NOTOC__ &lt;br /&gt;
{{New items|3.0158|1.5.7-9.20477|This function subscribes a [[player]] to specific [[element data]].&lt;br /&gt;
This function is used together with [[setElementData]] in ''&amp;quot;subscribe&amp;quot;'' mode.&lt;br /&gt;
}}&lt;br /&gt;
{{Note|Before using this function you need to setup an initial value of element data in ''&amp;quot;subscribe&amp;quot;'' mode, otherwise the subscriber will not be added.}}&lt;br /&gt;
{{Note|Calling [[removeElementData]] or [[setElementData]] with other sync mode will automatically remove all subscribers of specified element data.}}&lt;br /&gt;
&lt;br /&gt;
==Syntax== &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
bool addElementDataSubscriber ( element theElement, string key, player thePlayer )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
{{OOP||[[element]]:addDataSubscriber||removeElementDataSubscriber}}&lt;br /&gt;
&lt;br /&gt;
===Required Arguments=== &lt;br /&gt;
*'''theElement:''' The [[element]] you wish to subscribe the [[player]] to.&lt;br /&gt;
*'''key:''' The key you wish to subscribe the player to.&lt;br /&gt;
*'''thePlayer:''' The [[player]] you wish to subscribe.&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns ''true'' if the player was subscribed, ''false'' otherwise.&lt;br /&gt;
&lt;br /&gt;
==Example== &lt;br /&gt;
&amp;lt;section name=&amp;quot;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
addEventHandler(&amp;quot;onVehicleEnter&amp;quot;, getRootElement(), function(thePlayer, seat)&lt;br /&gt;
   if seat==0 then -- if the player is a driver&lt;br /&gt;
      addElementDataSubscriber(source, &amp;quot;id&amp;quot;, thePlayer) -- subscribe the player to element&lt;br /&gt;
   end&lt;br /&gt;
end)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
{{Requirements|1.5.7-9.20477|n/a|}}&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Element_functions}}&lt;/div&gt;</summary>
		<author><name>Icensow</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=GetColShapeType&amp;diff=63058</id>
		<title>GetColShapeType</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=GetColShapeType&amp;diff=63058"/>
		<updated>2019-06-22T09:41:18Z</updated>

		<summary type="html">&lt;p&gt;Icensow: /* Syntax */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server client function}}&lt;br /&gt;
__NOTOC__&lt;br /&gt;
{{New feature/item|3.0156|1.5.5|12286|This function is used to retrieve the type of an colshape.}}&lt;br /&gt;
&lt;br /&gt;
==Syntax== &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
int getColShapeType ( colshape shape )  &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
{{OOP||[[colshape]]:getShapeType|shapeType|}}&lt;br /&gt;
&lt;br /&gt;
===Required Arguments=== &lt;br /&gt;
*'''shape:''' The [[colshape]] you wish to get the type of.&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns ''false'' if invalid arguments were passed, or an [[int]]eger of the type of the colshape, which include:&lt;br /&gt;
*'''0:''' circle&lt;br /&gt;
*'''1:''' cuboid&lt;br /&gt;
*'''2:''' sphere&lt;br /&gt;
*'''3:''' rectangle&lt;br /&gt;
*'''4:''' polygon&lt;br /&gt;
*'''5:''' tube&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
This example outputs the type of all colshapes.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local circle = createColCircle(0, 0, 1)&lt;br /&gt;
local cubboid = createColCuboid(0, 0, 0, 0, 0, 0)&lt;br /&gt;
local sphere = createColSphere(0, 0, 0, 0)&lt;br /&gt;
local rectangle = createColRectangle(0, 0, 0, 0)&lt;br /&gt;
local polygon = createColPolygon(0, 0, 0, 0, 0, 0, 0, 0)&lt;br /&gt;
local tube = createColTube(0, 0, 0, 0, 0)&lt;br /&gt;
&lt;br /&gt;
iprint(&amp;quot;circle&amp;quot;, getColShapeType(circle), circle:getShapeType(), circle.shapeType)&lt;br /&gt;
iprint(&amp;quot;cubboid&amp;quot;, getColShapeType(cubboid), cubboid:getShapeType(), cubboid.shapeType)&lt;br /&gt;
iprint(&amp;quot;sphere&amp;quot;, getColShapeType(sphere), sphere:getShapeType(), sphere.shapeType)&lt;br /&gt;
iprint(&amp;quot;rectangle&amp;quot;, getColShapeType(rectangle), rectangle:getShapeType(), rectangle.shapeType)&lt;br /&gt;
iprint(&amp;quot;polygon&amp;quot;, getColShapeType(polygon), polygon:getShapeType(), polygon.shapeType)&lt;br /&gt;
iprint(&amp;quot;tube&amp;quot;, getColShapeType(tube), tube:getShapeType(), tube.shapeType)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Collision_shape_functions}}&lt;br /&gt;
&lt;br /&gt;
[[hu:getColShapeType]]&lt;/div&gt;</summary>
		<author><name>Icensow</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=GetColShapeType&amp;diff=63057</id>
		<title>GetColShapeType</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=GetColShapeType&amp;diff=63057"/>
		<updated>2019-06-22T09:40:34Z</updated>

		<summary type="html">&lt;p&gt;Icensow: /* Returns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server client function}}&lt;br /&gt;
__NOTOC__&lt;br /&gt;
{{New feature/item|3.0156|1.5.5|12286|This function is used to retrieve the type of an colshape.}}&lt;br /&gt;
&lt;br /&gt;
==Syntax== &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
string getColShapeType ( colshape shape )  &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
{{OOP||[[colshape]]:getShapeType|shapeType|}}&lt;br /&gt;
&lt;br /&gt;
===Required Arguments=== &lt;br /&gt;
*'''shape:''' The [[colshape]] you wish to get the type of.&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns ''false'' if invalid arguments were passed, or an [[int]]eger of the type of the colshape, which include:&lt;br /&gt;
*'''0:''' circle&lt;br /&gt;
*'''1:''' cuboid&lt;br /&gt;
*'''2:''' sphere&lt;br /&gt;
*'''3:''' rectangle&lt;br /&gt;
*'''4:''' polygon&lt;br /&gt;
*'''5:''' tube&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
This example outputs the type of all colshapes.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local circle = createColCircle(0, 0, 1)&lt;br /&gt;
local cubboid = createColCuboid(0, 0, 0, 0, 0, 0)&lt;br /&gt;
local sphere = createColSphere(0, 0, 0, 0)&lt;br /&gt;
local rectangle = createColRectangle(0, 0, 0, 0)&lt;br /&gt;
local polygon = createColPolygon(0, 0, 0, 0, 0, 0, 0, 0)&lt;br /&gt;
local tube = createColTube(0, 0, 0, 0, 0)&lt;br /&gt;
&lt;br /&gt;
iprint(&amp;quot;circle&amp;quot;, getColShapeType(circle), circle:getShapeType(), circle.shapeType)&lt;br /&gt;
iprint(&amp;quot;cubboid&amp;quot;, getColShapeType(cubboid), cubboid:getShapeType(), cubboid.shapeType)&lt;br /&gt;
iprint(&amp;quot;sphere&amp;quot;, getColShapeType(sphere), sphere:getShapeType(), sphere.shapeType)&lt;br /&gt;
iprint(&amp;quot;rectangle&amp;quot;, getColShapeType(rectangle), rectangle:getShapeType(), rectangle.shapeType)&lt;br /&gt;
iprint(&amp;quot;polygon&amp;quot;, getColShapeType(polygon), polygon:getShapeType(), polygon.shapeType)&lt;br /&gt;
iprint(&amp;quot;tube&amp;quot;, getColShapeType(tube), tube:getShapeType(), tube.shapeType)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Collision_shape_functions}}&lt;br /&gt;
&lt;br /&gt;
[[hu:getColShapeType]]&lt;/div&gt;</summary>
		<author><name>Icensow</name></author>
	</entry>
</feed>