Skip to content

OnPlayerKeyBinding

A player pressed or let go of a key the mode declared.

name is always one the mode declared with RegisterKeyBinding - a press of any other name is dropped by the server - and it comes whichever physical key the player has bound to it. pressed is true when the key went down and false when it came up. A held key is reported down once and up once (its repeats are not sent), and the game lets go of every key it holds when its window loses the focus. A modified game or a reload of the mode between the press and the release can still break that pairing, so a mode that must not act twice, or must not leave something on, keeps its own record of who is holding what.

The press is the player’s game’s word: a modified game may send presses of a registered name that no key made. Use a binding to ask for something the player may do anyway, and check the rest as you would any input from a player.

function OnPlayerKeyBinding(pid, name, pressed)
-- ...
end
Parameter Type
pid number the player
name string the binding’s name, as the mode declared it
pressed boolean true when the key went down, false when it came up

nothing

local whistled = {}
function OnPlayerKeyBinding(pid, name, pressed)
if name == "horse.whistle" and pressed and not whistled[pid] then
whistled[pid] = true
callHorse(pid)
SetTimer(function() whistled[pid] = nil end, 5000, false) -- once every five seconds
end
end

RegisterKeyBinding · the Key bindings group of the index