GetKeyBoundToCommand: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "{{Server client function}} This function allow you get first key binded to command. ==Syntax== <syntaxhighlight lang="lua"> string getKeyBoundToCommand( string command ) </syntaxhighlight> ===Required Ar...")
 
mNo edit summary
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Server client function}}
__NOTOC__
This function allow you get first key binded to command.
{{Client function}}
This function allow you get first key bound to command.


==Syntax==  
==Syntax==  
Line 14: Line 15:


==Example==  
==Example==  
<section name="Client" class="client" show="true">
This example adds a /getcommandbind command, allowing players to see what keys are bound to the given command.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function yourFunction()
--This function is executed when the player uses the /getcommandbind [command] command.
--your function here
--It outputs the key the command is bound to (if it is bound).
local function playerCommand(_, command)
if not command then --if no command name was given, output a syntax error message.
outputChatBox("* Syntax: /getcommandbind [command name] .", 255, 0, 0)
return
end
local keyName = getKeyBoundToCommand(command)
if keyName then
outputChatBox("* The command /"..command.." is bound to the "..keyName.." key.", 0, 0, 255)
else
outputChatBox("* The command /"..command.." is not bound to any keys.", 0, 0, 255)
end
end
end
 
addCommandHandler("getcommandbind", playerCommand)
addCommandHandler("bindedcommand",yourFunction)
 
function bindHandler()
  local bindedKey = getKeyBoundToCommand("bindedcommand") --get binded key
    if not bindedKey then
      bindedKey = "z"
      bindKey(bindedKey,"down","bindedcommand")  --if key is not exist then bind it by syntax 2
    end
  outputChatBox("Press '"..bindedKey.."' for do yourFunction",255,255,0,true) --after all done output it in chatbox
end
addEventHandler("onClientResourceStart", bindHandler)
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Input_functions}}
{{Client_input_functions}}

Latest revision as of 08:27, 23 June 2015

This function allow you get first key bound to command.

Syntax

string getKeyBoundToCommand( string command )

Required Arguments

  • command: command what you need check.

Returns

Returns a string of first key binded to current command.

Example

This example adds a /getcommandbind command, allowing players to see what keys are bound to the given command.

--This function is executed when the player uses the /getcommandbind [command] command.
--It outputs the key the command is bound to (if it is bound).
local function playerCommand(_, command)
	if not command then --if no command name was given, output a syntax error message.
		outputChatBox("* Syntax: /getcommandbind [command name] .", 255, 0, 0)
		return
	end
	
	local keyName = getKeyBoundToCommand(command)
	if keyName then
		outputChatBox("* The command /"..command.." is bound to the "..keyName.." key.", 0, 0, 255)
	else
		outputChatBox("* The command /"..command.." is not bound to any keys.", 0, 0, 255)
	end
end
addCommandHandler("getcommandbind", playerCommand)

See Also