<?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=Carlos+Eduardo+Oliveira</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=Carlos+Eduardo+Oliveira"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/wiki/Special:Contributions/Carlos_Eduardo_Oliveira"/>
	<updated>2026-04-24T10:01:20Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=SetElementData&amp;diff=37303</id>
		<title>SetElementData</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=SetElementData&amp;diff=37303"/>
		<updated>2013-10-14T05:37:22Z</updated>

		<summary type="html">&lt;p&gt;Carlos Eduardo Oliveira: &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 or the server. As such you should avoid passing data that is not able to be synced into this function (i.e. xmlnodes, acls, aclgroups etc.) Server-created elements are able to be synced.&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;
&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;
{{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;
&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>Carlos Eduardo Oliveira</name></author>
	</entry>
</feed>