<?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=Wafamde</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=Wafamde"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/wiki/Special:Contributions/Wafamde"/>
	<updated>2026-05-15T01:05:24Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=GetBans&amp;diff=28537</id>
		<title>GetBans</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=GetBans&amp;diff=28537"/>
		<updated>2011-12-03T16:00:30Z</updated>

		<summary type="html">&lt;p&gt;Wafamde: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__ &lt;br /&gt;
{{Server function}}&lt;br /&gt;
This function will return a table over all the [[ban]] values in the server.&lt;br /&gt;
&lt;br /&gt;
==Syntax== &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
table getBans ()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns a [[table]] of all the [[ban]]s.&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;
'''Example 1:''' This example lists every ban when somebody types &amp;quot;/bans&amp;quot;. WARNING: This will spam chat (for the player that executed the command) if the server has a lot of bans.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function listBans ( playerSource )&lt;br /&gt;
local banList = getBans() -- Return a table of all the bans.&lt;br /&gt;
	--&lt;br /&gt;
	for banID, ban in ipairs ( banList ) do -- For every ban do the following...	&lt;br /&gt;
		--&lt;br /&gt;
		local nick = getBanNick ( ban ) -- Get the IP of the ban&lt;br /&gt;
		--&lt;br /&gt;
		if nick then&lt;br /&gt;
			outputChatBox ( &amp;quot;Ban #&amp;quot; .. banID .. &amp;quot;: &amp;quot; .. nick, playerSource , 255, 0, 0, true ) -- Output the ban.&lt;br /&gt;
		end&lt;br /&gt;
		--&lt;br /&gt;
	end&lt;br /&gt;
	--&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler ( &amp;quot;bans&amp;quot;, listBans ) -- Add &amp;quot;/bans&amp;quot; as the trigger for the function.&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;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;false&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 2:''' &amp;lt;br&amp;gt;&lt;br /&gt;
This example shows you how you can make a commandHandler that can return data about bans on record.&amp;lt;br&amp;gt;&lt;br /&gt;
In this example there are several ways to get the info you want.&amp;lt;br&amp;gt;&lt;br /&gt;
You can find the ban you are looking for by providing one or more of the following arguments: &amp;lt;br&amp;gt;&lt;br /&gt;
- IP			(The IP that has been banned)&amp;lt;br&amp;gt;&lt;br /&gt;
- Serial		(The Serial that has been banned)&amp;lt;br&amp;gt;&lt;br /&gt;
- Nick			(The Nick that has been banned)&amp;lt;br&amp;gt;&lt;br /&gt;
'''*You only have to provide ONE argument to find what you are looking for.*'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example there is also TWO ways of returning the info you want to see.&amp;lt;br&amp;gt;&lt;br /&gt;
Notice in the example that the ''' FORTH ''' argument is called ''' showOutput ''' .&amp;lt;br&amp;gt;&lt;br /&gt;
If ''' showOutput ''' is ' 1 ' then the server will return all the data on ONE line.&amp;lt;br&amp;gt;&lt;br /&gt;
If ''' showOutput ''' is anything else than ' 1 ' the server will return all data on seperate lines.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
An example of what the command could look like:&amp;lt;br&amp;gt;&lt;br /&gt;
''' /bans 192.168.0.10 0 0 1 '''	This example would look for the IP.&amp;lt;br&amp;gt;&lt;br /&gt;
''' /bans 0 NAME 0 1 '''	This example would look for the NAME.&amp;lt;br&amp;gt;&lt;br /&gt;
''' /bans 0 0 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 1 '''	This example would look for the Serial.&amp;lt;br&amp;gt;&lt;br /&gt;
'''*' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ' is not a serial. Replace it with the serial you want to find. (Amazing if you know one)*'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function findBanOnRecord( playerSource, cmd, iIp, iNick, iSerial, showOutput )&lt;br /&gt;
local allBans = getBans() 	-- Returns a table of all bans on record.&lt;br /&gt;
	--&lt;br /&gt;
	for banID, ban in ipairs ( allBans ) do 	-- Loop through all the bans to find our target.&lt;br /&gt;
		--&lt;br /&gt;
		local nick = getBanNick ( ban )&lt;br /&gt;
		local ip = getBanIP ( ban )&lt;br /&gt;
		local serial = getBanSerial( ban )&lt;br /&gt;
		local banTime = getBanTime( ban )&lt;br /&gt;
		local banReason = getBanReason ( ban ) &lt;br /&gt;
		&lt;br /&gt;
		&lt;br /&gt;
			-- If ' nick ' doesn't exist, we will use &amp;quot;N/A&amp;quot;&lt;br /&gt;
			if not nick then		&lt;br /&gt;
				nick = &amp;quot;N/A&amp;quot;&lt;br /&gt;
			end&lt;br /&gt;
			-- If ' ip ' doesn't exist, we will use &amp;quot;N/A&amp;quot;&lt;br /&gt;
			if not ip then			-- &lt;br /&gt;
				ip = &amp;quot;N/A&amp;quot;&lt;br /&gt;
			end&lt;br /&gt;
			-- If ' serial ' doesn't exist, we will use &amp;quot;N/A&amp;quot;&lt;br /&gt;
			if not serial then		-- &lt;br /&gt;
				serial = &amp;quot;N/A&amp;quot;&lt;br /&gt;
			end&lt;br /&gt;
			-- If ' banReason ' doesn't exist, we will use &amp;quot;N/A&amp;quot;&lt;br /&gt;
			if not banReason then&lt;br /&gt;
				banReason = &amp;quot;N/A&amp;quot;&lt;br /&gt;
			end&lt;br /&gt;
			&lt;br /&gt;
			&lt;br /&gt;
			&lt;br /&gt;
			if nick == iNick or ip == iIp or serial == iSerial then		-- If any of our input arguments match any bans.&lt;br /&gt;
				--&lt;br /&gt;
				if tonumber(showOutput) == 1 then		-- If we use ' 1 ' in the forth argument, all the data will be output on ONE line.&lt;br /&gt;
					outputChatBox ( &amp;quot;Ban #&amp;quot; .. banID .. &amp;quot; | Nick: &amp;quot; .. nick .. &amp;quot; | IP: &amp;quot; .. ip .. &amp;quot; | Serial: &amp;quot; .. serial .. &amp;quot; | BanTime: &amp;quot; .. banTime .. &amp;quot; | BanReason: &amp;quot; .. banReason, playerSource, 0, 153, 0, true ) &lt;br /&gt;
				else									-- If nothing or anything other than ' 1 ' is used in the forth argument, all the data will be output on seperate lines.&lt;br /&gt;
					outputChatBox ( &amp;quot;Ban #&amp;quot; .. banID, playerSource, 0, 153, 0, true )&lt;br /&gt;
					outputChatBox ( &amp;quot;Nick: &amp;quot; .. nick, playerSource, 0, 153, 0, true )&lt;br /&gt;
					outputChatBox ( &amp;quot;IP: &amp;quot; .. ip, playerSource, 0, 153, 0, true )&lt;br /&gt;
					outputChatBox ( &amp;quot;Serial: &amp;quot; .. serial, playerSource, 0, 153, 0, true )&lt;br /&gt;
					outputChatBox ( &amp;quot;BanTime: &amp;quot; .. banTime, playerSource, 0, 153, 0, true )&lt;br /&gt;
					outputChatBox ( &amp;quot;BanReason: &amp;quot; .. banReason, playerSource, 0, 153, 0, true )&lt;br /&gt;
				end&lt;br /&gt;
				--&lt;br /&gt;
			break		-- Break the loop when we have found our target.&lt;br /&gt;
			--&lt;br /&gt;
		end&lt;br /&gt;
		--&lt;br /&gt;
	end&lt;br /&gt;
	--&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler ( &amp;quot;bans&amp;quot;, listBans ) &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;
{{Admin functions}}&lt;br /&gt;
[[ru:getBans]]&lt;/div&gt;</summary>
		<author><name>Wafamde</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=GetBans&amp;diff=28536</id>
		<title>GetBans</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=GetBans&amp;diff=28536"/>
		<updated>2011-12-03T15:06:02Z</updated>

		<summary type="html">&lt;p&gt;Wafamde: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__ &lt;br /&gt;
{{Server function}}&lt;br /&gt;
This function will return a table over all the [[ban]] values in the server.&lt;br /&gt;
&lt;br /&gt;
==Syntax== &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
table getBans ()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns a [[table]] of all the [[ban]]s.&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;
'''Example 1:''' This example lists every ban when somebody types &amp;quot;/bans&amp;quot;. WARNING: This will spam chat (for the player that executed the command) if the server has a lot of bans.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function listBans ( playerSource )&lt;br /&gt;
local banList = getBans() -- Return a table of all the bans.&lt;br /&gt;
	--&lt;br /&gt;
	for banID, ban in ipairs ( banList ) do -- For every ban do the following...	&lt;br /&gt;
		--&lt;br /&gt;
		local nick = getBanNick ( ban ) -- Get the IP of the ban&lt;br /&gt;
		--&lt;br /&gt;
		if nick then&lt;br /&gt;
			outputChatBox ( &amp;quot;Ban #&amp;quot; .. banID .. &amp;quot;: &amp;quot; .. nick, playerSource , 255, 0, 0 ) -- Output the ban.&lt;br /&gt;
		end&lt;br /&gt;
		--&lt;br /&gt;
	end&lt;br /&gt;
	--&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler ( &amp;quot;bans&amp;quot;, listBans ) -- Add &amp;quot;/bans&amp;quot; as the trigger for the function.&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;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;false&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 2:''' &amp;lt;br&amp;gt;&lt;br /&gt;
This example shows you how you can make a commandHandler that can return data about bans on record.&amp;lt;br&amp;gt;&lt;br /&gt;
In this example there are several ways to get the info you want.&amp;lt;br&amp;gt;&lt;br /&gt;
You can find the ban you are looking for by providing one or more of the following arguments: &amp;lt;br&amp;gt;&lt;br /&gt;
- IP			(The IP that has been banned)&amp;lt;br&amp;gt;&lt;br /&gt;
- Serial		(The Serial that has been banned)&amp;lt;br&amp;gt;&lt;br /&gt;
- Nick			(The Nick that has been banned)&amp;lt;br&amp;gt;&lt;br /&gt;
'''*You only have to provide ONE argument to find what you are looking for.*'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example there is also TWO ways of returning the info you want to see.&amp;lt;br&amp;gt;&lt;br /&gt;
Notice in the example that the ''' FORTH ''' argument is called ''' showOutput ''' .&amp;lt;br&amp;gt;&lt;br /&gt;
If ''' showOutput ''' is ' 1 ' then the server will return all the data on ONE line.&amp;lt;br&amp;gt;&lt;br /&gt;
If ''' showOutput ''' is anything else than ' 1 ' the server will return all data on seperate lines.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
An example of what the command could look like:&amp;lt;br&amp;gt;&lt;br /&gt;
''' /bans 192.168.0.10 0 0 1 '''	This example would look for the IP.&amp;lt;br&amp;gt;&lt;br /&gt;
''' /bans 0 NAME 0 1 '''	This example would look for the NAME.&amp;lt;br&amp;gt;&lt;br /&gt;
''' /bans 0 0 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 1 '''	This example would look for the Serial.&amp;lt;br&amp;gt;&lt;br /&gt;
'''*' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ' is not a serial. Replace it with the serial you want to find. (Amazing if you know one)*'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function findBanOnRecord( playerSource, cmd, iIp, iNick, iSerial, showOutput )&lt;br /&gt;
local allBans = getBans() 	-- Returns a table of all bans on record.&lt;br /&gt;
	--&lt;br /&gt;
	for banID, ban in ipairs ( allBans ) do 	-- Loop through all the bans to find our target.&lt;br /&gt;
		--&lt;br /&gt;
		local nick = getBanNick ( ban )&lt;br /&gt;
		local ip = getBanIP ( ban )&lt;br /&gt;
		local serial = getBanSerial( ban )&lt;br /&gt;
		local banTime = getBanTime( ban )&lt;br /&gt;
		local banReason = getBanReason ( ban ) &lt;br /&gt;
		&lt;br /&gt;
		&lt;br /&gt;
			-- If ' nick ' doesn't exist, we will use &amp;quot;N/A&amp;quot;&lt;br /&gt;
			if not nick then		&lt;br /&gt;
				nick = &amp;quot;N/A&amp;quot;&lt;br /&gt;
			end&lt;br /&gt;
			-- If ' ip ' doesn't exist, we will use &amp;quot;N/A&amp;quot;&lt;br /&gt;
			if not ip then			-- &lt;br /&gt;
				ip = &amp;quot;N/A&amp;quot;&lt;br /&gt;
			end&lt;br /&gt;
			-- If ' serial ' doesn't exist, we will use &amp;quot;N/A&amp;quot;&lt;br /&gt;
			if not serial then		-- &lt;br /&gt;
				serial = &amp;quot;N/A&amp;quot;&lt;br /&gt;
			end&lt;br /&gt;
			-- If ' banReason ' doesn't exist, we will use &amp;quot;N/A&amp;quot;&lt;br /&gt;
			if not banReason then&lt;br /&gt;
				banReason = &amp;quot;N/A&amp;quot;&lt;br /&gt;
			end&lt;br /&gt;
			&lt;br /&gt;
			&lt;br /&gt;
			&lt;br /&gt;
			if nick == iNick or ip == iIp or serial == iSerial then		-- If any of our input arguments match any bans.&lt;br /&gt;
				--&lt;br /&gt;
				if tonumber(showOutput) == 1 then		-- If we use ' 1 ' in the forth argument, all the data will be output on ONE line.&lt;br /&gt;
					outputChatBox ( &amp;quot;Ban #&amp;quot; .. banID .. &amp;quot; | Nick: &amp;quot; .. nick .. &amp;quot; | IP: &amp;quot; .. ip .. &amp;quot; | Serial: &amp;quot; .. serial .. &amp;quot; | BanTime: &amp;quot; .. banTime .. &amp;quot; | BanReason: &amp;quot; .. banReason, playerSource, 0, 153, 0, true ) &lt;br /&gt;
				else									-- If nothing or anything other than ' 1 ' is used in the forth argument, all the data will be output on seperate lines.&lt;br /&gt;
					outputChatBox ( &amp;quot;Ban #&amp;quot; .. banID, playerSource, 0, 153, 0, true )&lt;br /&gt;
					outputChatBox ( &amp;quot;Nick: &amp;quot; .. nick, playerSource, 0, 153, 0, true )&lt;br /&gt;
					outputChatBox ( &amp;quot;IP: &amp;quot; .. ip, playerSource, 0, 153, 0, true )&lt;br /&gt;
					outputChatBox ( &amp;quot;Serial: &amp;quot; .. serial, playerSource, 0, 153, 0, true )&lt;br /&gt;
					outputChatBox ( &amp;quot;BanTime: &amp;quot; .. banTime, playerSource, 0, 153, 0, true )&lt;br /&gt;
					outputChatBox ( &amp;quot;BanReason: &amp;quot; .. banReason, playerSource, 0, 153, 0, true )&lt;br /&gt;
				end&lt;br /&gt;
				--&lt;br /&gt;
			break		-- Break the loop when we have found our target.&lt;br /&gt;
			--&lt;br /&gt;
		end&lt;br /&gt;
		--&lt;br /&gt;
	end&lt;br /&gt;
	--&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler ( &amp;quot;bans&amp;quot;, listBans ) &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;
{{Admin functions}}&lt;br /&gt;
[[ru:getBans]]&lt;/div&gt;</summary>
		<author><name>Wafamde</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=GetBans&amp;diff=28535</id>
		<title>GetBans</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=GetBans&amp;diff=28535"/>
		<updated>2011-12-03T15:01:31Z</updated>

		<summary type="html">&lt;p&gt;Wafamde: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__ &lt;br /&gt;
{{Server function}}&lt;br /&gt;
This function will return a table over all the [[ban]] values in the server.&lt;br /&gt;
&lt;br /&gt;
==Syntax== &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
table getBans ()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns a [[table]] of all the [[ban]]s.&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;
'''Example 1:''' This example lists every ban when somebody types &amp;quot;/bans&amp;quot;. WARNING: This will spam chat (for the player that executed the command) if the server has a lot of bans.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function listBans ( playerSource )&lt;br /&gt;
local banList = getBans() -- Return a table of all the bans.&lt;br /&gt;
	--&lt;br /&gt;
	for banID, ban in ipairs ( banList ) do -- For every ban do the following...	&lt;br /&gt;
		--&lt;br /&gt;
		local nick = getBanNick ( ban ) -- Get the IP of the ban&lt;br /&gt;
		--&lt;br /&gt;
		if nick then&lt;br /&gt;
			outputChatBox ( &amp;quot;Ban #&amp;quot; .. banID .. &amp;quot;: &amp;quot; .. nick, playerSource , 255, 0, 0 ) -- Output the ban.&lt;br /&gt;
		end&lt;br /&gt;
		--&lt;br /&gt;
	end&lt;br /&gt;
	--&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler ( &amp;quot;bans&amp;quot;, listBans ) -- Add &amp;quot;/bans&amp;quot; as the trigger for the function.&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;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;false&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 2:''' &amp;lt;br&amp;gt;&lt;br /&gt;
This example shows you how you can make a commandHandler that can return data about bans on record.&amp;lt;br&amp;gt;&lt;br /&gt;
In this example there are several ways to get the info you want.&amp;lt;br&amp;gt;&lt;br /&gt;
You can find the ban you are looking for by providing one or more of the following arguments: &amp;lt;br&amp;gt;&lt;br /&gt;
- IP			(The IP that has been banned)&amp;lt;br&amp;gt;&lt;br /&gt;
- Serial		(The Serial that has been banned)&amp;lt;br&amp;gt;&lt;br /&gt;
- Nick			(The Nick that has been banned)&amp;lt;br&amp;gt;&lt;br /&gt;
'''*You only have to provide ONE argument to find what you are looking for.*'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example there is also TWO ways of returning the info you want to see.&amp;lt;br&amp;gt;&lt;br /&gt;
Notice in the example that the ''' FORTH ''' argument is called ''' showOutput ''' .&amp;lt;br&amp;gt;&lt;br /&gt;
If ''' showOutput ''' is ' 1 ' then the server will return all the data on ONE line.&amp;lt;br&amp;gt;&lt;br /&gt;
If ''' showOutput ''' is anything else than ' 1 ' the server will return all data on seperate lines.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
An example of what the command could look like:&amp;lt;br&amp;gt;&lt;br /&gt;
''' /bans 192.168.0.10 0 0 1 '''	This example would look for the IP.&amp;lt;br&amp;gt;&lt;br /&gt;
''' /bans 0 NAME 0 1 '''	This example would look for the NAME.&amp;lt;br&amp;gt;&lt;br /&gt;
''' /bans 0 0 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 1 '''	This example would look for the Serial.&amp;lt;br&amp;gt;&lt;br /&gt;
'''*' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ' is not a serial. Replace it with the serial you want to find. (Amazing if you know one)*'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function findBanOnRecord( playerSource, cmd, iIp, iNick, iSerial, showOutput )&lt;br /&gt;
local allBans = getBans() 	-- Returns a table of all bans on record.&lt;br /&gt;
	--&lt;br /&gt;
	for banID, ban in ipairs ( allBans ) do 	-- Loop through all the bans to find our target.&lt;br /&gt;
		--&lt;br /&gt;
		local nick = getBanNick ( ban )&lt;br /&gt;
		local ip = getBanIP ( ban )&lt;br /&gt;
		local serial = getBanSerial( ban )&lt;br /&gt;
		local banTime = getBanTime( ban )&lt;br /&gt;
		local banReason = getBanReason ( ban ) &lt;br /&gt;
			--&lt;br /&gt;
			if not nick then		-- if ' nick ' doesn't exist, we will use &amp;quot;N/A&amp;quot;&lt;br /&gt;
				nick = &amp;quot;N/A&amp;quot;&lt;br /&gt;
			end&lt;br /&gt;
			--&lt;br /&gt;
			if not ip then			-- if ' ip ' doesn't exist, we will use &amp;quot;N/A&amp;quot;&lt;br /&gt;
				ip = &amp;quot;N/A&amp;quot;&lt;br /&gt;
			end&lt;br /&gt;
			--&lt;br /&gt;
			if not serial then		-- if ' serial ' doesn't exist, we will use &amp;quot;N/A&amp;quot;&lt;br /&gt;
				serial = &amp;quot;N/A&amp;quot;&lt;br /&gt;
			end&lt;br /&gt;
			--&lt;br /&gt;
			if not banReason then 	-- if ' banReason ' doesn't exist, we will use &amp;quot;N/A&amp;quot;&lt;br /&gt;
				banReason = &amp;quot;N/A&amp;quot;&lt;br /&gt;
			end&lt;br /&gt;
			--&lt;br /&gt;
			if nick == iNick or ip == iIp or serial == iSerial then		-- If any of our input arguments match any bans.&lt;br /&gt;
				--&lt;br /&gt;
				if tonumber(showOutput) == 1 then		-- If we use ' 1 ' in the forth argument, all the data will be output on ONE line.&lt;br /&gt;
					outputChatBox ( &amp;quot;Ban #&amp;quot; .. banID .. &amp;quot; | Nick: &amp;quot; .. nick .. &amp;quot; | IP: &amp;quot; .. ip .. &amp;quot; | Serial: &amp;quot; .. serial .. &amp;quot; | BanTime: &amp;quot; .. banTime .. &amp;quot; | BanReason: &amp;quot; .. banReason, playerSource, 0, 153, 0, true ) &lt;br /&gt;
				else									-- If nothing or anything other than ' 1 ' is used in the forth argument, all the data will be output on seperate lines.&lt;br /&gt;
					outputChatBox ( &amp;quot;Ban #&amp;quot; .. banID, playerSource, 0, 153, 0, true )&lt;br /&gt;
					outputChatBox ( &amp;quot;Nick: &amp;quot; .. nick, playerSource, 0, 153, 0, true )&lt;br /&gt;
					outputChatBox ( &amp;quot;IP: &amp;quot; .. ip, playerSource, 0, 153, 0, true )&lt;br /&gt;
					outputChatBox ( &amp;quot;Serial: &amp;quot; .. serial, playerSource, 0, 153, 0, true )&lt;br /&gt;
					outputChatBox ( &amp;quot;BanTime: &amp;quot; .. banTime, playerSource, 0, 153, 0, true )&lt;br /&gt;
					outputChatBox ( &amp;quot;BanReason: &amp;quot; .. banReason, playerSource, 0, 153, 0, true )&lt;br /&gt;
				end&lt;br /&gt;
				--&lt;br /&gt;
			break		-- Break the loop when we have found our target.&lt;br /&gt;
			--&lt;br /&gt;
		end&lt;br /&gt;
		--&lt;br /&gt;
	end&lt;br /&gt;
	--&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler ( &amp;quot;bans&amp;quot;, listBans ) &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;
{{Admin functions}}&lt;br /&gt;
[[ru:getBans]]&lt;/div&gt;</summary>
		<author><name>Wafamde</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=GetBans&amp;diff=28534</id>
		<title>GetBans</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=GetBans&amp;diff=28534"/>
		<updated>2011-12-03T14:58:36Z</updated>

		<summary type="html">&lt;p&gt;Wafamde: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__ &lt;br /&gt;
{{Server function}}&lt;br /&gt;
This function will return a table over all the [[ban]] values in the server.&lt;br /&gt;
&lt;br /&gt;
==Syntax== &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
table getBans ()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns a [[table]] of all the [[ban]]s.&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;
'''Example 1:''' This example lists every ban when somebody types &amp;quot;/bans&amp;quot;. WARNING: This will spam chat (for the player that executed the command) if the server has a lot of bans.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function listBans ( playerSource )&lt;br /&gt;
local banList = getBans() -- Return a table of all the bans.&lt;br /&gt;
	--&lt;br /&gt;
	for banID, ban in ipairs ( banList ) do -- For every ban do the following...	&lt;br /&gt;
		--&lt;br /&gt;
		local nick = getBanNick ( ban ) -- Get the IP of the ban&lt;br /&gt;
		--&lt;br /&gt;
		if nick then&lt;br /&gt;
			outputChatBox ( &amp;quot;Ban #&amp;quot; .. banID .. &amp;quot;: &amp;quot; .. nick, playerSource , 255, 0, 0 ) -- Output the ban.&lt;br /&gt;
		end&lt;br /&gt;
		--&lt;br /&gt;
	end&lt;br /&gt;
	--&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler ( &amp;quot;bans&amp;quot;, listBans ) -- Add &amp;quot;/bans&amp;quot; as the trigger for the function.&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;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;false&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 2:''' &amp;lt;br&amp;gt;&lt;br /&gt;
This example shows you how you can make a commandHandler that can return data about bans on record.&amp;lt;br&amp;gt;&lt;br /&gt;
In this example there are several ways to get the info you want.&amp;lt;br&amp;gt;&lt;br /&gt;
You can find the ban you are looking for by providing one or more of the following arguments: &amp;lt;br&amp;gt;&lt;br /&gt;
- IP			(The IP that has been banned)&amp;lt;br&amp;gt;&lt;br /&gt;
- Serial		(The Serial that has been banned)&amp;lt;br&amp;gt;&lt;br /&gt;
- Nick			(The Nick that has been banned)&amp;lt;br&amp;gt;&lt;br /&gt;
'''*You only have to provide ONE argument to find what you are looking for.*'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example there is also TWO ways of returning the info you want to see.&amp;lt;br&amp;gt;&lt;br /&gt;
Notice in the example that the ''' FORTH ''' argument is called ''' showOutput ''' .&amp;lt;br&amp;gt;&lt;br /&gt;
If ''' showOutput ''' is ' 1 ' then the server will return all the data on ONE line.&amp;lt;br&amp;gt;&lt;br /&gt;
If ''' showOutput ''' is anything else than ' 1 ' the server will return all data on seperate lines.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
An example of what the command could look like:&amp;lt;br&amp;gt;&lt;br /&gt;
''' /bans 192.168.0.10 0 0 1 '''	This example would look for the IP.&amp;lt;br&amp;gt;&lt;br /&gt;
''' /bans 0 NAME 0 1 '''	This example would look for the NAME.&amp;lt;br&amp;gt;&lt;br /&gt;
''' /bans 0 0 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 1 '''	This example would look for the Serial.&amp;lt;br&amp;gt;&lt;br /&gt;
'''*' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ' is not a serial. Replace it with the serial you want to find. (Amazing if you know one)*'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function findBanOnRecord( playerSource, cmd, iIp, iNick, iSerial, showOutput )&lt;br /&gt;
local allBans = getBans() 	-- Returns a table of all bans on record.&lt;br /&gt;
	--&lt;br /&gt;
	for banID, ban in ipairs ( allBans ) do 	-- Loop through all the bans to find our target.&lt;br /&gt;
		--&lt;br /&gt;
		local nick = getBanNick ( ban )&lt;br /&gt;
		local ip = getBanIP ( ban )&lt;br /&gt;
		local serial = getBanSerial( ban )&lt;br /&gt;
		local banTime = getBanTime( ban )&lt;br /&gt;
		local banReason = getBanReason ( ban ) &lt;br /&gt;
		&lt;br /&gt;
			if not nick then		-- if ' nick ' doesn't exist, we will use &amp;quot;N/A&amp;quot;&lt;br /&gt;
				nick = &amp;quot;N/A&amp;quot;&lt;br /&gt;
			end&lt;br /&gt;
			&lt;br /&gt;
			if not ip then			-- if ' ip ' doesn't exist, we will use &amp;quot;N/A&amp;quot;&lt;br /&gt;
				ip = &amp;quot;N/A&amp;quot;&lt;br /&gt;
			end&lt;br /&gt;
			&lt;br /&gt;
			if not serial then		-- if ' serial ' doesn't exist, we will use &amp;quot;N/A&amp;quot;&lt;br /&gt;
				serial = &amp;quot;N/A&amp;quot;&lt;br /&gt;
			end&lt;br /&gt;
			&lt;br /&gt;
			if not banReason then 	-- if ' banReason ' doesn't exist, we will use &amp;quot;N/A&amp;quot;&lt;br /&gt;
				banReason = &amp;quot;N/A&amp;quot;&lt;br /&gt;
			end&lt;br /&gt;
		&lt;br /&gt;
		if nick == iNick or ip == iIp or serial == iSerial then		-- If any of our input arguments match any bans.&lt;br /&gt;
			if tonumber(showOutput) == 1 then		-- If we use ' 1 ' in the forth argument, all the data will be output on ONE line.&lt;br /&gt;
				outputChatBox ( &amp;quot;Ban #&amp;quot; .. banID .. &amp;quot; | Nick: &amp;quot; .. nick .. &amp;quot; | IP: &amp;quot; .. ip .. &amp;quot; | Serial: &amp;quot; .. serial .. &amp;quot; | BanTime: &amp;quot; .. banTime .. &amp;quot; | BanReason: &amp;quot; .. banReason, playerSource, 0, 153, 0, true ) &lt;br /&gt;
			else									-- If nothing or anything other than ' 1 ' is used in the forth argument, all the data will be output on seperate lines.&lt;br /&gt;
				outputChatBox ( &amp;quot;Ban #&amp;quot; .. banID, playerSource, 0, 153, 0, true )&lt;br /&gt;
				outputChatBox ( &amp;quot;Nick: &amp;quot; .. nick, playerSource, 0, 153, 0, true )&lt;br /&gt;
				outputChatBox ( &amp;quot;IP: &amp;quot; .. ip, playerSource, 0, 153, 0, true )&lt;br /&gt;
				outputChatBox ( &amp;quot;Serial: &amp;quot; .. serial, playerSource, 0, 153, 0, true )&lt;br /&gt;
				outputChatBox ( &amp;quot;BanTime: &amp;quot; .. banTime, playerSource, 0, 153, 0, true )&lt;br /&gt;
				outputChatBox ( &amp;quot;BanReason: &amp;quot; .. banReason, playerSource, 0, 153, 0, true )&lt;br /&gt;
			end&lt;br /&gt;
			break		-- Break the loop when we have found our target.&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler ( &amp;quot;bans&amp;quot;, listBans ) &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;
{{Admin functions}}&lt;br /&gt;
[[ru:getBans]]&lt;/div&gt;</summary>
		<author><name>Wafamde</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=GetBans&amp;diff=28533</id>
		<title>GetBans</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=GetBans&amp;diff=28533"/>
		<updated>2011-12-03T06:35:13Z</updated>

		<summary type="html">&lt;p&gt;Wafamde: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__ &lt;br /&gt;
{{Server function}}&lt;br /&gt;
This function will return a table over all the [[ban]] values in the server.&lt;br /&gt;
&lt;br /&gt;
==Syntax== &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
table getBans ()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns a [[table]] of all the [[ban]]s.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
This example lists every ban when somebody types &amp;quot;/bans&amp;quot;. WARNING: This will spam chat (for the player that executed the command) if the server has a lot of bans.&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;
function listBans ( playerSource )&lt;br /&gt;
local banList = getBans() -- Return a table of all the bans.&lt;br /&gt;
	--&lt;br /&gt;
	for banID, ban in ipairs ( banList ) do -- For every ban do the following...	&lt;br /&gt;
		--&lt;br /&gt;
		local nick = getBanNick ( ban ) -- Get the IP of the ban&lt;br /&gt;
		--&lt;br /&gt;
		if nick then&lt;br /&gt;
			outputChatBox ( &amp;quot;Ban #&amp;quot; .. banID .. &amp;quot;: &amp;quot; .. nick, playerSource , 255, 0, 0 ) -- Output the ban.&lt;br /&gt;
		end&lt;br /&gt;
		--&lt;br /&gt;
	end&lt;br /&gt;
	--&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler ( &amp;quot;bans&amp;quot;, listBans ) -- Add &amp;quot;/bans&amp;quot; as the trigger for the function.&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;
{{Admin functions}}&lt;br /&gt;
[[ru:getBans]]&lt;/div&gt;</summary>
		<author><name>Wafamde</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=AddCommandHandler&amp;diff=28517</id>
		<title>AddCommandHandler</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=AddCommandHandler&amp;diff=28517"/>
		<updated>2011-11-30T17:20:33Z</updated>

		<summary type="html">&lt;p&gt;Wafamde: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__ &lt;br /&gt;
{{Server client function}}&lt;br /&gt;
{{Note_box|It is strongly advised that you do not use the same name for your handler function as the command name, as this can lead to confusion if multiple handler functions are used. Use a name that describes your handler's purpose more specifically.}}&lt;br /&gt;
This function will attach a scripting function (handler) to a console command, so that whenever a player or administrator uses the command the function is called.&lt;br /&gt;
&lt;br /&gt;
Multiple command handlers can be attached to a single command, and they will be called in the order that the handlers were attached. Equally, multiple commands can be handled by a single function, and the ''commandName'' parameter used to decide the course of action.&lt;br /&gt;
&lt;br /&gt;
For users, a command is in the format:&lt;br /&gt;
&lt;br /&gt;
''commandName'' ''argument1'' ''argument2''&lt;br /&gt;
&lt;br /&gt;
This can be triggered from the player's console or directly from the chat box by prefixing the message with a forward slash (''/''). For server side handlers, the server admin is also able to trigger these directly from the server's console in the same way as they are triggered from a player's console.&lt;br /&gt;
&lt;br /&gt;
==Syntax== &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;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
bool addCommandHandler ( string commandName, function handlerFunction, [bool restricted = false, bool caseSensitive = true] )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
===Required Arguments===&lt;br /&gt;
*'''commandName:''' This is the name of the command you wish to attach a handler to. This is what must be typed into the console to trigger the function.&lt;br /&gt;
*'''handlerFunction:''' This is the function that you want the command to trigger, which has to be defined before you add the handler. This function can take two parameters, playerSource and commandName, followed by as many parameters you expect after your command (see below). These are all optional.&lt;br /&gt;
===Optional Arguments=== &lt;br /&gt;
{{OptionalArg}} &lt;br /&gt;
*'''restricted:''' Specify whether or not this command should be restricted by default. Use this on commands that should be inaccessible to everyone as default except special users specified in the ACL (Access Control List). This is to make sure admin commands such as ie. 'punish' won't be available to everyone if a server administrator forgets masking it in ACL. Make sure to add the command to your ACL under the proper group for it to be usefull (i.e &amp;lt;right name=&amp;quot;command.killEveryone&amp;quot; access=&amp;quot;true&amp;quot;&amp;gt;&amp;lt;/right&amp;gt;). This argument defaults to false if nothing is specified.&lt;br /&gt;
{{New feature|3|1.0|&lt;br /&gt;
*'''caseSensitive:''' Specifies if the command handler will ignore the case for this command name.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section name=&amp;quot;Client&amp;quot; class=&amp;quot;client&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;
bool addCommandHandler ( string commandName, function handlerFunction, [bool caseSensitive = true] )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
===Required Arguments===&lt;br /&gt;
*'''commandName:''' This is the name of the command you wish to attach a handler to. This is what must be typed into the console to trigger the function.&lt;br /&gt;
*'''handlerFunction:''' This is the function that you want the command to trigger, which has to be defined before you add the handler. This function can take two parameters, playerSource and commandName, followed by as many parameters you expect after your command (see below). These are all optional.&lt;br /&gt;
===Optional Arguments=== &lt;br /&gt;
{{OptionalArg}} &lt;br /&gt;
{{New feature|3|1.0|&lt;br /&gt;
*'''caseSensitive:''' Specifies if the command handler will ignore the case for this command name.&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Handler function parameters====&lt;br /&gt;
These are the parameters for the handler function that is called when the command is used.&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;player playerSource, string commandName, [string arg1, string arg2, ...] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* '''playerSource:''' The player who triggered the command. If not triggered by a player (e.g. by admin), this will be ''false''.&lt;br /&gt;
* '''commandName:''' The name of the command triggered. This is useful if multiple commands go through one function.&lt;br /&gt;
* '''arg1, arg2, ...:''' Each word after command name in the original command is passed here in a seperate variable. If there is no value for an argument, its variable will contain [[nil]]. You can deal with a variable number of arguments using the vararg expression, as shown in '''Example 4''' below.&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section name=&amp;quot;Client&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt; string commandName, [string arg1, string arg2, ...] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* '''commandName:''' The name of the command triggered. This is useful if multiple commands go through one function.&lt;br /&gt;
* '''arg1, arg2, ...:''' Each word after command name in the original command is passed here in a seperate variable. If there is no value for an argument, its variable will contain [[nil]]. You can deal with a variable number of arguments using the vararg expression, as shown in '''Example 4''' below.&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns ''true'' if the command handler was added successfully, ''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;
'''Example 1:''' This example defines a command handler for the command ''createmarker''. This will create a red marker at the position of the player player who uses it.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Define our function that will handle this command&lt;br /&gt;
function consoleCreateMarker ( playerSource )&lt;br /&gt;
	-- If a player triggered it (rather than the admin) then&lt;br /&gt;
	if ( playerSource ) then&lt;br /&gt;
		-- Get that player's position&lt;br /&gt;
		local x, y, z = getElementPosition ( playerSource )&lt;br /&gt;
		-- Create a size 2, red checkpoint marker at their position&lt;br /&gt;
		createMarker ( x, y, z, &amp;quot;checkpoint&amp;quot;, 2, 255, 0, 0, 255 )&lt;br /&gt;
		-- Output it in his chat box&lt;br /&gt;
		outputChatBox ( &amp;quot;You got a red marker&amp;quot;, playerSource )&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
-- Attach the 'consoleCreateMarker' function to the &amp;quot;createmarker&amp;quot; command&lt;br /&gt;
addCommandHandler ( &amp;quot;createmarker&amp;quot;, consoleCreateMarker )&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;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;hide&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 2:''' This example implements a ''set_vehicle_color'' command.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Define our function that will handle this command&lt;br /&gt;
function consoleSetVehicleColor ( playerSource, commandName, col1, col2, col3, col4 )&lt;br /&gt;
	-- If a player triggered this in-game&lt;br /&gt;
	if ( playerSource ) then&lt;br /&gt;
		-- Get the player's vehicle&lt;br /&gt;
		local playerVehicle = getPedOccupiedVehicle ( playerSource )&lt;br /&gt;
		-- If the player is in a vehicle and we've got at least 1 parameter&lt;br /&gt;
		if ( playerVehicle and col1 ) then&lt;br /&gt;
			-- Get the vehicle's existing color and use it if fewer than 4 arguments were passed&lt;br /&gt;
			local exCol1, exCol2, exCol3, exCol4 = getVehicleColor ( playerVehicle )&lt;br /&gt;
&lt;br /&gt;
			if not col2 then col2 = exCol2 end&lt;br /&gt;
			if not col3 then col3 = exCol3 end&lt;br /&gt;
			if not col4 then col4 = exCol4 end&lt;br /&gt;
&lt;br /&gt;
			-- Set the vehicle's color&lt;br /&gt;
			setVehicleColor ( playerVehicle, col1, col2, col3, col4 )&lt;br /&gt;
		else&lt;br /&gt;
			-- If we didn't get at least 1 parameter or the player doesn't have a vehicle, display some help text&lt;br /&gt;
			outputConsole ( &amp;quot;This function will set your current vehicle's colors. A vehicle can have up to 4 colors.&amp;quot;, playerSource )&lt;br /&gt;
			outputConsole ( &amp;quot;Syntax: set_vehicle_color color1 [ color2 color3 color4 ]&amp;quot;, playerSource )&lt;br /&gt;
			outputConsole ( &amp;quot;You must be in a vehicle to use this function.&amp;quot;, playerSource )&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
-- Attach the 'consoleSetVehicleColor' function to the &amp;quot;set_vehicle_color&amp;quot; command&lt;br /&gt;
addCommandHandler ( &amp;quot;set_vehicle_color&amp;quot;, consoleSetVehicleColor )&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;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;hide&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 3:''' This example makes use of Lua's vararg expression to implement a ''check_parameters'' command to count the number of parameters passed, merge them all into a single string and output it. This is also shows you how you can use table.concat to merge all the passed arguments. This is particularly useful when you want to read in a sentence of text passed from the user. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Define our function that will handle this command (which can accept a variable number of arguments after commandName)&lt;br /&gt;
function consoleCheckParameters ( playerSource, commandName, ... )&lt;br /&gt;
	-- If a player, not an admin, triggered it,&lt;br /&gt;
	if playerSource then&lt;br /&gt;
		-- Get the number of arguments in the arg table (arg table is the same as: {...})&lt;br /&gt;
		local parameterCount = #arg&lt;br /&gt;
		-- Output it to the player's chatbox&lt;br /&gt;
		outputChatBox ( &amp;quot;Number of parameters: &amp;quot; .. parameterCount, playerSource )&lt;br /&gt;
		-- Join them together in a single comma-separated string&lt;br /&gt;
		local stringWithAllParameters = table.concat( arg, &amp;quot;, &amp;quot; )&lt;br /&gt;
		-- Output this parameter list to the player's chatbox&lt;br /&gt;
		outputChatBox ( &amp;quot;Parameters passed: &amp;quot; .. stringWithAllParameters, playerSource )&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
-- Attach the 'consoleCheckParameters' function to the &amp;quot;check_parameters&amp;quot; command&lt;br /&gt;
addCommandHandler ( &amp;quot;check_parameters&amp;quot;, consoleCheckParameters )&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;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;hide&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 4:''' This example shows using a single function to handle multiple command handlers. This isn't advised for general usage, as it makes code harder to understand, but where multiple command handlers share some logic, it can be a useful way of reducing duplicated code. Generally, it would be preferable to put this shared logic in a separate function instead, as this gives you more control over the flow.&lt;br /&gt;
&amp;lt;!-- commands are case sensitive by default, in this example too --&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- make the function&lt;br /&gt;
function moneyCmd(player, cmd, amount)&lt;br /&gt;
    if getElementData(player, &amp;quot;canUseMoneyFunctions&amp;quot;) then -- the shared logic&lt;br /&gt;
        if cmd == &amp;quot;givemoney&amp;quot; then&lt;br /&gt;
            amount  = tonumber(amount)&lt;br /&gt;
            if amount then&lt;br /&gt;
                givePlayerMoney(player, amount)&lt;br /&gt;
            else&lt;br /&gt;
                outputChatBox(&amp;quot;[usage] /givemoney [amount]&amp;quot;, player)&lt;br /&gt;
            end&lt;br /&gt;
        else if cmd == &amp;quot;takemoney&amp;quot; then&lt;br /&gt;
            amount = tonumber(amount)&lt;br /&gt;
            if amount then&lt;br /&gt;
                takePlayerMoney(player, amount)&lt;br /&gt;
            else&lt;br /&gt;
                outputChatBox(&amp;quot;[usage] /takemoney [amount]&amp;quot;, player)&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
    else&lt;br /&gt;
        outputChatBox(&amp;quot;You aren't able to use this command&amp;quot;, player)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
addCommandHandler(&amp;quot;givemoney&amp;quot;, moneyCmd);&lt;br /&gt;
addCommandHandler(&amp;quot;takemoney&amp;quot;, moneyCmd);&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;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;false&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 5:''' This example shows you how to create a function inside a commandHandler. This example creates an object, in this case a dildo, and attaches it to the player. Notice that unlike the other examples, we dont add 'addCommandHandler' after the function has been created. We create the function inside the commandHandler. This is not something you have to do, but it can save some work and space in the end in some cases.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;addCommandHandler(&amp;quot;give_me_a_willy&amp;quot;,function(player) -- Notice our function starts here&lt;br /&gt;
local x,y,z = getElementPosition(player)&lt;br /&gt;
local myObject = createObject(321,x,y,z)&lt;br /&gt;
setElementCollisionsEnabled(myObject ,false)&lt;br /&gt;
attachElements(myObject ,player,0.03,0.2,-0.45,0,0,90)&lt;br /&gt;
end) -- Remember to end the function before closing the commandHandler.&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;Client&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 1:''' This creates a GUI window and allows a player to change its alpha (transparency) value with a command. Note that, in a clientside script, the player using the command is not passed as a parameter to the handler function, since it is always the local player.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;--Create a window&lt;br /&gt;
myWindow = guiCreateWindow ( 0.30, 0.10, 0.5, 0.60, &amp;quot;GUI window title&amp;quot;, true )&lt;br /&gt;
&lt;br /&gt;
--Add a command handler to change the alpha of the GUI window. Usage example: 'alpha 0.15'&lt;br /&gt;
function changeAlpha ( commandName, alphaAmount )&lt;br /&gt;
	-- All command parameters are strings, so we'll convert the value to a number first&lt;br /&gt;
	alphaAmount = tonumber(alphaAmount)&lt;br /&gt;
	guiSetAlpha ( myWindow, alphaAmount )&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler ( &amp;quot;alpha&amp;quot;, changeAlpha )&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;Client&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;false&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 2:''' This creates a GUI window and allows a player to change its alpha (transparency) value with a command. Note that, in a clientside script, the player using the command is not passed as a parameter to the handler function, since it is always the local player.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;function escapeMe ( commandName, taskType )&lt;br /&gt;
	local x, y, z = getElementPosition ( getLocalPlayer() ) --Get player's position&lt;br /&gt;
	setElementPosition ( getLocalPlayer(), x+(math.random(-10,10)), y+(math.random(-10,10)), z+(math.random(1,15)) ) --Move a player randomly to a nearby location. X is current x + a number between -10, 10 and so on.&lt;br /&gt;
end    &lt;br /&gt;
addCommandHandler ( &amp;quot;escape&amp;quot;, escapeMe ) --When player types &amp;quot;/escape&amp;quot; in chatbox or &amp;quot;escape&amp;quot; in console&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;
{{Server functions}}&lt;/div&gt;</summary>
		<author><name>Wafamde</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=AddCommandHandler&amp;diff=28516</id>
		<title>AddCommandHandler</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=AddCommandHandler&amp;diff=28516"/>
		<updated>2011-11-30T17:20:13Z</updated>

		<summary type="html">&lt;p&gt;Wafamde: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__ &lt;br /&gt;
{{Server client function}}&lt;br /&gt;
{{Note_box|It is strongly advised that you do not use the same name for your handler function as the command name, as this can lead to confusion if multiple handler functions are used. Use a name that describes your handler's purpose more specifically.}}&lt;br /&gt;
This function will attach a scripting function (handler) to a console command, so that whenever a player or administrator uses the command the function is called.&lt;br /&gt;
&lt;br /&gt;
Multiple command handlers can be attached to a single command, and they will be called in the order that the handlers were attached. Equally, multiple commands can be handled by a single function, and the ''commandName'' parameter used to decide the course of action.&lt;br /&gt;
&lt;br /&gt;
For users, a command is in the format:&lt;br /&gt;
&lt;br /&gt;
''commandName'' ''argument1'' ''argument2''&lt;br /&gt;
&lt;br /&gt;
This can be triggered from the player's console or directly from the chat box by prefixing the message with a forward slash (''/''). For server side handlers, the server admin is also able to trigger these directly from the server's console in the same way as they are triggered from a player's console.&lt;br /&gt;
&lt;br /&gt;
==Syntax== &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;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
bool addCommandHandler ( string commandName, function handlerFunction, [bool restricted = false, bool caseSensitive = true] )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
===Required Arguments===&lt;br /&gt;
*'''commandName:''' This is the name of the command you wish to attach a handler to. This is what must be typed into the console to trigger the function.&lt;br /&gt;
*'''handlerFunction:''' This is the function that you want the command to trigger, which has to be defined before you add the handler. This function can take two parameters, playerSource and commandName, followed by as many parameters you expect after your command (see below). These are all optional.&lt;br /&gt;
===Optional Arguments=== &lt;br /&gt;
{{OptionalArg}} &lt;br /&gt;
*'''restricted:''' Specify whether or not this command should be restricted by default. Use this on commands that should be inaccessible to everyone as default except special users specified in the ACL (Access Control List). This is to make sure admin commands such as ie. 'punish' won't be available to everyone if a server administrator forgets masking it in ACL. Make sure to add the command to your ACL under the proper group for it to be usefull (i.e &amp;lt;right name=&amp;quot;command.killEveryone&amp;quot; access=&amp;quot;true&amp;quot;&amp;gt;&amp;lt;/right&amp;gt;). This argument defaults to false if nothing is specified.&lt;br /&gt;
{{New feature|3|1.0|&lt;br /&gt;
*'''caseSensitive:''' Specifies if the command handler will ignore the case for this command name.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section name=&amp;quot;Client&amp;quot; class=&amp;quot;client&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;
bool addCommandHandler ( string commandName, function handlerFunction, [bool caseSensitive = true] )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
===Required Arguments===&lt;br /&gt;
*'''commandName:''' This is the name of the command you wish to attach a handler to. This is what must be typed into the console to trigger the function.&lt;br /&gt;
*'''handlerFunction:''' This is the function that you want the command to trigger, which has to be defined before you add the handler. This function can take two parameters, playerSource and commandName, followed by as many parameters you expect after your command (see below). These are all optional.&lt;br /&gt;
===Optional Arguments=== &lt;br /&gt;
{{OptionalArg}} &lt;br /&gt;
{{New feature|3|1.0|&lt;br /&gt;
*'''caseSensitive:''' Specifies if the command handler will ignore the case for this command name.&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Handler function parameters====&lt;br /&gt;
These are the parameters for the handler function that is called when the command is used.&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;player playerSource, string commandName, [string arg1, string arg2, ...] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* '''playerSource:''' The player who triggered the command. If not triggered by a player (e.g. by admin), this will be ''false''.&lt;br /&gt;
* '''commandName:''' The name of the command triggered. This is useful if multiple commands go through one function.&lt;br /&gt;
* '''arg1, arg2, ...:''' Each word after command name in the original command is passed here in a seperate variable. If there is no value for an argument, its variable will contain [[nil]]. You can deal with a variable number of arguments using the vararg expression, as shown in '''Example 4''' below.&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section name=&amp;quot;Client&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt; string commandName, [string arg1, string arg2, ...] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* '''commandName:''' The name of the command triggered. This is useful if multiple commands go through one function.&lt;br /&gt;
* '''arg1, arg2, ...:''' Each word after command name in the original command is passed here in a seperate variable. If there is no value for an argument, its variable will contain [[nil]]. You can deal with a variable number of arguments using the vararg expression, as shown in '''Example 4''' below.&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns ''true'' if the command handler was added successfully, ''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;
'''Example 1:''' This example defines a command handler for the command ''createmarker''. This will create a red marker at the position of the player player who uses it.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Define our function that will handle this command&lt;br /&gt;
function consoleCreateMarker ( playerSource )&lt;br /&gt;
	-- If a player triggered it (rather than the admin) then&lt;br /&gt;
	if ( playerSource ) then&lt;br /&gt;
		-- Get that player's position&lt;br /&gt;
		local x, y, z = getElementPosition ( playerSource )&lt;br /&gt;
		-- Create a size 2, red checkpoint marker at their position&lt;br /&gt;
		createMarker ( x, y, z, &amp;quot;checkpoint&amp;quot;, 2, 255, 0, 0, 255 )&lt;br /&gt;
		-- Output it in his chat box&lt;br /&gt;
		outputChatBox ( &amp;quot;You got a red marker&amp;quot;, playerSource )&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
-- Attach the 'consoleCreateMarker' function to the &amp;quot;createmarker&amp;quot; command&lt;br /&gt;
addCommandHandler ( &amp;quot;createmarker&amp;quot;, consoleCreateMarker )&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;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;hide&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 2:''' This example implements a ''set_vehicle_color'' command.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Define our function that will handle this command&lt;br /&gt;
function consoleSetVehicleColor ( playerSource, commandName, col1, col2, col3, col4 )&lt;br /&gt;
	-- If a player triggered this in-game&lt;br /&gt;
	if ( playerSource ) then&lt;br /&gt;
		-- Get the player's vehicle&lt;br /&gt;
		local playerVehicle = getPedOccupiedVehicle ( playerSource )&lt;br /&gt;
		-- If the player is in a vehicle and we've got at least 1 parameter&lt;br /&gt;
		if ( playerVehicle and col1 ) then&lt;br /&gt;
			-- Get the vehicle's existing color and use it if fewer than 4 arguments were passed&lt;br /&gt;
			local exCol1, exCol2, exCol3, exCol4 = getVehicleColor ( playerVehicle )&lt;br /&gt;
&lt;br /&gt;
			if not col2 then col2 = exCol2 end&lt;br /&gt;
			if not col3 then col3 = exCol3 end&lt;br /&gt;
			if not col4 then col4 = exCol4 end&lt;br /&gt;
&lt;br /&gt;
			-- Set the vehicle's color&lt;br /&gt;
			setVehicleColor ( playerVehicle, col1, col2, col3, col4 )&lt;br /&gt;
		else&lt;br /&gt;
			-- If we didn't get at least 1 parameter or the player doesn't have a vehicle, display some help text&lt;br /&gt;
			outputConsole ( &amp;quot;This function will set your current vehicle's colors. A vehicle can have up to 4 colors.&amp;quot;, playerSource )&lt;br /&gt;
			outputConsole ( &amp;quot;Syntax: set_vehicle_color color1 [ color2 color3 color4 ]&amp;quot;, playerSource )&lt;br /&gt;
			outputConsole ( &amp;quot;You must be in a vehicle to use this function.&amp;quot;, playerSource )&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
-- Attach the 'consoleSetVehicleColor' function to the &amp;quot;set_vehicle_color&amp;quot; command&lt;br /&gt;
addCommandHandler ( &amp;quot;set_vehicle_color&amp;quot;, consoleSetVehicleColor )&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;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;hide&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 3:''' This example makes use of Lua's vararg expression to implement a ''check_parameters'' command to count the number of parameters passed, merge them all into a single string and output it. This is also shows you how you can use table.concat to merge all the passed arguments. This is particularly useful when you want to read in a sentence of text passed from the user. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Define our function that will handle this command (which can accept a variable number of arguments after commandName)&lt;br /&gt;
function consoleCheckParameters ( playerSource, commandName, ... )&lt;br /&gt;
	-- If a player, not an admin, triggered it,&lt;br /&gt;
	if playerSource then&lt;br /&gt;
		-- Get the number of arguments in the arg table (arg table is the same as: {...})&lt;br /&gt;
		local parameterCount = #arg&lt;br /&gt;
		-- Output it to the player's chatbox&lt;br /&gt;
		outputChatBox ( &amp;quot;Number of parameters: &amp;quot; .. parameterCount, playerSource )&lt;br /&gt;
		-- Join them together in a single comma-separated string&lt;br /&gt;
		local stringWithAllParameters = table.concat( arg, &amp;quot;, &amp;quot; )&lt;br /&gt;
		-- Output this parameter list to the player's chatbox&lt;br /&gt;
		outputChatBox ( &amp;quot;Parameters passed: &amp;quot; .. stringWithAllParameters, playerSource )&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
-- Attach the 'consoleCheckParameters' function to the &amp;quot;check_parameters&amp;quot; command&lt;br /&gt;
addCommandHandler ( &amp;quot;check_parameters&amp;quot;, consoleCheckParameters )&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;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;hide&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 4:''' This example shows using a single function to handle multiple command handlers. This isn't advised for general usage, as it makes code harder to understand, but where multiple command handlers share some logic, it can be a useful way of reducing duplicated code. Generally, it would be preferable to put this shared logic in a separate function instead, as this gives you more control over the flow.&lt;br /&gt;
&amp;lt;!-- commands are case sensitive by default, in this example too --&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- make the function&lt;br /&gt;
function moneyCmd(player, cmd, amount)&lt;br /&gt;
    if getElementData(player, &amp;quot;canUseMoneyFunctions&amp;quot;) then -- the shared logic&lt;br /&gt;
        if cmd == &amp;quot;givemoney&amp;quot; then&lt;br /&gt;
            amount  = tonumber(amount)&lt;br /&gt;
            if amount then&lt;br /&gt;
                givePlayerMoney(player, amount)&lt;br /&gt;
            else&lt;br /&gt;
                outputChatBox(&amp;quot;[usage] /givemoney [amount]&amp;quot;, player)&lt;br /&gt;
            end&lt;br /&gt;
        else if cmd == &amp;quot;takemoney&amp;quot; then&lt;br /&gt;
            amount = tonumber(amount)&lt;br /&gt;
            if amount then&lt;br /&gt;
                takePlayerMoney(player, amount)&lt;br /&gt;
            else&lt;br /&gt;
                outputChatBox(&amp;quot;[usage] /takemoney [amount]&amp;quot;, player)&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
    else&lt;br /&gt;
        outputChatBox(&amp;quot;You aren't able to use this command&amp;quot;, player)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
addCommandHandler(&amp;quot;givemoney&amp;quot;, moneyCmd);&lt;br /&gt;
addCommandHandler(&amp;quot;takemoney&amp;quot;, moneyCmd);&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;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;false&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 5:''' This example shows you how to create a function inside a commandHandler. This example creates an object, in this case a dildo, and attaches it to the player. Notice that unlike the other examples, we dont add 'addCommandHandler' after the function has been created. We create the function inside the commandHandler. This is not something you have to do, but it can save some work and space in the end in some cases.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;addCommandHandler(&amp;quot;give_me_a_willy&amp;quot;,function(player) -- Notice our function stats here&lt;br /&gt;
local x,y,z = getElementPosition(player)&lt;br /&gt;
local myObject = createObject(321,x,y,z)&lt;br /&gt;
setElementCollisionsEnabled(myObject ,false)&lt;br /&gt;
attachElements(myObject ,player,0.03,0.2,-0.45,0,0,90)&lt;br /&gt;
end) -- Remember to end the function before closing the commandHandler.&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;Client&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 1:''' This creates a GUI window and allows a player to change its alpha (transparency) value with a command. Note that, in a clientside script, the player using the command is not passed as a parameter to the handler function, since it is always the local player.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;--Create a window&lt;br /&gt;
myWindow = guiCreateWindow ( 0.30, 0.10, 0.5, 0.60, &amp;quot;GUI window title&amp;quot;, true )&lt;br /&gt;
&lt;br /&gt;
--Add a command handler to change the alpha of the GUI window. Usage example: 'alpha 0.15'&lt;br /&gt;
function changeAlpha ( commandName, alphaAmount )&lt;br /&gt;
	-- All command parameters are strings, so we'll convert the value to a number first&lt;br /&gt;
	alphaAmount = tonumber(alphaAmount)&lt;br /&gt;
	guiSetAlpha ( myWindow, alphaAmount )&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler ( &amp;quot;alpha&amp;quot;, changeAlpha )&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;Client&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;false&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 2:''' This creates a GUI window and allows a player to change its alpha (transparency) value with a command. Note that, in a clientside script, the player using the command is not passed as a parameter to the handler function, since it is always the local player.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;function escapeMe ( commandName, taskType )&lt;br /&gt;
	local x, y, z = getElementPosition ( getLocalPlayer() ) --Get player's position&lt;br /&gt;
	setElementPosition ( getLocalPlayer(), x+(math.random(-10,10)), y+(math.random(-10,10)), z+(math.random(1,15)) ) --Move a player randomly to a nearby location. X is current x + a number between -10, 10 and so on.&lt;br /&gt;
end    &lt;br /&gt;
addCommandHandler ( &amp;quot;escape&amp;quot;, escapeMe ) --When player types &amp;quot;/escape&amp;quot; in chatbox or &amp;quot;escape&amp;quot; in console&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;
{{Server functions}}&lt;/div&gt;</summary>
		<author><name>Wafamde</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=AddCommandHandler&amp;diff=28515</id>
		<title>AddCommandHandler</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=AddCommandHandler&amp;diff=28515"/>
		<updated>2011-11-30T17:16:39Z</updated>

		<summary type="html">&lt;p&gt;Wafamde: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__ &lt;br /&gt;
{{Server client function}}&lt;br /&gt;
{{Note_box|It is strongly advised that you do not use the same name for your handler function as the command name, as this can lead to confusion if multiple handler functions are used. Use a name that describes your handler's purpose more specifically.}}&lt;br /&gt;
This function will attach a scripting function (handler) to a console command, so that whenever a player or administrator uses the command the function is called.&lt;br /&gt;
&lt;br /&gt;
Multiple command handlers can be attached to a single command, and they will be called in the order that the handlers were attached. Equally, multiple commands can be handled by a single function, and the ''commandName'' parameter used to decide the course of action.&lt;br /&gt;
&lt;br /&gt;
For users, a command is in the format:&lt;br /&gt;
&lt;br /&gt;
''commandName'' ''argument1'' ''argument2''&lt;br /&gt;
&lt;br /&gt;
This can be triggered from the player's console or directly from the chat box by prefixing the message with a forward slash (''/''). For server side handlers, the server admin is also able to trigger these directly from the server's console in the same way as they are triggered from a player's console.&lt;br /&gt;
&lt;br /&gt;
==Syntax== &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;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
bool addCommandHandler ( string commandName, function handlerFunction, [bool restricted = false, bool caseSensitive = true] )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
===Required Arguments===&lt;br /&gt;
*'''commandName:''' This is the name of the command you wish to attach a handler to. This is what must be typed into the console to trigger the function.&lt;br /&gt;
*'''handlerFunction:''' This is the function that you want the command to trigger, which has to be defined before you add the handler. This function can take two parameters, playerSource and commandName, followed by as many parameters you expect after your command (see below). These are all optional.&lt;br /&gt;
===Optional Arguments=== &lt;br /&gt;
{{OptionalArg}} &lt;br /&gt;
*'''restricted:''' Specify whether or not this command should be restricted by default. Use this on commands that should be inaccessible to everyone as default except special users specified in the ACL (Access Control List). This is to make sure admin commands such as ie. 'punish' won't be available to everyone if a server administrator forgets masking it in ACL. Make sure to add the command to your ACL under the proper group for it to be usefull (i.e &amp;lt;right name=&amp;quot;command.killEveryone&amp;quot; access=&amp;quot;true&amp;quot;&amp;gt;&amp;lt;/right&amp;gt;). This argument defaults to false if nothing is specified.&lt;br /&gt;
{{New feature|3|1.0|&lt;br /&gt;
*'''caseSensitive:''' Specifies if the command handler will ignore the case for this command name.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section name=&amp;quot;Client&amp;quot; class=&amp;quot;client&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;
bool addCommandHandler ( string commandName, function handlerFunction, [bool caseSensitive = true] )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
===Required Arguments===&lt;br /&gt;
*'''commandName:''' This is the name of the command you wish to attach a handler to. This is what must be typed into the console to trigger the function.&lt;br /&gt;
*'''handlerFunction:''' This is the function that you want the command to trigger, which has to be defined before you add the handler. This function can take two parameters, playerSource and commandName, followed by as many parameters you expect after your command (see below). These are all optional.&lt;br /&gt;
===Optional Arguments=== &lt;br /&gt;
{{OptionalArg}} &lt;br /&gt;
{{New feature|3|1.0|&lt;br /&gt;
*'''caseSensitive:''' Specifies if the command handler will ignore the case for this command name.&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Handler function parameters====&lt;br /&gt;
These are the parameters for the handler function that is called when the command is used.&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;player playerSource, string commandName, [string arg1, string arg2, ...] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* '''playerSource:''' The player who triggered the command. If not triggered by a player (e.g. by admin), this will be ''false''.&lt;br /&gt;
* '''commandName:''' The name of the command triggered. This is useful if multiple commands go through one function.&lt;br /&gt;
* '''arg1, arg2, ...:''' Each word after command name in the original command is passed here in a seperate variable. If there is no value for an argument, its variable will contain [[nil]]. You can deal with a variable number of arguments using the vararg expression, as shown in '''Example 4''' below.&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section name=&amp;quot;Client&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt; string commandName, [string arg1, string arg2, ...] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* '''commandName:''' The name of the command triggered. This is useful if multiple commands go through one function.&lt;br /&gt;
* '''arg1, arg2, ...:''' Each word after command name in the original command is passed here in a seperate variable. If there is no value for an argument, its variable will contain [[nil]]. You can deal with a variable number of arguments using the vararg expression, as shown in '''Example 4''' below.&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns ''true'' if the command handler was added successfully, ''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;
'''Example 1:''' This example defines a command handler for the command ''createmarker''. This will create a red marker at the position of the player player who uses it.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Define our function that will handle this command&lt;br /&gt;
function consoleCreateMarker ( playerSource )&lt;br /&gt;
	-- If a player triggered it (rather than the admin) then&lt;br /&gt;
	if ( playerSource ) then&lt;br /&gt;
		-- Get that player's position&lt;br /&gt;
		local x, y, z = getElementPosition ( playerSource )&lt;br /&gt;
		-- Create a size 2, red checkpoint marker at their position&lt;br /&gt;
		createMarker ( x, y, z, &amp;quot;checkpoint&amp;quot;, 2, 255, 0, 0, 255 )&lt;br /&gt;
		-- Output it in his chat box&lt;br /&gt;
		outputChatBox ( &amp;quot;You got a red marker&amp;quot;, playerSource )&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
-- Attach the 'consoleCreateMarker' function to the &amp;quot;createmarker&amp;quot; command&lt;br /&gt;
addCommandHandler ( &amp;quot;createmarker&amp;quot;, consoleCreateMarker )&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;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;hide&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 2:''' This example implements a ''set_vehicle_color'' command.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Define our function that will handle this command&lt;br /&gt;
function consoleSetVehicleColor ( playerSource, commandName, col1, col2, col3, col4 )&lt;br /&gt;
	-- If a player triggered this in-game&lt;br /&gt;
	if ( playerSource ) then&lt;br /&gt;
		-- Get the player's vehicle&lt;br /&gt;
		local playerVehicle = getPedOccupiedVehicle ( playerSource )&lt;br /&gt;
		-- If the player is in a vehicle and we've got at least 1 parameter&lt;br /&gt;
		if ( playerVehicle and col1 ) then&lt;br /&gt;
			-- Get the vehicle's existing color and use it if fewer than 4 arguments were passed&lt;br /&gt;
			local exCol1, exCol2, exCol3, exCol4 = getVehicleColor ( playerVehicle )&lt;br /&gt;
&lt;br /&gt;
			if not col2 then col2 = exCol2 end&lt;br /&gt;
			if not col3 then col3 = exCol3 end&lt;br /&gt;
			if not col4 then col4 = exCol4 end&lt;br /&gt;
&lt;br /&gt;
			-- Set the vehicle's color&lt;br /&gt;
			setVehicleColor ( playerVehicle, col1, col2, col3, col4 )&lt;br /&gt;
		else&lt;br /&gt;
			-- If we didn't get at least 1 parameter or the player doesn't have a vehicle, display some help text&lt;br /&gt;
			outputConsole ( &amp;quot;This function will set your current vehicle's colors. A vehicle can have up to 4 colors.&amp;quot;, playerSource )&lt;br /&gt;
			outputConsole ( &amp;quot;Syntax: set_vehicle_color color1 [ color2 color3 color4 ]&amp;quot;, playerSource )&lt;br /&gt;
			outputConsole ( &amp;quot;You must be in a vehicle to use this function.&amp;quot;, playerSource )&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
-- Attach the 'consoleSetVehicleColor' function to the &amp;quot;set_vehicle_color&amp;quot; command&lt;br /&gt;
addCommandHandler ( &amp;quot;set_vehicle_color&amp;quot;, consoleSetVehicleColor )&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;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;hide&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 3:''' This example makes use of Lua's vararg expression to implement a ''check_parameters'' command to count the number of parameters passed, merge them all into a single string and output it. This is also shows you how you can use table.concat to merge all the passed arguments. This is particularly useful when you want to read in a sentence of text passed from the user. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Define our function that will handle this command (which can accept a variable number of arguments after commandName)&lt;br /&gt;
function consoleCheckParameters ( playerSource, commandName, ... )&lt;br /&gt;
	-- If a player, not an admin, triggered it,&lt;br /&gt;
	if playerSource then&lt;br /&gt;
		-- Get the number of arguments in the arg table (arg table is the same as: {...})&lt;br /&gt;
		local parameterCount = #arg&lt;br /&gt;
		-- Output it to the player's chatbox&lt;br /&gt;
		outputChatBox ( &amp;quot;Number of parameters: &amp;quot; .. parameterCount, playerSource )&lt;br /&gt;
		-- Join them together in a single comma-separated string&lt;br /&gt;
		local stringWithAllParameters = table.concat( arg, &amp;quot;, &amp;quot; )&lt;br /&gt;
		-- Output this parameter list to the player's chatbox&lt;br /&gt;
		outputChatBox ( &amp;quot;Parameters passed: &amp;quot; .. stringWithAllParameters, playerSource )&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
-- Attach the 'consoleCheckParameters' function to the &amp;quot;check_parameters&amp;quot; command&lt;br /&gt;
addCommandHandler ( &amp;quot;check_parameters&amp;quot;, consoleCheckParameters )&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;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;hide&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 4:''' This example shows using a single function to handle multiple command handlers. This isn't advised for general usage, as it makes code harder to understand, but where multiple command handlers share some logic, it can be a useful way of reducing duplicated code. Generally, it would be preferable to put this shared logic in a separate function instead, as this gives you more control over the flow.&lt;br /&gt;
&amp;lt;!-- commands are case sensitive by default, in this example too --&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- make the function&lt;br /&gt;
function moneyCmd(player, cmd, amount)&lt;br /&gt;
    if getElementData(player, &amp;quot;canUseMoneyFunctions&amp;quot;) then -- the shared logic&lt;br /&gt;
        if cmd == &amp;quot;givemoney&amp;quot; then&lt;br /&gt;
            amount  = tonumber(amount)&lt;br /&gt;
            if amount then&lt;br /&gt;
                givePlayerMoney(player, amount)&lt;br /&gt;
            else&lt;br /&gt;
                outputChatBox(&amp;quot;[usage] /givemoney [amount]&amp;quot;, player)&lt;br /&gt;
            end&lt;br /&gt;
        else if cmd == &amp;quot;takemoney&amp;quot; then&lt;br /&gt;
            amount = tonumber(amount)&lt;br /&gt;
            if amount then&lt;br /&gt;
                takePlayerMoney(player, amount)&lt;br /&gt;
            else&lt;br /&gt;
                outputChatBox(&amp;quot;[usage] /takemoney [amount]&amp;quot;, player)&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
    else&lt;br /&gt;
        outputChatBox(&amp;quot;You aren't able to use this command&amp;quot;, player)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
addCommandHandler(&amp;quot;givemoney&amp;quot;, moneyCmd);&lt;br /&gt;
addCommandHandler(&amp;quot;takemoney&amp;quot;, moneyCmd);&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;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;false&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 5:''' This example shows you how to create a function inside a commandHandler. This example creates an object, in this case a dildo, and attaches it to the player. Notice that unlike the other examples, we dont add 'addCommandHandler' after the function has been created. We create the function inside the commandHandler. This is not something you have to do, but it can save some work and space in the end in some cases.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;addCommandHandler(&amp;quot;give_me_a_willy&amp;quot;,function(player)&lt;br /&gt;
local x,y,z = getElementPosition(player)&lt;br /&gt;
local myObject = createObject(321,x,y,z)&lt;br /&gt;
setElementCollisionsEnabled(myObject ,false)&lt;br /&gt;
attachElements(myObject ,player,0.03,0.2,-0.45,0,0,90)&lt;br /&gt;
end)&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;Client&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 1:''' This creates a GUI window and allows a player to change its alpha (transparency) value with a command. Note that, in a clientside script, the player using the command is not passed as a parameter to the handler function, since it is always the local player.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;--Create a window&lt;br /&gt;
myWindow = guiCreateWindow ( 0.30, 0.10, 0.5, 0.60, &amp;quot;GUI window title&amp;quot;, true )&lt;br /&gt;
&lt;br /&gt;
--Add a command handler to change the alpha of the GUI window. Usage example: 'alpha 0.15'&lt;br /&gt;
function changeAlpha ( commandName, alphaAmount )&lt;br /&gt;
	-- All command parameters are strings, so we'll convert the value to a number first&lt;br /&gt;
	alphaAmount = tonumber(alphaAmount)&lt;br /&gt;
	guiSetAlpha ( myWindow, alphaAmount )&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler ( &amp;quot;alpha&amp;quot;, changeAlpha )&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;Client&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;false&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 2:''' This creates a GUI window and allows a player to change its alpha (transparency) value with a command. Note that, in a clientside script, the player using the command is not passed as a parameter to the handler function, since it is always the local player.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;function escapeMe ( commandName, taskType )&lt;br /&gt;
	local x, y, z = getElementPosition ( getLocalPlayer() ) --Get player's position&lt;br /&gt;
	setElementPosition ( getLocalPlayer(), x+(math.random(-10,10)), y+(math.random(-10,10)), z+(math.random(1,15)) ) --Move a player randomly to a nearby location. X is current x + a number between -10, 10 and so on.&lt;br /&gt;
end    &lt;br /&gt;
addCommandHandler ( &amp;quot;escape&amp;quot;, escapeMe ) --When player types &amp;quot;/escape&amp;quot; in chatbox or &amp;quot;escape&amp;quot; in console&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;
{{Server functions}}&lt;/div&gt;</summary>
		<author><name>Wafamde</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=AddCommandHandler&amp;diff=28514</id>
		<title>AddCommandHandler</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=AddCommandHandler&amp;diff=28514"/>
		<updated>2011-11-30T17:15:32Z</updated>

		<summary type="html">&lt;p&gt;Wafamde: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__ &lt;br /&gt;
{{Server client function}}&lt;br /&gt;
{{Note_box|It is strongly advised that you do not use the same name for your handler function as the command name, as this can lead to confusion if multiple handler functions are used. Use a name that describes your handler's purpose more specifically.}}&lt;br /&gt;
This function will attach a scripting function (handler) to a console command, so that whenever a player or administrator uses the command the function is called.&lt;br /&gt;
&lt;br /&gt;
Multiple command handlers can be attached to a single command, and they will be called in the order that the handlers were attached. Equally, multiple commands can be handled by a single function, and the ''commandName'' parameter used to decide the course of action.&lt;br /&gt;
&lt;br /&gt;
For users, a command is in the format:&lt;br /&gt;
&lt;br /&gt;
''commandName'' ''argument1'' ''argument2''&lt;br /&gt;
&lt;br /&gt;
This can be triggered from the player's console or directly from the chat box by prefixing the message with a forward slash (''/''). For server side handlers, the server admin is also able to trigger these directly from the server's console in the same way as they are triggered from a player's console.&lt;br /&gt;
&lt;br /&gt;
==Syntax== &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;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
bool addCommandHandler ( string commandName, function handlerFunction, [bool restricted = false, bool caseSensitive = true] )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
===Required Arguments===&lt;br /&gt;
*'''commandName:''' This is the name of the command you wish to attach a handler to. This is what must be typed into the console to trigger the function.&lt;br /&gt;
*'''handlerFunction:''' This is the function that you want the command to trigger, which has to be defined before you add the handler. This function can take two parameters, playerSource and commandName, followed by as many parameters you expect after your command (see below). These are all optional.&lt;br /&gt;
===Optional Arguments=== &lt;br /&gt;
{{OptionalArg}} &lt;br /&gt;
*'''restricted:''' Specify whether or not this command should be restricted by default. Use this on commands that should be inaccessible to everyone as default except special users specified in the ACL (Access Control List). This is to make sure admin commands such as ie. 'punish' won't be available to everyone if a server administrator forgets masking it in ACL. Make sure to add the command to your ACL under the proper group for it to be usefull (i.e &amp;lt;right name=&amp;quot;command.killEveryone&amp;quot; access=&amp;quot;true&amp;quot;&amp;gt;&amp;lt;/right&amp;gt;). This argument defaults to false if nothing is specified.&lt;br /&gt;
{{New feature|3|1.0|&lt;br /&gt;
*'''caseSensitive:''' Specifies if the command handler will ignore the case for this command name.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section name=&amp;quot;Client&amp;quot; class=&amp;quot;client&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;
bool addCommandHandler ( string commandName, function handlerFunction, [bool caseSensitive = true] )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
===Required Arguments===&lt;br /&gt;
*'''commandName:''' This is the name of the command you wish to attach a handler to. This is what must be typed into the console to trigger the function.&lt;br /&gt;
*'''handlerFunction:''' This is the function that you want the command to trigger, which has to be defined before you add the handler. This function can take two parameters, playerSource and commandName, followed by as many parameters you expect after your command (see below). These are all optional.&lt;br /&gt;
===Optional Arguments=== &lt;br /&gt;
{{OptionalArg}} &lt;br /&gt;
{{New feature|3|1.0|&lt;br /&gt;
*'''caseSensitive:''' Specifies if the command handler will ignore the case for this command name.&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Handler function parameters====&lt;br /&gt;
These are the parameters for the handler function that is called when the command is used.&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;player playerSource, string commandName, [string arg1, string arg2, ...] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* '''playerSource:''' The player who triggered the command. If not triggered by a player (e.g. by admin), this will be ''false''.&lt;br /&gt;
* '''commandName:''' The name of the command triggered. This is useful if multiple commands go through one function.&lt;br /&gt;
* '''arg1, arg2, ...:''' Each word after command name in the original command is passed here in a seperate variable. If there is no value for an argument, its variable will contain [[nil]]. You can deal with a variable number of arguments using the vararg expression, as shown in '''Example 4''' below.&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section name=&amp;quot;Client&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt; string commandName, [string arg1, string arg2, ...] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* '''commandName:''' The name of the command triggered. This is useful if multiple commands go through one function.&lt;br /&gt;
* '''arg1, arg2, ...:''' Each word after command name in the original command is passed here in a seperate variable. If there is no value for an argument, its variable will contain [[nil]]. You can deal with a variable number of arguments using the vararg expression, as shown in '''Example 4''' below.&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns ''true'' if the command handler was added successfully, ''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;
'''Example 1:''' This example defines a command handler for the command ''createmarker''. This will create a red marker at the position of the player player who uses it.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Define our function that will handle this command&lt;br /&gt;
function consoleCreateMarker ( playerSource )&lt;br /&gt;
	-- If a player triggered it (rather than the admin) then&lt;br /&gt;
	if ( playerSource ) then&lt;br /&gt;
		-- Get that player's position&lt;br /&gt;
		local x, y, z = getElementPosition ( playerSource )&lt;br /&gt;
		-- Create a size 2, red checkpoint marker at their position&lt;br /&gt;
		createMarker ( x, y, z, &amp;quot;checkpoint&amp;quot;, 2, 255, 0, 0, 255 )&lt;br /&gt;
		-- Output it in his chat box&lt;br /&gt;
		outputChatBox ( &amp;quot;You got a red marker&amp;quot;, playerSource )&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
-- Attach the 'consoleCreateMarker' function to the &amp;quot;createmarker&amp;quot; command&lt;br /&gt;
addCommandHandler ( &amp;quot;createmarker&amp;quot;, consoleCreateMarker )&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;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;hide&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 2:''' This example implements a ''set_vehicle_color'' command.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Define our function that will handle this command&lt;br /&gt;
function consoleSetVehicleColor ( playerSource, commandName, col1, col2, col3, col4 )&lt;br /&gt;
	-- If a player triggered this in-game&lt;br /&gt;
	if ( playerSource ) then&lt;br /&gt;
		-- Get the player's vehicle&lt;br /&gt;
		local playerVehicle = getPedOccupiedVehicle ( playerSource )&lt;br /&gt;
		-- If the player is in a vehicle and we've got at least 1 parameter&lt;br /&gt;
		if ( playerVehicle and col1 ) then&lt;br /&gt;
			-- Get the vehicle's existing color and use it if fewer than 4 arguments were passed&lt;br /&gt;
			local exCol1, exCol2, exCol3, exCol4 = getVehicleColor ( playerVehicle )&lt;br /&gt;
&lt;br /&gt;
			if not col2 then col2 = exCol2 end&lt;br /&gt;
			if not col3 then col3 = exCol3 end&lt;br /&gt;
			if not col4 then col4 = exCol4 end&lt;br /&gt;
&lt;br /&gt;
			-- Set the vehicle's color&lt;br /&gt;
			setVehicleColor ( playerVehicle, col1, col2, col3, col4 )&lt;br /&gt;
		else&lt;br /&gt;
			-- If we didn't get at least 1 parameter or the player doesn't have a vehicle, display some help text&lt;br /&gt;
			outputConsole ( &amp;quot;This function will set your current vehicle's colors. A vehicle can have up to 4 colors.&amp;quot;, playerSource )&lt;br /&gt;
			outputConsole ( &amp;quot;Syntax: set_vehicle_color color1 [ color2 color3 color4 ]&amp;quot;, playerSource )&lt;br /&gt;
			outputConsole ( &amp;quot;You must be in a vehicle to use this function.&amp;quot;, playerSource )&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
-- Attach the 'consoleSetVehicleColor' function to the &amp;quot;set_vehicle_color&amp;quot; command&lt;br /&gt;
addCommandHandler ( &amp;quot;set_vehicle_color&amp;quot;, consoleSetVehicleColor )&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;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;hide&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 3:''' This example makes use of Lua's vararg expression to implement a ''check_parameters'' command to count the number of parameters passed, merge them all into a single string and output it. This is also shows you how you can use table.concat to merge all the passed arguments. This is particularly useful when you want to read in a sentence of text passed from the user. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Define our function that will handle this command (which can accept a variable number of arguments after commandName)&lt;br /&gt;
function consoleCheckParameters ( playerSource, commandName, ... )&lt;br /&gt;
	-- If a player, not an admin, triggered it,&lt;br /&gt;
	if playerSource then&lt;br /&gt;
		-- Get the number of arguments in the arg table (arg table is the same as: {...})&lt;br /&gt;
		local parameterCount = #arg&lt;br /&gt;
		-- Output it to the player's chatbox&lt;br /&gt;
		outputChatBox ( &amp;quot;Number of parameters: &amp;quot; .. parameterCount, playerSource )&lt;br /&gt;
		-- Join them together in a single comma-separated string&lt;br /&gt;
		local stringWithAllParameters = table.concat( arg, &amp;quot;, &amp;quot; )&lt;br /&gt;
		-- Output this parameter list to the player's chatbox&lt;br /&gt;
		outputChatBox ( &amp;quot;Parameters passed: &amp;quot; .. stringWithAllParameters, playerSource )&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
-- Attach the 'consoleCheckParameters' function to the &amp;quot;check_parameters&amp;quot; command&lt;br /&gt;
addCommandHandler ( &amp;quot;check_parameters&amp;quot;, consoleCheckParameters )&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;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;hide&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 4:''' This example shows using a single function to handle multiple command handlers. This isn't advised for general usage, as it makes code harder to understand, but where multiple command handlers share some logic, it can be a useful way of reducing duplicated code. Generally, it would be preferable to put this shared logic in a separate function instead, as this gives you more control over the flow.&lt;br /&gt;
&amp;lt;!-- commands are case sensitive by default, in this example too --&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- make the function&lt;br /&gt;
function moneyCmd(player, cmd, amount)&lt;br /&gt;
    if getElementData(player, &amp;quot;canUseMoneyFunctions&amp;quot;) then -- the shared logic&lt;br /&gt;
        if cmd == &amp;quot;givemoney&amp;quot; then&lt;br /&gt;
            amount  = tonumber(amount)&lt;br /&gt;
            if amount then&lt;br /&gt;
                givePlayerMoney(player, amount)&lt;br /&gt;
            else&lt;br /&gt;
                outputChatBox(&amp;quot;[usage] /givemoney [amount]&amp;quot;, player)&lt;br /&gt;
            end&lt;br /&gt;
        else if cmd == &amp;quot;takemoney&amp;quot; then&lt;br /&gt;
            amount = tonumber(amount)&lt;br /&gt;
            if amount then&lt;br /&gt;
                takePlayerMoney(player, amount)&lt;br /&gt;
            else&lt;br /&gt;
                outputChatBox(&amp;quot;[usage] /takemoney [amount]&amp;quot;, player)&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
    else&lt;br /&gt;
        outputChatBox(&amp;quot;You aren't able to use this command&amp;quot;, player)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
addCommandHandler(&amp;quot;givemoney&amp;quot;, moneyCmd);&lt;br /&gt;
addCommandHandler(&amp;quot;takemoney&amp;quot;, moneyCmd);&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;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;false&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 5:''' This example shows you how to create a function inside a commandHandler. This example creates an object, in this case a dildo, and attaches it to the player. Notice that unlike the other examples, we dont add 'addCommandHandler' after the function has been created. We create the function inside the commandHandler. This is not something you have to do, but it can save some work and space in the end in some cases.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;addCommandHandler(&amp;quot;give_me_a_penis&amp;quot;,function(player)&lt;br /&gt;
local x,y,z = getElementPosition(player)&lt;br /&gt;
local myObject = createObject(321,x,y,z)&lt;br /&gt;
setElementCollisionsEnabled(myObject ,false)&lt;br /&gt;
attachElements(myObject ,player,0.03,0.2,-0.45,0,0,90)&lt;br /&gt;
end)&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;Client&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 1:''' This creates a GUI window and allows a player to change its alpha (transparency) value with a command. Note that, in a clientside script, the player using the command is not passed as a parameter to the handler function, since it is always the local player.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;--Create a window&lt;br /&gt;
myWindow = guiCreateWindow ( 0.30, 0.10, 0.5, 0.60, &amp;quot;GUI window title&amp;quot;, true )&lt;br /&gt;
&lt;br /&gt;
--Add a command handler to change the alpha of the GUI window. Usage example: 'alpha 0.15'&lt;br /&gt;
function changeAlpha ( commandName, alphaAmount )&lt;br /&gt;
	-- All command parameters are strings, so we'll convert the value to a number first&lt;br /&gt;
	alphaAmount = tonumber(alphaAmount)&lt;br /&gt;
	guiSetAlpha ( myWindow, alphaAmount )&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler ( &amp;quot;alpha&amp;quot;, changeAlpha )&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;Client&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;false&amp;quot;&amp;gt;&lt;br /&gt;
'''Example 2:''' This creates a GUI window and allows a player to change its alpha (transparency) value with a command. Note that, in a clientside script, the player using the command is not passed as a parameter to the handler function, since it is always the local player.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;function escapeMe ( commandName, taskType )&lt;br /&gt;
	local x, y, z = getElementPosition ( getLocalPlayer() ) --Get player's position&lt;br /&gt;
	setElementPosition ( getLocalPlayer(), x+(math.random(-10,10)), y+(math.random(-10,10)), z+(math.random(1,15)) ) --Move a player randomly to a nearby location. X is current x + a number between -10, 10 and so on.&lt;br /&gt;
end    &lt;br /&gt;
addCommandHandler ( &amp;quot;escape&amp;quot;, escapeMe ) --When player types &amp;quot;/escape&amp;quot; in chatbox or &amp;quot;escape&amp;quot; in console&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;
{{Server functions}}&lt;/div&gt;</summary>
		<author><name>Wafamde</name></author>
	</entry>
</feed>