Skip to content

RegisterKeyBinding

Declares a key the mode wants - a name, what it is for and the key it starts on.

Every player’s game is told the list of bindings when they join and whenever it changes, so a binding declared later reaches the players who are already in. The player’s own choice of key for a binding, when they made one, wins over defaultKey; the game keeps it for the server.

The name is 1 to 32 of a-z 0-9 _ . : - (capitals are lowered): the name OnPlayerKeyBinding answers to, and the one a player gives KcdMp_bind; dots make readable groups ("arena.ready"). description is one line, at most 96 characters, that the player’s list of bindings shows. defaultKey is the game’s own name for a key - "f2", "insert", "y" - or "" for none until the player binds one; f9, f12, escape, lwin and rwin are refused. A default that the game keeps for itself (see above) is accepted, and leaves the binding without a key until the player picks one, so pick keys the game leaves alone.

At most 32 bindings; declaring a name again changes its description and default key. A reload of the mode empties the list: declare the bindings in OnGameModeInit.

The answer is true, or false and the reason: "a binding name is 1-32 of a-z, 0-9 and _ . : -", "the description is over 96 characters", "the default key is the engine's name for a key (f2, insert, y ...)", "f9 is reserved" (or whichever it was) or "too many key bindings (32 at most)".

RegisterKeyBinding(name, description, defaultKey)
Parameter Type
name string the binding’s name - 1 to 32 of a-z 0-9 _ . : -
description string one line on what the key is for, 96 characters at most
defaultKey string the key it starts on, the game’s name for it ("f2"); "" for none

true, or false, reason - the reason as a person reads it

function OnGameModeInit()
RegisterKeyBinding("map.toggle", "Open the map of the guild lands", "f2")
RegisterKeyBinding("horse.whistle", "Whistle for your horse", "f3")
local ok, why = RegisterKeyBinding("menu", "Open the menu", "escape")
if not ok then Log("menu key: " .. why) end --> menu key: escape is reserved
end

OnPlayerKeyBinding · the Key bindings group of the index