ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Shared functions
  3. toggleControl

Function

toggleControl

Server and clientInput and controlsIdentical to MTA:SA

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).
enabledbool
false = 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