unbindKey | Multi Theft Auto: Wiki Skip to content

unbindKey

Client-side
Server-side
Shared

This page is incomplete! Help wanted!

Please finish this page using the corresponding Old Wiki article.
Go to Contribution guidelines for more information.


Removes an existing key bind from the specified player.

Note

unbindKey will only work on binds that were added by the same resource

Note

unbindKey on the server may return true on failure

Note

If you call unbindKey twice, it will break other scripts: Issue 497

Syntax

unbindKey ( )

Code Examples

server

This function binds the player'sF1key to a functiongoMoowhich outputs a chat message when pressed. The key is then unbound so that it can effectively only be used once per life.

-- define the function that will be called when F1 is pressed
function goMoo( player )
outputChatBox ( getPlayerName ( player ) .. " says Mooooooo!" )
unbindKey ( player, "F1", "down", goMoo ) -- this function will no longer be triggered by the player, after removing the bind.
end
function playerSpawn ( )
bindKey ( source, "F1", "down", goMoo ) -- bind the player's F1 key to the 'goMoo' function defined above
end
addEventHandler ( "onPlayerSpawn", root, playerSpawn ) -- make the playerSpawn function be called when a player spawns