mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
BREAKING! Since the folder name determines the import name (i.e. lib.callbacks), use better names and lowerCamelCase.
54 lines
1.0 KiB
Lua
54 lines
1.0 KiB
Lua
--- Call on frame to disable all stored keys.
|
|
--- ```
|
|
--- disableControls()
|
|
--- ```
|
|
local disableControls = {}
|
|
|
|
---@param ... number
|
|
function disableControls:Add(...)
|
|
local keys = type(...) == 'table' and ... or {...}
|
|
for i=1, #keys do
|
|
local key = keys[i]
|
|
if self[key] then
|
|
self[key] += 1
|
|
else
|
|
self[key] = 1
|
|
end
|
|
end
|
|
end
|
|
|
|
---@param ... number
|
|
function disableControls:Remove(...)
|
|
local keys = type(...) == 'table' and ... or {...}
|
|
for i=1, #keys do
|
|
local key = keys[i]
|
|
local exists = self[key]
|
|
if exists and exists > 1 then
|
|
self[key] -= 1
|
|
else
|
|
self[key] = nil
|
|
end
|
|
end
|
|
end
|
|
|
|
---@param ... number
|
|
function disableControls:Clear(...)
|
|
local keys = type(...) == 'table' and ... or {...}
|
|
for i=1, #keys do
|
|
self[keys[i]] = nil
|
|
end
|
|
end
|
|
|
|
local keys = {}
|
|
local DisableControlAction = DisableControlAction
|
|
local pairs = pairs
|
|
|
|
return setmetatable(disableControls, {
|
|
__index = keys,
|
|
__newindex = keys,
|
|
__call = function()
|
|
for k in pairs(keys) do
|
|
DisableControlAction(0, k, true)
|
|
end
|
|
end
|
|
}) |