<?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=F9SoOoL</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=F9SoOoL"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/wiki/Special:Contributions/F9SoOoL"/>
	<updated>2026-04-24T12:43:16Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=SetElementData&amp;diff=50560</id>
		<title>SetElementData</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=SetElementData&amp;diff=50560"/>
		<updated>2017-03-17T21:00:53Z</updated>

		<summary type="html">&lt;p&gt;F9SoOoL: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server client function}}&lt;br /&gt;
__NOTOC__ &lt;br /&gt;
This function stores [[element data]] under a certain key, attached to an element. Element data set using this is then synced with all clients and the server. The data can contain server created elements, but you should avoid passing data that is not able to be synced such as xmlnodes, acls, aclgroups etc.&lt;br /&gt;
&lt;br /&gt;
As element data is synced to all clients, it can generate a lot of network traffic and consume server CPU. Events are much more efficient for sending data from a client to the server only, or from the server to a specific client.&lt;br /&gt;
&lt;br /&gt;
{{Tip|A simple and efficient way to make a variable known to the server and clients is to use setElementData on the [[root]] element.}}&lt;br /&gt;
{{Note|See [[Script security]] for tips on preventing cheaters when using events and 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 setElementData ( element theElement, string key, var value [, bool synchronize = true ] )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
{{OOP||[[element]]:setData||getElementData}}&lt;br /&gt;
&lt;br /&gt;
===Required Arguments=== &lt;br /&gt;
*'''theElement:''' The [[element]] you wish to attach the data to.&lt;br /&gt;
*'''key:''' The key you wish to store the data under. (Maximum 31 characters.) &lt;br /&gt;
*'''value:''' The value you wish to store. See [[element data]] for a list of acceptable datatypes.&lt;br /&gt;
&lt;br /&gt;
===Optional Arguments=== &lt;br /&gt;
*'''synchronize:''' Determines whether or not the data will be synchronized with the server (client-side variation) and remote clients (both variations).&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns ''true'' if the data was set succesfully, ''false'' otherwise.&lt;br /&gt;
&lt;br /&gt;
===Issues===&lt;br /&gt;
{{Issues|&lt;br /&gt;
{{Issue|7389|[Fixed in 1.3.5-7389] Problem with floating numbers}}&lt;br /&gt;
}}&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;
This example allows a player to add a custom tag onto their nickname, and also reverts it back to normal if they wish.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function addPlayerCustomTag ( thePlayer, command, newTag )&lt;br /&gt;
	--Let's make sure the newTag param has been entered...&lt;br /&gt;
	if ( newTag ) then&lt;br /&gt;
		--Grab their current playername for saving.&lt;br /&gt;
		local sPlayerNickname = getPlayerName ( thePlayer )&lt;br /&gt;
		--Create their new nickname with their tag&lt;br /&gt;
		local sNewPlayerNickname = newTag .. &amp;quot; &amp;quot; .. sPlayerNickname&lt;br /&gt;
		&lt;br /&gt;
		--Let's first load the element data, see if it's there already&lt;br /&gt;
		--The reason for this is that if a player were to do /addtag twice,&lt;br /&gt;
		--the tag would be prepended a second time&lt;br /&gt;
		local sOldNick = getElementData( thePlayer, &amp;quot;tempdata.originalnick&amp;quot; )&lt;br /&gt;
		if ( sOldNick == false ) then&lt;br /&gt;
			--Save their orignal nickname in their element data&lt;br /&gt;
			setElementData ( thePlayer, &amp;quot;tempdata.originalnick&amp;quot;, sPlayerNickname )&lt;br /&gt;
		end&lt;br /&gt;
		&lt;br /&gt;
		--Set their new nickname globally&lt;br /&gt;
		setPlayerName ( thePlayer, sNewPlayerNickname )&lt;br /&gt;
		&lt;br /&gt;
		--Tell them it's done&lt;br /&gt;
		outputChatBox ( &amp;quot;Your new nickname has been set, to put it back to its original state you can use /deltag&amp;quot;, thePlayer )&lt;br /&gt;
	else&lt;br /&gt;
		--The newTag param was not entered, give an error message&lt;br /&gt;
		outputChatBox ( &amp;quot;/addtag - Incorrect syntax, Correct: /addtag &amp;lt;newtag&amp;gt;&amp;quot;, thePlayer )&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler ( &amp;quot;addtag&amp;quot;, addPlayerCustomTag )&lt;br /&gt;
&lt;br /&gt;
function removePlayerCustomTag ( thePlayer, command )&lt;br /&gt;
	--We first need to check that they have already used /addtag, let's do that now&lt;br /&gt;
	local sOldNick = getElementData( thePlayer, &amp;quot;tempdata.originalnick&amp;quot; )&lt;br /&gt;
	if ( sOldNick ) then&lt;br /&gt;
		--Great, they have a tag added, let's reset them&lt;br /&gt;
		&lt;br /&gt;
		--First we will want to reset the element data back to its default (that being false)&lt;br /&gt;
		setElementData ( thePlayer, &amp;quot;tempdata.originalnick&amp;quot;, false )&lt;br /&gt;
		&lt;br /&gt;
		--Now set the client name back&lt;br /&gt;
		setPlayerName( thePlayer, sOldNick )&lt;br /&gt;
		&lt;br /&gt;
		--Notify them&lt;br /&gt;
		outputChatBox ( &amp;quot;Your old nickname has been set&amp;quot;, thePlayer )&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler ( &amp;quot;deltag&amp;quot;, removePlayerCustomTag )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Element_functions}}&lt;/div&gt;</summary>
		<author><name>F9SoOoL</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=SetElementData&amp;diff=50559</id>
		<title>SetElementData</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=SetElementData&amp;diff=50559"/>
		<updated>2017-03-17T20:59:54Z</updated>

		<summary type="html">&lt;p&gt;F9SoOoL: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server client function}}&lt;br /&gt;
__NOTOC__ &lt;br /&gt;
This function stores [[element data]] under a certain key, attached to an element. Element data set using this is then synced with all clients and the server. The data can contain server created elements, but you should avoid passing data that is not able to be synced such as xmlnodes, acls, aclgroups etc.&lt;br /&gt;
&lt;br /&gt;
As element data is synced to all clients, it can generate a lot of network traffic and consume server CPU. Events are much more efficient for sending data from a client to the server only, or from the server to a specific client.&lt;br /&gt;
&lt;br /&gt;
{{Tip|A simple and efficient way to make a variable known to the server and clients is to use setElementData on the [[root]] element.}}&lt;br /&gt;
{{Note|See [[Script security]] for tips on preventing cheaters when using events and 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 setElementData ( element theElement, string key, var value [, bool synchronize = true ] )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
{{OOP||[[element]]:setData||getElementData}}&lt;br /&gt;
&lt;br /&gt;
===Required Arguments=== &lt;br /&gt;
*'''theElement:''' The [[element]] you wish to attach the data to.&lt;br /&gt;
*'''key:''' The key you wish to store the data under. (Maximum 31 characters.) &lt;br /&gt;
*'''value:''' The value you wish to store. See [[element data]] for a list of acceptable datatypes.&lt;br /&gt;
&lt;br /&gt;
===Optional Arguments=== &lt;br /&gt;
*'''synchronize:''' Determines whether or not the data will be synchronized with the server (client-side variation) and remote clients (both variations).&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns ''true'' if the data was set succesfully, ''false'' otherwise.&lt;br /&gt;
&lt;br /&gt;
===Issues===&lt;br /&gt;
{{Issues|&lt;br /&gt;
{{Issue|7389|[Fixed in 1.3.5-7389] Problem with floating numbers}}&lt;br /&gt;
}}&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;
This example allows a player to add a custom tag onto their nickname, and also reverts it back to normal if they wish.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function addPlayerCustomTag ( thePlayer, command, newTag )&lt;br /&gt;
	--Let's make sure the newTag param has been entered...&lt;br /&gt;
	if ( newTag ) then&lt;br /&gt;
		--Grab their current playername for saving.&lt;br /&gt;
		local sPlayerNickname = getPlayerName ( thePlayer )&lt;br /&gt;
		--Create their new nickname with their tag&lt;br /&gt;
		local sNewPlayerNickname = newTag .. &amp;quot; &amp;quot; .. sPlayerNickname&lt;br /&gt;
		&lt;br /&gt;
		--Let's first load the element data, see if it's there already&lt;br /&gt;
		--The reason for this is that if a player were to do /addtag twice,&lt;br /&gt;
		--the tag would be prepended a second time&lt;br /&gt;
		local sOldNick = getElementData( thePlayer, &amp;quot;tempdata.originalnick&amp;quot; )&lt;br /&gt;
		if ( sOldNick == false ) then&lt;br /&gt;
			--Save their orignal nickname in their element data&lt;br /&gt;
			setElementData ( thePlayer, &amp;quot;tempdata.originalnick&amp;quot;, sPlayerNickname )&lt;br /&gt;
		end&lt;br /&gt;
		&lt;br /&gt;
		--Set their new nickname globally&lt;br /&gt;
		setPlayerName ( thePlayer, sNewPlayerNickname )&lt;br /&gt;
		&lt;br /&gt;
		--Tell them it's done&lt;br /&gt;
		outputChatBox ( &amp;quot;Your new nickname has been set, to put it back to its original state you can use /deltag&amp;quot;, thePlayer )&lt;br /&gt;
	else&lt;br /&gt;
		--The newTag param was not entered, give an error message&lt;br /&gt;
		outputChatBox ( &amp;quot;/addtag - Incorrect syntax, Correct: /addtag &amp;lt;newtag&amp;gt;&amp;quot;, thePlayer )&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler ( &amp;quot;addtag&amp;quot;, addPlayerCustomTag )&lt;br /&gt;
&lt;br /&gt;
function removePlayerCustomTag ( thePlayer, command )&lt;br /&gt;
	--We first need to check that they have already used /addtag, let's do that now&lt;br /&gt;
	local sOldNick = getElementData( thePlayer, &amp;quot;tempdata.originalnick&amp;quot; )&lt;br /&gt;
	if ( sOldNick ) then&lt;br /&gt;
		--Great, they have a tag added, let's reset them&lt;br /&gt;
		&lt;br /&gt;
		--First we will want to reset the element data back to its default (that being false)&lt;br /&gt;
		setElementData ( thePlayer, &amp;quot;tempdata.originalnick&amp;quot;, false )&lt;br /&gt;
		&lt;br /&gt;
		--Now set the client name back&lt;br /&gt;
		setPlayerName( thePlayer, sOldNick )&lt;br /&gt;
		&lt;br /&gt;
		--Notify them&lt;br /&gt;
		outputChatBox ( &amp;quot;Your old nickname has been set&amp;quot;, thePlayer )&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler ( &amp;quot;deltag&amp;quot;, removePlayerCustomTag )&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Element_functions}}&lt;/div&gt;</summary>
		<author><name>F9SoOoL</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=SetElementData&amp;diff=50558</id>
		<title>SetElementData</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=SetElementData&amp;diff=50558"/>
		<updated>2017-03-17T20:59:27Z</updated>

		<summary type="html">&lt;p&gt;F9SoOoL: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server client function}}&lt;br /&gt;
__NOTOC__ &lt;br /&gt;
This function stores [[element data]] under a certain key, attached to an element. Element data set using this is then synced with all clients and the server. The data can contain server created elements, but you should avoid passing data that is not able to be synced such as xmlnodes, acls, aclgroups etc.&lt;br /&gt;
&lt;br /&gt;
As element data is synced to all clients, it can generate a lot of network traffic and consume server CPU. Events are much more efficient for sending data from a client to the server only, or from the server to a specific client.&lt;br /&gt;
&lt;br /&gt;
{{Tip|A simple and efficient way to make a variable known to the server and clients is to use setElementData on the [[root]] element.}}&lt;br /&gt;
{{Note|See [[Script security]] for tips on preventing cheaters when using events and 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 setElementData ( element theElement, string key, var value [, bool synchronize = true ] )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
{{OOP||[[element]]:setData||getElementData}}&lt;br /&gt;
&lt;br /&gt;
===Required Arguments=== &lt;br /&gt;
*'''theElement:''' The [[element]] you wish to attach the data to.&lt;br /&gt;
*'''key:''' The key you wish to store the data under. (Maximum 31 characters.) &lt;br /&gt;
*'''value:''' The value you wish to store. See [[element data]] for a list of acceptable datatypes.&lt;br /&gt;
&lt;br /&gt;
===Optional Arguments=== &lt;br /&gt;
*'''synchronize:''' Determines whether or not the data will be synchronized with the server (client-side variation) and remote clients (both variations).&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns ''true'' if the data was set succesfully, ''false'' otherwise.&lt;br /&gt;
&lt;br /&gt;
===Issues===&lt;br /&gt;
{{Issues|&lt;br /&gt;
{{Issue|7389|[Fixed in 1.3.5-7389] Problem with floating numbers}}&lt;br /&gt;
}}&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;
This example allows a player to add a custom tag onto their nickname, and also reverts it back to normal if they wish.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function addPlayerCustomTag ( thePlayer, command, newTag )&lt;br /&gt;
	--Let's make sure the newTag param has been entered...&lt;br /&gt;
	if ( newTag ) then&lt;br /&gt;
		--Grab their current playername for saving.&lt;br /&gt;
		local sPlayerNickname = getPlayerName ( thePlayer )&lt;br /&gt;
		--Create their new nickname with their tag&lt;br /&gt;
		local sNewPlayerNickname = newTag .. &amp;quot; &amp;quot; .. sPlayerNickname&lt;br /&gt;
		&lt;br /&gt;
		--Let's first load the element data, see if it's there already&lt;br /&gt;
		--The reason for this is that if a player were to do /addtag twice,&lt;br /&gt;
		--the tag would be prepended a second time&lt;br /&gt;
		local sOldNick = getElementData( thePlayer, &amp;quot;tempdata.originalnick&amp;quot; )&lt;br /&gt;
		if ( sOldNick == false ) then&lt;br /&gt;
			--Save their orignal nickname in their element data&lt;br /&gt;
			setElementData ( thePlayer, &amp;quot;tempdata.originalnick&amp;quot;, sPlayerNickname )&lt;br /&gt;
		end&lt;br /&gt;
		&lt;br /&gt;
		--Set their new nickname globally&lt;br /&gt;
		setPlayerName ( thePlayer, sNewPlayerNickname )&lt;br /&gt;
		&lt;br /&gt;
		--Tell them it's done&lt;br /&gt;
		outputChatBox ( &amp;quot;Your new nickname has been set, to put it back to its original state you can use /deltag&amp;quot;, thePlayer )&lt;br /&gt;
	else&lt;br /&gt;
		--The newTag param was not entered, give an error message&lt;br /&gt;
		outputChatBox ( &amp;quot;/addtag - Incorrect syntax, Correct: /addtag &amp;lt;newtag&amp;gt;&amp;quot;, thePlayer )&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler ( &amp;quot;addtag&amp;quot;, addPlayerCustomTag )&lt;br /&gt;
&lt;br /&gt;
function removePlayerCustomTag ( thePlayer, command )&lt;br /&gt;
	--We first need to check that they have already used /addtag, let's do that now&lt;br /&gt;
	local sOldNick = getElementData( thePlayer, &amp;quot;tempdata.originalnick&amp;quot; )&lt;br /&gt;
	if ( sOldNick ) then&lt;br /&gt;
		--Great, they have a tag added, let's reset them&lt;br /&gt;
		&lt;br /&gt;
		--First we will want to reset the element data back to its default (that being false)&lt;br /&gt;
		setElementData ( thePlayer, &amp;quot;tempdata.originalnick&amp;quot;, false )&lt;br /&gt;
		&lt;br /&gt;
		--Now set the client name back&lt;br /&gt;
		setPlayerName( thePlayer, sOldNick )&lt;br /&gt;
		&lt;br /&gt;
		--Notify them&lt;br /&gt;
		outputChatBox ( &amp;quot;Your old nickname has been set&amp;quot;, thePlayer )&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler ( &amp;quot;deltag&amp;quot;, removePlayerCustomTag )&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Element_functions}}&lt;/div&gt;</summary>
		<author><name>F9SoOoL</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=SetElementData&amp;diff=50557</id>
		<title>SetElementData</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=SetElementData&amp;diff=50557"/>
		<updated>2017-03-17T20:58:58Z</updated>

		<summary type="html">&lt;p&gt;F9SoOoL: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server client function}}&lt;br /&gt;
__NOTOC__ &lt;br /&gt;
This function stores [[element data]] under a certain key, attached to an element. Element data set using this is then synced with all clients and the server. The data can contain server created elements, but you should avoid passing data that is not able to be synced such as xmlnodes, acls, aclgroups etc.&lt;br /&gt;
&lt;br /&gt;
As element data is synced to all clients, it can generate a lot of network traffic and consume server CPU. Events are much more efficient for sending data from a client to the server only, or from the server to a specific client.&lt;br /&gt;
&lt;br /&gt;
{{Tip|A simple and efficient way to make a variable known to the server and clients is to use setElementData on the [[root]] element.}}&lt;br /&gt;
{{Note|See [[Script security]] for tips on preventing cheaters when using events and 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 setElementData ( element theElement, string key, var value [, bool synchronize = true ] )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
{{OOP||[[element]]:setData||getElementData}}&lt;br /&gt;
&lt;br /&gt;
===Required Arguments=== &lt;br /&gt;
*'''theElement:''' The [[element]] you wish to attach the data to.&lt;br /&gt;
*'''key:''' The key you wish to store the data under. (Maximum 31 characters.) &lt;br /&gt;
*'''value:''' The value you wish to store. See [[element data]] for a list of acceptable datatypes.&lt;br /&gt;
&lt;br /&gt;
===Optional Arguments=== &lt;br /&gt;
*'''synchronize:''' Determines whether or not the data will be synchronized with the server (client-side variation) and remote clients (both variations).&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns ''true'' if the data was set succesfully, ''false'' otherwise.&lt;br /&gt;
&lt;br /&gt;
===Issues===&lt;br /&gt;
{{Issues|&lt;br /&gt;
{{Issue|7389|[Fixed in 1.3.5-7389] Problem with floating numbers}}&lt;br /&gt;
}}&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;
This example allows a player to add a custom tag onto their nickname, and also reverts it back to normal if they wish.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function addPlayerCustomTag ( thePlayer, command, newTag )&lt;br /&gt;
	--Let's make sure the newTag param has been entered...&lt;br /&gt;
	if ( newTag ) then&lt;br /&gt;
		--Grab their current playername for saving.&lt;br /&gt;
		local sPlayerNickname = getPlayerName ( thePlayer )&lt;br /&gt;
		--Create their new nickname with their tag&lt;br /&gt;
		local sNewPlayerNickname = newTag .. &amp;quot; &amp;quot; .. sPlayerNickname&lt;br /&gt;
		&lt;br /&gt;
		--Let's first load the element data, see if it's there already&lt;br /&gt;
		--The reason for this is that if a player were to do /addtag twice,&lt;br /&gt;
		--the tag would be prepended a second time&lt;br /&gt;
		local sOldNick = getElementData( thePlayer, &amp;quot;tempdata.originalnick&amp;quot; )&lt;br /&gt;
		if ( sOldNick == false ) then&lt;br /&gt;
			--Save their orignal nickname in their element data&lt;br /&gt;
			setElementData ( thePlayer, &amp;quot;tempdata.originalnick&amp;quot;, sPlayerNickname )&lt;br /&gt;
		end&lt;br /&gt;
		&lt;br /&gt;
		--Set their new nickname globally&lt;br /&gt;
		setPlayerName ( thePlayer, sNewPlayerNickname )&lt;br /&gt;
		&lt;br /&gt;
		--Tell them it's done&lt;br /&gt;
		outputChatBox ( &amp;quot;Your new nickname has been set, to put it back to its original state you can use /deltag&amp;quot;, thePlayer )&lt;br /&gt;
	else&lt;br /&gt;
		--The newTag param was not entered, give an error message&lt;br /&gt;
		outputChatBox ( &amp;quot;/addtag - Incorrect syntax, Correct: /addtag &amp;lt;newtag&amp;gt;&amp;quot;, thePlayer )&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler ( &amp;quot;addtag&amp;quot;, addPlayerCustomTag )&lt;br /&gt;
&lt;br /&gt;
function removePlayerCustomTag ( thePlayer, command )&lt;br /&gt;
	--We first need to check that they have already used /addtag, let's do that now&lt;br /&gt;
	local sOldNick = getElementData( thePlayer, &amp;quot;tempdata.originalnick&amp;quot; )&lt;br /&gt;
	if ( sOldNick ) then&lt;br /&gt;
		--Great, they have a tag added, let's reset them&lt;br /&gt;
		&lt;br /&gt;
		--First we will want to reset the element data back to its default (that being false)&lt;br /&gt;
		setElementData ( thePlayer, &amp;quot;tempdata.originalnick&amp;quot;, false )&lt;br /&gt;
		&lt;br /&gt;
		--Now set the client name back&lt;br /&gt;
		setPlayerName( thePlayer, sOldNick )&lt;br /&gt;
		&lt;br /&gt;
		--Notify them&lt;br /&gt;
		outputChatBox ( &amp;quot;Your old nickname has been set&amp;quot;, thePlayer )&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler ( &amp;quot;deltag&amp;quot;, removePlayerCustomTag )&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Element_functions}}&lt;/div&gt;</summary>
		<author><name>F9SoOoL</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=SetElementHealth&amp;diff=49855</id>
		<title>SetElementHealth</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=SetElementHealth&amp;diff=49855"/>
		<updated>2016-11-17T17:01:05Z</updated>

		<summary type="html">&lt;p&gt;F9SoOoL: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server client function}}&lt;br /&gt;
__NOTOC__&lt;br /&gt;
This function sets the health for the specified [[element]]. This can be a [[ped]], [[object]] or a [[vehicle]].&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
bool setElementHealth ( element theElement, float newHealth )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{{OOP||[[element]]:setHealth|health|getElementHealth}}&lt;br /&gt;
&lt;br /&gt;
===Required Arguments===&lt;br /&gt;
*'''theElement:''' The [[ped]], [[vehicle]] or [[object]] whose health you want to set.&lt;br /&gt;
*'''newHealth:''' A float indicating the new health to set for the element.&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns ''true'' if the new health was set successfully, or ''false'' if invalid arguments were passed.&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;
This example adds a 'hpslap' console command that lets players &amp;quot;slap&amp;quot; others (doing 20 damage).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function hpSlap ( sourcePlayer, command, targetPlayerName )&lt;br /&gt;
    -- check if the user has access to it first&lt;br /&gt;
    if not hasObjectPermissionTo(sourcePlayer, &amp;quot;command.slap&amp;quot;, false) then&lt;br /&gt;
        outputChatBox ( &amp;quot;You cannot use this command.&amp;quot;, sourcePlayer )&lt;br /&gt;
        return false&lt;br /&gt;
    end&lt;br /&gt;
    -- look up the player to be slapped&lt;br /&gt;
    local targetPlayer = getPlayerFromName ( targetPlayerName )&lt;br /&gt;
    -- if there's a player with such name,&lt;br /&gt;
    if targetPlayer then&lt;br /&gt;
        -- subtract 20 from his health&lt;br /&gt;
        setElementHealth ( targetPlayer, getElementHealth(targetPlayer) - 20 )&lt;br /&gt;
    else&lt;br /&gt;
        -- otherwise, output an error message&lt;br /&gt;
        outputChatBox ( &amp;quot;There is no player named &amp;quot; .. targetPlayerName .. &amp;quot;!&amp;quot;, sourcePlayer )&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
-- add our function as a handler for &amp;quot;hpslap&amp;quot;&lt;br /&gt;
addCommandHandler ( &amp;quot;hpslap&amp;quot;, hpSlap )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&amp;lt;section name=&amp;quot;Example 1&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
This example setting health by a command.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function Health(player, command, amount)&lt;br /&gt;
setElementHealth(player, tonumber(amount))&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler(&amp;quot;set&amp;quot;, Health)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Element functions}}&lt;/div&gt;</summary>
		<author><name>F9SoOoL</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=SetElementData&amp;diff=49854</id>
		<title>SetElementData</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=SetElementData&amp;diff=49854"/>
		<updated>2016-11-17T16:56:36Z</updated>

		<summary type="html">&lt;p&gt;F9SoOoL: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server client function}}&lt;br /&gt;
__NOTOC__ &lt;br /&gt;
This function stores [[element data]] under a certain key, attached to an element. Element data set using this is then synced with all clients and the server. The data can contain server created elements, but you should avoid passing data that is not able to be synced such as xmlnodes, acls, aclgroups etc.&lt;br /&gt;
&lt;br /&gt;
As element data is synced to all clients, it can generate a lot of network traffic and consume server CPU. Events are much more efficient for sending data from a client to the server only, or from the server to a specific client.&lt;br /&gt;
&lt;br /&gt;
{{Tip|A simple and efficient way to make a variable known to the server and clients is to use setElementData on the [[root]] element.}}&lt;br /&gt;
{{Note|See [[Script security]] for tips on preventing cheaters when using events and 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 setElementData ( element theElement, string key, var value [, bool synchronize = true ] )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
{{OOP||[[element]]:setData||getElementData}}&lt;br /&gt;
&lt;br /&gt;
===Required Arguments=== &lt;br /&gt;
*'''theElement:''' The [[element]] you wish to attach the data to.&lt;br /&gt;
*'''key:''' The key you wish to store the data under. (Maximum 31 characters.) &lt;br /&gt;
*'''value:''' The value you wish to store. See [[element data]] for a list of acceptable datatypes.&lt;br /&gt;
&lt;br /&gt;
===Optional Arguments=== &lt;br /&gt;
*'''synchronize:''' Determines whether or not the data will be synchronized with the server (client-side variation) and remote clients (both variations).&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns ''true'' if the data was set succesfully, ''false'' otherwise.&lt;br /&gt;
&lt;br /&gt;
===Issues===&lt;br /&gt;
{{Issues|&lt;br /&gt;
{{Issue|7389|[Fixed in 1.3.5-7389] Problem with floating numbers}}&lt;br /&gt;
}}&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;
This example allows a player to add a custom tag onto their nickname, and also reverts it back to normal if they wish.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function addPlayerCustomTag ( thePlayer, command, newTag )&lt;br /&gt;
	--Let's make sure the newTag param has been entered...&lt;br /&gt;
	if ( newTag ) then&lt;br /&gt;
		--Grab their current playername for saving.&lt;br /&gt;
		local sPlayerNickname = getPlayerName ( thePlayer )&lt;br /&gt;
		--Create their new nickname with their tag&lt;br /&gt;
		local sNewPlayerNickname = newTag .. &amp;quot; &amp;quot; .. sPlayerNickname&lt;br /&gt;
		&lt;br /&gt;
		--Let's first load the element data, see if it's there already&lt;br /&gt;
		--The reason for this is that if a player were to do /addtag twice,&lt;br /&gt;
		--the tag would be prepended a second time&lt;br /&gt;
		local sOldNick = getElementData( thePlayer, &amp;quot;tempdata.originalnick&amp;quot; )&lt;br /&gt;
		if ( sOldNick == false ) then&lt;br /&gt;
			--Save their orignal nickname in their element data&lt;br /&gt;
			setElementData ( thePlayer, &amp;quot;tempdata.originalnick&amp;quot;, sPlayerNickname )&lt;br /&gt;
		end&lt;br /&gt;
		&lt;br /&gt;
		--Set their new nickname globally&lt;br /&gt;
		setPlayerName ( thePlayer, sNewPlayerNickname )&lt;br /&gt;
		&lt;br /&gt;
		--Tell them it's done&lt;br /&gt;
		outputChatBox ( &amp;quot;Your new nickname has been set, to put it back to its original state you can use /deltag&amp;quot;, thePlayer )&lt;br /&gt;
	else&lt;br /&gt;
		--The newTag param was not entered, give an error message&lt;br /&gt;
		outputChatBox ( &amp;quot;/addtag - Incorrect syntax, Correct: /addtag &amp;lt;newtag&amp;gt;&amp;quot;, thePlayer )&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler ( &amp;quot;addtag&amp;quot;, addPlayerCustomTag )&lt;br /&gt;
&lt;br /&gt;
function removePlayerCustomTag ( thePlayer, command )&lt;br /&gt;
	--We first need to check that they have already used /addtag, let's do that now&lt;br /&gt;
	local sOldNick = getElementData( thePlayer, &amp;quot;tempdata.originalnick&amp;quot; )&lt;br /&gt;
	if ( sOldNick ) then&lt;br /&gt;
		--Great, they have a tag added, let's reset them&lt;br /&gt;
		&lt;br /&gt;
		--First we will want to reset the element data back to its default (that being false)&lt;br /&gt;
		setElementData ( thePlayer, &amp;quot;tempdata.originalnick&amp;quot;, false )&lt;br /&gt;
		&lt;br /&gt;
		--Now set the client name back&lt;br /&gt;
		setPlayerName( thePlayer, sOldNick )&lt;br /&gt;
		&lt;br /&gt;
		--Notify them&lt;br /&gt;
		outputChatBox ( &amp;quot;Your old nickname has been set&amp;quot;, thePlayer )&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler ( &amp;quot;deltag&amp;quot;, removePlayerCustomTag )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&amp;lt;section name=&amp;quot;Example 2&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
This example is a script of resetting the score in tactics servers.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function Reset(source, cmd)&lt;br /&gt;
local player = source&lt;br /&gt;
setElementData(player, &amp;quot;Kills&amp;quot;, &amp;quot;0&amp;quot;) --Set kills 0&lt;br /&gt;
setElementData(player, &amp;quot;Deaths&amp;quot;, &amp;quot;0&amp;quot;) --Set Deaths 0&lt;br /&gt;
setElementData(player, &amp;quot;Damage&amp;quot;, &amp;quot;0&amp;quot;) --Set Damage 0&lt;br /&gt;
outputChatBox(&amp;quot;#ff0000[ Score ] : #ffffffScore Has been Resetted!&amp;quot;, player, 255, 0, 0, true) --Msg for the player&lt;br /&gt;
end    --End function&lt;br /&gt;
addCommandHandler(&amp;quot;reset&amp;quot;, Reset)  --The command&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Element_functions}}&lt;/div&gt;</summary>
		<author><name>F9SoOoL</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=SetElementData&amp;diff=49853</id>
		<title>SetElementData</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=SetElementData&amp;diff=49853"/>
		<updated>2016-11-17T16:55:18Z</updated>

		<summary type="html">&lt;p&gt;F9SoOoL: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server client function}}&lt;br /&gt;
__NOTOC__ &lt;br /&gt;
This function stores [[element data]] under a certain key, attached to an element. Element data set using this is then synced with all clients and the server. The data can contain server created elements, but you should avoid passing data that is not able to be synced such as xmlnodes, acls, aclgroups etc.&lt;br /&gt;
&lt;br /&gt;
As element data is synced to all clients, it can generate a lot of network traffic and consume server CPU. Events are much more efficient for sending data from a client to the server only, or from the server to a specific client.&lt;br /&gt;
&lt;br /&gt;
{{Tip|A simple and efficient way to make a variable known to the server and clients is to use setElementData on the [[root]] element.}}&lt;br /&gt;
{{Note|See [[Script security]] for tips on preventing cheaters when using events and 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 setElementData ( element theElement, string key, var value [, bool synchronize = true ] )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
{{OOP||[[element]]:setData||getElementData}}&lt;br /&gt;
&lt;br /&gt;
===Required Arguments=== &lt;br /&gt;
*'''theElement:''' The [[element]] you wish to attach the data to.&lt;br /&gt;
*'''key:''' The key you wish to store the data under. (Maximum 31 characters.) &lt;br /&gt;
*'''value:''' The value you wish to store. See [[element data]] for a list of acceptable datatypes.&lt;br /&gt;
&lt;br /&gt;
===Optional Arguments=== &lt;br /&gt;
*'''synchronize:''' Determines whether or not the data will be synchronized with the server (client-side variation) and remote clients (both variations).&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns ''true'' if the data was set succesfully, ''false'' otherwise.&lt;br /&gt;
&lt;br /&gt;
===Issues===&lt;br /&gt;
{{Issues|&lt;br /&gt;
{{Issue|7389|[Fixed in 1.3.5-7389] Problem with floating numbers}}&lt;br /&gt;
}}&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;
This example allows a player to add a custom tag onto their nickname, and also reverts it back to normal if they wish.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function addPlayerCustomTag ( thePlayer, command, newTag )&lt;br /&gt;
	--Let's make sure the newTag param has been entered...&lt;br /&gt;
	if ( newTag ) then&lt;br /&gt;
		--Grab their current playername for saving.&lt;br /&gt;
		local sPlayerNickname = getPlayerName ( thePlayer )&lt;br /&gt;
		--Create their new nickname with their tag&lt;br /&gt;
		local sNewPlayerNickname = newTag .. &amp;quot; &amp;quot; .. sPlayerNickname&lt;br /&gt;
		&lt;br /&gt;
		--Let's first load the element data, see if it's there already&lt;br /&gt;
		--The reason for this is that if a player were to do /addtag twice,&lt;br /&gt;
		--the tag would be prepended a second time&lt;br /&gt;
		local sOldNick = getElementData( thePlayer, &amp;quot;tempdata.originalnick&amp;quot; )&lt;br /&gt;
		if ( sOldNick == false ) then&lt;br /&gt;
			--Save their orignal nickname in their element data&lt;br /&gt;
			setElementData ( thePlayer, &amp;quot;tempdata.originalnick&amp;quot;, sPlayerNickname )&lt;br /&gt;
		end&lt;br /&gt;
		&lt;br /&gt;
		--Set their new nickname globally&lt;br /&gt;
		setPlayerName ( thePlayer, sNewPlayerNickname )&lt;br /&gt;
		&lt;br /&gt;
		--Tell them it's done&lt;br /&gt;
		outputChatBox ( &amp;quot;Your new nickname has been set, to put it back to its original state you can use /deltag&amp;quot;, thePlayer )&lt;br /&gt;
	else&lt;br /&gt;
		--The newTag param was not entered, give an error message&lt;br /&gt;
		outputChatBox ( &amp;quot;/addtag - Incorrect syntax, Correct: /addtag &amp;lt;newtag&amp;gt;&amp;quot;, thePlayer )&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler ( &amp;quot;addtag&amp;quot;, addPlayerCustomTag )&lt;br /&gt;
&lt;br /&gt;
function removePlayerCustomTag ( thePlayer, command )&lt;br /&gt;
	--We first need to check that they have already used /addtag, let's do that now&lt;br /&gt;
	local sOldNick = getElementData( thePlayer, &amp;quot;tempdata.originalnick&amp;quot; )&lt;br /&gt;
	if ( sOldNick ) then&lt;br /&gt;
		--Great, they have a tag added, let's reset them&lt;br /&gt;
		&lt;br /&gt;
		--First we will want to reset the element data back to its default (that being false)&lt;br /&gt;
		setElementData ( thePlayer, &amp;quot;tempdata.originalnick&amp;quot;, false )&lt;br /&gt;
		&lt;br /&gt;
		--Now set the client name back&lt;br /&gt;
		setPlayerName( thePlayer, sOldNick )&lt;br /&gt;
		&lt;br /&gt;
		--Notify them&lt;br /&gt;
		outputChatBox ( &amp;quot;Your old nickname has been set&amp;quot;, thePlayer )&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler ( &amp;quot;deltag&amp;quot;, removePlayerCustomTag )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&amp;lt;section name=&amp;quot;example 2&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
This example is a script of resetting the score in tactics servers.&lt;br /&gt;
axhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function Reset(source, cmd)&lt;br /&gt;
local player = source&lt;br /&gt;
setElementData(player, &amp;quot;Kills&amp;quot;, &amp;quot;0&amp;quot;) --Set kills 0&lt;br /&gt;
setElementData(player, &amp;quot;Deaths&amp;quot;, &amp;quot;0&amp;quot;) --Set Deaths 0&lt;br /&gt;
setElementData(player, &amp;quot;Damage&amp;quot;, &amp;quot;0&amp;quot;) --Set Damage 0&lt;br /&gt;
outputChatBox(&amp;quot;#ff0000[ Score ] : #ffffffScore Has been Resetted!&amp;quot;, player, 255, 0, 0, true) --Msg for the player&lt;br /&gt;
end    --End function&lt;br /&gt;
addCommandHandler(&amp;quot;reset&amp;quot;, Reset)  --The command&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Element_functions}}&lt;/div&gt;</summary>
		<author><name>F9SoOoL</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=OnPlayerSpawn&amp;diff=49851</id>
		<title>OnPlayerSpawn</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=OnPlayerSpawn&amp;diff=49851"/>
		<updated>2016-11-17T16:21:34Z</updated>

		<summary type="html">&lt;p&gt;F9SoOoL: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__ &lt;br /&gt;
{{Server event}}&lt;br /&gt;
This event is called when a player spawns.&lt;br /&gt;
&lt;br /&gt;
==Parameters==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
float posX, float posY, float posZ, float spawnRotation, team theTeam, int theSkin, int theInterior, int theDimension&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''posX''': The X position the player spawned at&lt;br /&gt;
*'''posY''': The Y position the player spawned at&lt;br /&gt;
*'''posZ''': The Z position the player spawned at&lt;br /&gt;
*'''spawnRotation''': The rotation the player spawned with&lt;br /&gt;
*'''theTeam''': The team the player spawned with&lt;br /&gt;
*'''theSkin''': The skin / model the player spawned with&lt;br /&gt;
*'''theInterior''': The interior the player spawned in&lt;br /&gt;
*'''theDimension''': The dimension the player spawned in&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Add the event's source in the section below --&amp;gt;&lt;br /&gt;
==Source==&lt;br /&gt;
The [[event system#Event source|source]] of this event is the [[player]] that just spawned.&lt;br /&gt;
&lt;br /&gt;
==Example==  &lt;br /&gt;
This example plays a sound when a player spawns.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- when a player spawns,&lt;br /&gt;
function player_Spawn ( posX, posY, posZ, spawnRotation, theTeam, theSkin, theInterior, theDimension )&lt;br /&gt;
	-- play a frontend sound for him&lt;br /&gt;
	playSoundFrontEnd ( source, 16 )&lt;br /&gt;
end&lt;br /&gt;
-- add the player_Spawn function as a handler for onPlayerSpawn&lt;br /&gt;
addEventHandler ( &amp;quot;onPlayerSpawn&amp;quot;, getRootElement(), player_Spawn )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section name=&amp;quot;Example 1&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
This example spawn the player in a specific place in the map.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function Spawn()&lt;br /&gt;
spawnPlayer(source, 0, 0, 0) --Change the positions&lt;br /&gt;
end    --End function&lt;br /&gt;
addEventHandler(&amp;quot;onPlayerSpawn&amp;quot;, getRootElement(), Spawn)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{See also/Server event|Player events}}&lt;/div&gt;</summary>
		<author><name>F9SoOoL</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=OnPlayerJoin&amp;diff=49850</id>
		<title>OnPlayerJoin</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=OnPlayerJoin&amp;diff=49850"/>
		<updated>2016-11-17T16:06:47Z</updated>

		<summary type="html">&lt;p&gt;F9SoOoL: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
{{Server event}}&lt;br /&gt;
This event is triggered when a player joins the server.&lt;br /&gt;
&lt;br /&gt;
==Parameters==&lt;br /&gt;
No parameters.&lt;br /&gt;
&lt;br /&gt;
==Source==&lt;br /&gt;
The source of this event is the [[player]] who joined.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
This example gets the joined client's name and sends him a welcome message including his name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- we register greetPlayer as a handler for the event&lt;br /&gt;
function greetPlayer ( )&lt;br /&gt;
	-- we store the player's name&lt;br /&gt;
	local joinedPlayerName = getPlayerName ( source )&lt;br /&gt;
	local serverName = getServerName( )&lt;br /&gt;
	-- and send him a greeting&lt;br /&gt;
	outputChatBox ( &amp;quot;Welcome &amp;quot; .. joinedPlayerName .. &amp;quot; to &amp;quot;.. serverName ..&amp;quot;!&amp;quot; , source, 255, 255, 255 )&lt;br /&gt;
end&lt;br /&gt;
addEventHandler ( &amp;quot;onPlayerJoin&amp;quot;, getRootElement(), greetPlayer )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
This example sets random color to every player who joins.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- create a table to save the color&lt;br /&gt;
ChatColors = {}&lt;br /&gt;
&lt;br /&gt;
-- sets colors when player join&lt;br /&gt;
function onJoin ()&lt;br /&gt;
        -- create a table to add rgb values. Index will be the player element&lt;br /&gt;
	ChatColors[source] = {math.random (50, 255), math.random (50, 255), math.random (50, 255)}&lt;br /&gt;
end&lt;br /&gt;
-- checks if player has sent a message&lt;br /&gt;
function onChat ( message, messageType )&lt;br /&gt;
	if messageType == 0 then&lt;br /&gt;
                -- use the table to get the saved rgb values&lt;br /&gt;
		outputChatBox ( getPlayerName ( source ) .. &amp;quot;: #E0D0B0&amp;quot; .. message, getRootElement(), ChatColors[source][1], ChatColors[source][2], ChatColors[source][3], true )&lt;br /&gt;
		cancelEvent()&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler ( &amp;quot;onPlayerJoin&amp;quot;, getRootElement(), onJoin)&lt;br /&gt;
addEventHandler ( &amp;quot;onPlayerChat&amp;quot;, getRootElement(), onChat )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;section name=&amp;quot;Example 1&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
This example rediercts any player joins to the server automatically to any other server, add the script for admin group.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function Redirect()&lt;br /&gt;
redirectPlayer (source, &amp;quot;server ip&amp;quot;, &amp;quot;server port&amp;quot;)&lt;br /&gt;
end    --End function&lt;br /&gt;
addEventHandler(&amp;quot;onPlayerJoin&amp;quot;, getRootElement(), Redirect)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{See also/Server event|Player events}}&lt;/div&gt;</summary>
		<author><name>F9SoOoL</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=OnPlayerWasted&amp;diff=49849</id>
		<title>OnPlayerWasted</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=OnPlayerWasted&amp;diff=49849"/>
		<updated>2016-11-17T15:54:40Z</updated>

		<summary type="html">&lt;p&gt;F9SoOoL: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__ &lt;br /&gt;
{{Server event}}&lt;br /&gt;
This event is triggered when a player is killed or dies.&lt;br /&gt;
&lt;br /&gt;
==Parameters==&lt;br /&gt;
{{New feature/item|3|1.0||&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
int totalAmmo, element killer, int killerWeapon, int bodypart, bool stealth&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
{{Deprecated_feature|3|1.0|&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
int totalAmmo, element killer, int killerWeapon, int bodypart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
*'''totalAmmo''': an integer representing the total ammo the victim had when he died.&lt;br /&gt;
*'''killer''': an [[element]] representing the player or vehicle who was the killer.  If there was no killer this is ''false''.&lt;br /&gt;
*'''killerWeapon''': an integer representing the [[Weapons|killer weapon]] or the [[Death Reasons|death reason]].&lt;br /&gt;
*'''bodypart''': an integer representing the bodypart ID the victim was hit on when he died.&lt;br /&gt;
{{BodyParts}}&lt;br /&gt;
*{{New feature/item|3|1.0||'''stealth''': boolean value representing whether or not this was a stealth kill}}&lt;br /&gt;
&lt;br /&gt;
==Source==&lt;br /&gt;
The [[event system#Event source|source]] of this event is the [[player]] that died or got killed.&lt;br /&gt;
&lt;br /&gt;
==Example== &lt;br /&gt;
This example prints the killer and bodypart to the chat when a player dies.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- register player_Wasted as a handler for onPlayerWasted&lt;br /&gt;
function player_Wasted ( ammo, attacker, weapon, bodypart )&lt;br /&gt;
	-- if there was an attacker&lt;br /&gt;
	if ( attacker ) then&lt;br /&gt;
		-- we declare our variable outside the following checks&lt;br /&gt;
		local tempString&lt;br /&gt;
		-- if the element that killed him was a player,&lt;br /&gt;
		if ( getElementType ( attacker ) == &amp;quot;player&amp;quot; ) then&lt;br /&gt;
			-- put the attacker, victim and weapon info in the string&lt;br /&gt;
			tempString = getPlayerName ( attacker )..&amp;quot; killed &amp;quot;..getPlayerName ( source )..&amp;quot; (&amp;quot;..getWeaponNameFromID ( weapon )..&amp;quot;)&amp;quot;&lt;br /&gt;
		-- else, if it was a vehicle,&lt;br /&gt;
		elseif ( getElementType ( attacker ) == &amp;quot;vehicle&amp;quot; ) then&lt;br /&gt;
			-- we'll get the name from the attacker vehicle's driver&lt;br /&gt;
			tempString = getPlayerName ( getVehicleController ( attacker ) )..&amp;quot; killed &amp;quot;..getPlayerName ( source )..&amp;quot; (&amp;quot;..getWeaponNameFromID ( weapon )..&amp;quot;)&amp;quot;&lt;br /&gt;
		end&lt;br /&gt;
		-- if the victim was shot in the head, append a special message&lt;br /&gt;
		if ( bodypart == 9 ) then&lt;br /&gt;
			tempString = tempString..&amp;quot; (HEADSHOT!)&amp;quot;&lt;br /&gt;
		-- else, just append the bodypart name&lt;br /&gt;
		else&lt;br /&gt;
			tempString = tempString..&amp;quot; (&amp;quot;..getBodyPartName ( bodypart )..&amp;quot;)&amp;quot;&lt;br /&gt;
		end&lt;br /&gt;
		-- display the message&lt;br /&gt;
		outputChatBox ( tempString )&lt;br /&gt;
	-- if there was no attacker,&lt;br /&gt;
	else&lt;br /&gt;
		-- output a death message without attacker info&lt;br /&gt;
		outputChatBox ( getPlayerName ( source )..&amp;quot; died. (&amp;quot;..getWeaponNameFromID ( weapon )..&amp;quot;) (&amp;quot;..getBodyPartName ( bodypart )..&amp;quot;)&amp;quot; )&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler ( &amp;quot;onPlayerWasted&amp;quot;, getRootElement(), player_Wasted )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And another example, this will spawn you in the middle of GTA SA world (x=0, y=0, z=3) after 2 seconds of your death&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
addEventHandler( &amp;quot;onPlayerWasted&amp;quot;, getRootElement( ),&lt;br /&gt;
	function()&lt;br /&gt;
		setTimer( spawnPlayer, 2000, 1, source, 0, 0, 3 )&lt;br /&gt;
	end&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;section name=&amp;quot;Example 1&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
This Example is a script for Tactics Servers , the script giving the killer health as a reward for killing.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function GiveHealth(ammo, killer, killerweapon, bodypart)&lt;br /&gt;
if ( killer ) and ( killer ~= source ) and ( (getElementHealth(killer)) ~= 100 ) --Here we have selcted that who will be gave a health is the killer&lt;br /&gt;
setElementHealth(killer, (getElementHealth(killer)) + 20) --He will get +20 health, if you want to reward him by sitting him health 100 you can just type 100 after (killer,&lt;br /&gt;
outputChatBox(&amp;quot;#ff0000[ Server ] : #ffff00You Have Got Health +20&amp;quot;,killer,255,0,0,true) --out put chat box for the killer&lt;br /&gt;
end      --End if&lt;br /&gt;
end      --End function&lt;br /&gt;
addEventHandler(&amp;quot;onPlayerWasted&amp;quot;, getRootElement(), GiveHealth)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{See also/Server event|Player events}}&lt;/div&gt;</summary>
		<author><name>F9SoOoL</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=OnPlayerChat&amp;diff=49848</id>
		<title>OnPlayerChat</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=OnPlayerChat&amp;diff=49848"/>
		<updated>2016-11-17T15:39:46Z</updated>

		<summary type="html">&lt;p&gt;F9SoOoL: /* Examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
{{Server event}}&lt;br /&gt;
This event is triggered when a player chats inside the chat box.&lt;br /&gt;
&lt;br /&gt;
==Parameters==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
string message, int messageType&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
*'''message''': A string representing the message typed into the chat.&lt;br /&gt;
*'''messageType''': An integer value representing the message type:&lt;br /&gt;
**'''0''': normal message&lt;br /&gt;
**'''1''': action message (/me)&lt;br /&gt;
**'''2''': team message&lt;br /&gt;
&lt;br /&gt;
==Source==&lt;br /&gt;
The [[event system#Event source|source]] of this event is the [[player]] who sent the chatbox message.&lt;br /&gt;
&lt;br /&gt;
==Cancel effect==&lt;br /&gt;
If this event is [[Event system#Canceling|canceled]], the game's chat system won't deliver the posts. You may use [[outputChatBox]] to send the messages then.&lt;br /&gt;
Cancelling this event also means the chat will not appear in the server console or logs. If you want chat logging, you will have to add a call to [[outputServerLog]] - See the second example.&lt;br /&gt;
&lt;br /&gt;
==Examples== &lt;br /&gt;
&lt;br /&gt;
&amp;lt;section name=&amp;quot;Example 1&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
This example limits receiving of chat messages to a spherical area around the player who sent the message, also blocking action and team text.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- define our chat radius&lt;br /&gt;
local chatRadius = 20 --units&lt;br /&gt;
&lt;br /&gt;
-- define a handler that will distribute the message to all nearby players&lt;br /&gt;
function sendMessageToNearbyPlayers( message, messageType )&lt;br /&gt;
    -- we will only send normal chat messages, action and team types will be ignored&lt;br /&gt;
    if messageType == 0 then&lt;br /&gt;
        -- get the chatting player's position&lt;br /&gt;
        local posX, posY, posZ = getElementPosition( source )&lt;br /&gt;
        &lt;br /&gt;
        -- create a sphere of the specified radius in that position&lt;br /&gt;
        local chatSphere = createColSphere( posX, posY, posZ, chatRadius )&lt;br /&gt;
        -- get a table all player elements inside it&lt;br /&gt;
        local nearbyPlayers = getElementsWithinColShape( chatSphere, &amp;quot;player&amp;quot; )&lt;br /&gt;
        -- and destroy the sphere, since we're done with it&lt;br /&gt;
        destroyElement( chatSphere )&lt;br /&gt;
        &lt;br /&gt;
        -- deliver the message to each player in that table&lt;br /&gt;
        for index, nearbyPlayer in ipairs( nearbyPlayers ) do&lt;br /&gt;
            outputChatBox( message, nearbyPlayer )&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
-- attach our new chat handler to onPlayerChat&lt;br /&gt;
addEventHandler( &amp;quot;onPlayerChat&amp;quot;, getRootElement(), sendMessageToNearbyPlayers )&lt;br /&gt;
&lt;br /&gt;
-- define another handler function that cancels the event so that the message won't be delivered through the &lt;br /&gt;
function blockChatMessage()&lt;br /&gt;
    cancelEvent()&lt;br /&gt;
end&lt;br /&gt;
-- attach it as a handler to onPlayerChat&lt;br /&gt;
addEventHandler( &amp;quot;onPlayerChat&amp;quot;, getRootElement(), blockChatMessage )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section name=&amp;quot;Example 2&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
This example implements colored player names in chat.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
--This function is executed when a player joins, it sets the player's name-tag color to a random color.&lt;br /&gt;
local function playerJoin()&lt;br /&gt;
	local red, green, blue = math.random (50, 255), math.random (50, 255), math.random (50, 255)&lt;br /&gt;
        setPlayerNametagColor(source, red, green, blue)&lt;br /&gt;
end&lt;br /&gt;
addEventHandler (&amp;quot;onPlayerJoin&amp;quot;, root, playerJoin)&lt;br /&gt;
&lt;br /&gt;
--This function is executed when a player says something in chat, it outputs the player's message, with their nick colored to match their name tag color.&lt;br /&gt;
local function playerChat(message, messageType)&lt;br /&gt;
	if messageType == 0 then --Global (main) chat&lt;br /&gt;
                cancelEvent()&lt;br /&gt;
                local red, green, blue = getPlayerNametagColor(source)&lt;br /&gt;
		outputChatBox(getPlayerName(source)..&amp;quot;: #FFFFFF&amp;quot;..message, root, red, green, blue, true )&lt;br /&gt;
		outputServerLog(&amp;quot;CHAT: &amp;quot;..getPlayerName(source)..&amp;quot;: &amp;quot;..message)--NOTE: Beacuse we cancelled the onPlayerChat event, we need to log chat manually.&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler(&amp;quot;onPlayerChat&amp;quot;, root, playerChat)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section name=&amp;quot;Example 3&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
This is a script for slap the player by a word in the chat.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
function Slap(thePlayer, msg)&lt;br /&gt;
if string.find(msg, 'slap') then  --Here we have put the word or the msg that will be used to slap the player&lt;br /&gt;
killPed (thePlayer, thePlayer) --This the action &amp;gt;&amp;gt; killing the player&lt;br /&gt;
end     --End if&lt;br /&gt;
end     --End function&lt;br /&gt;
addEventHandler(&amp;quot;onPlayerChat&amp;quot;, getRootElement(), Slap)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{See also/Server event|Player events}}&lt;/div&gt;</summary>
		<author><name>F9SoOoL</name></author>
	</entry>
</feed>