DisableControls
Reference-counted control disabling — a control stays off while any caller still wants it off.
Reference-counted control disabling — a control stays off while any caller still wants it off.
lib.disableControls disables FiveM controls with reference counting. Several systems can request
the same control, and it stays disabled as long as at least one reference is active — so closing your
menu never re-enables a control another script still needs.
lib.disableControls.add(24, 25, 257) -- attack, aim, hold-to-aim
-- ... later ...
lib.disableControls.remove(24, 25, 257)| Function | Description |
|---|---|
add(...) | Increment the counter for each control ID and disable it every frame. |
remove(...) | Decrement the counter. The control re-enables once it reaches 0. |
clear(...) | Force-remove the controls regardless of their counter — for a global reset only. |
add(...)remove(...)0.clear(...)Control IDs come from the FiveM controls reference;
lib.keys maps named keys to them.
local function openMenu()
lib.disableControls.add(24, 25, 47, 58)
end
local function closeMenu()
lib.disableControls.remove(24, 25, 47, 58)
endAlways pair an add with a matching remove — an add without remove keeps the control disabled
for the whole session. Calling remove more often than add is harmless (the counter won't drop
below zero), but it usually signals a logic bug upstream. clear ignores the counter and force-removes
the control: if another system had also add'd it, that one gets re-enabled by mistake — prefer
remove with the same controls you passed to add.