IsKeyBound: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
mNo edit summary
 
(9 intermediate revisions by 7 users not shown)
Line 1: Line 1:
__NOTOC__  
{{Server function}}
This function can be used to find out if a key has already been bound.
__NOTOC__
This function can be used to find out if a key has already been bound. If you do not specify a keyState or handler, any instances of key being bound will cause isKeyBound to return true.


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">bool isKeyBound ( player thePlayer, string key, [ string keyState, string function ] ) </syntaxhighlight>  
<syntaxhighlight lang="lua">bool isKeyBound ( player thePlayer, string key, [ string keyState, function handler ] ) </syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
Line 13: Line 14:
**'''"up":''' when the key is released
**'''"up":''' when the key is released
**'''"down":''' when the key is pressed
**'''"down":''' when the key is pressed
*'''function:''' The function you're checking against
*'''handler:''' The function you're checking against
Note: If you do not specify a ''keyState'' or ''function'', any instances of ''key'' being bound will be count.
 
===Returns===
Returns ''true'' if the key is bound, ''false'' otherwise.


==Example==   
==Example==   
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- This function tells everyone in the server if someone has numpad 9 bound!
function onPlayerJoin ()
  if (isKeyBound (source,"num_9")) then -- if num pad 9 is bound
    outputChatBox (getPlayerName (source) .. " has bound numpad 9!",getRootElement(),255,0,0,false) -- let see everybody that he has binded it
  end
end
addEventHandler ("onPlayerJoin",getRootElement(),onPlayerJoin) -- add event.
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Input functions}}
{{Input functions|server}}

Latest revision as of 22:33, 6 September 2024

This function can be used to find out if a key has already been bound. If you do not specify a keyState or handler, any instances of key being bound will cause isKeyBound to return true.

Syntax

bool isKeyBound ( player thePlayer, string key, [ string keyState, function handler ] ) 

Required Arguments

  • thePlayer: The player you're checking.
  • key: The key you're checking. See Key names for a list of valid key names.

Optional Arguments

  • keyState: Is the state of the key when it calls the function, Can be either:
    • "up": when the key is released
    • "down": when the key is pressed
  • handler: The function you're checking against

Returns

Returns true if the key is bound, false otherwise.

Example

-- This function tells everyone in the server if someone has numpad 9 bound!
function onPlayerJoin ()
  if (isKeyBound (source,"num_9")) then -- if num pad 9 is bound
    outputChatBox (getPlayerName (source) .. " has bound numpad 9!",getRootElement(),255,0,0,false) -- let see everybody that he has binded it
  end
end
addEventHandler ("onPlayerJoin",getRootElement(),onPlayerJoin) -- add event.

See Also