- Documentation
- Shared functions
- toggleControl
Function
toggleControl
Enables or disables one game control, e.g. shooting (fire), jumping (jump) or entering vehicles (enter_exit). A disabled control ignores the player's keys. On the server you pass a player or root.
Syntax
Server
bool toggleControl(player thePlayer, string control, bool enabled)Client
bool toggleControl(string control, bool enabled)Arguments
thePlayerplayer- A player or
root(server only). controlstring- The control name (
getControlNames). enabledboolfalse= blocked.
Returns
On the client true when the game blocks this control, false for a name outside the list below.
Example
A no-shooting zone at the spawn.
local safe = createColSphere(2495, -1687, 13.5, 30)
addEventHandler("onColShapeHit", safe, function(el)
if getElementType(el) == "player" then toggleControl(el, "fire", false) end
end)
addEventHandler("onColShapeLeave", safe, function(el)
if getElementType(el) == "player" then toggleControl(el, "fire", true) end
end)
See also
toggleAllControlsEnables or disables all game controls at once (e.g. during a cutscene or when freezing a player). Chat, console andbindKeykeys keep working.isControlEnabledChecks whether a game control is enabled (not blocked withtoggleControlortoggleAllControls).getControlNamesReturns the game control names accepted bytoggleControl,setControlStateandisControlEnabled.