<?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=N0pe97</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=N0pe97"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/wiki/Special:Contributions/N0pe97"/>
	<updated>2026-05-06T08:16:54Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=ExecuteCommandHandler&amp;diff=62787</id>
		<title>ExecuteCommandHandler</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=ExecuteCommandHandler&amp;diff=62787"/>
		<updated>2019-05-24T14:49:10Z</updated>

		<summary type="html">&lt;p&gt;N0pe97: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server client function}}&lt;br /&gt;
__NOTOC__&lt;br /&gt;
This function will call all the attached functions of an existing console command, for a specified player.&lt;br /&gt;
{{Note|You can only execute commands created with addCommandHandler. You cannot execute MTA harcoded commands due to security reasons.}}&lt;br /&gt;
{{Note|Serverside commands can only be executed by the server. The same applies to the client side}}&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
==Syntax== &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;bool executeCommandHandler ( string commandName, player thePlayer, [ string args ] )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Required Arguments==&lt;br /&gt;
*'''commandName:''' The name of the command you wish to execute. This is what must be typed into the console to trigger the function.&lt;br /&gt;
*'''thePlayer:''' The player that will be presented as executer of the command to the handler function(s) of the command.&lt;br /&gt;
&lt;br /&gt;
==Optional Arguments==&lt;br /&gt;
{{OptionalArg}}&lt;br /&gt;
* '''args:''' Additional parameters that will be passed to the handler function(s) of the command that is called, separated by spaces.&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;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;bool executeCommandHandler ( string commandName, [ string args ] )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Required Arguments==&lt;br /&gt;
*'''commandName:''' The name of the command you wish to execute. This is what must be typed into the console to trigger the function.&lt;br /&gt;
&lt;br /&gt;
==Optional Arguments==&lt;br /&gt;
{{OptionalArg}}&lt;br /&gt;
* '''args:''' Additional parameters that will be passed to the handler function(s) of the command that is called, separated by spaces.&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns ''true'' if the command handler was called 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;
This example defines a command handler for the command ''createmarker'' (which creates a red marker at the caller's position). It then creates a second command handler ''createmarker2'' which will call the first one.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Define the function that will handle the 'createmarker' command&lt;br /&gt;
function consoleCreateMarker ( playerSource, commandName )&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;
		x, y, z = getElementPosition ( playerSource )&lt;br /&gt;
		-- Create a marker at their position&lt;br /&gt;
		createMarker ( x, y, z, 0, &amp;quot;checkpoint&amp;quot;, 255, 0, 0, 255 )&lt;br /&gt;
		-- Output it in the 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;
-- Add the function as a handler for the command&lt;br /&gt;
addCommandHandler ( &amp;quot;createmarker&amp;quot;, consoleCreateMarker )&lt;br /&gt;
&lt;br /&gt;
-- Define a second console command that will just call the first.&lt;br /&gt;
-- First define the function&lt;br /&gt;
function consoleCreateMarker2 ( playerSource, commandName )&lt;br /&gt;
	-- re-route back to the original&lt;br /&gt;
	executeCommandHandler ( &amp;quot;createmarker&amp;quot;, playerSource )&lt;br /&gt;
end&lt;br /&gt;
-- Then add it as a handler for the new console command&lt;br /&gt;
addCommandHandler ( &amp;quot;createmarker2&amp;quot;, consoleCreateMarker2 )&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>N0pe97</name></author>
	</entry>
</feed>