2022-10-13 17:58:45 -06:00
|
|
|
---@class CKeybind
|
|
|
|
|
---@field name string
|
|
|
|
|
---@field description string
|
|
|
|
|
---@field keybind string
|
2022-10-14 11:01:57 +11:00
|
|
|
---@field disabled? boolean
|
2022-10-13 17:58:45 -06:00
|
|
|
---@field disable? fun(self: CKeybind, toggle: boolean)
|
|
|
|
|
---@field onPressed? fun(self: CKeybind)
|
|
|
|
|
---@field onReleased? fun(self: CKeybind)
|
|
|
|
|
|
|
|
|
|
local keybinds = {}
|
|
|
|
|
|
|
|
|
|
local function disableKeybind(self, toggle)
|
|
|
|
|
keybinds[self.name].disabled = toggle
|
|
|
|
|
end
|
|
|
|
|
|
2022-10-14 11:01:57 +11:00
|
|
|
local IsPauseMenuActive = IsPauseMenuActive
|
|
|
|
|
|
2022-10-13 17:58:45 -06:00
|
|
|
lib.keybinds = {
|
2022-10-14 11:01:57 +11:00
|
|
|
---@param data CKeybind
|
2022-10-13 17:58:45 -06:00
|
|
|
---@return CKeybind
|
2022-10-14 11:01:57 +11:00
|
|
|
new = function(data)
|
|
|
|
|
data.keybind = data.keybind or ''
|
|
|
|
|
data.disabled = data.disabled or false
|
|
|
|
|
data.disable = disableKeybind
|
|
|
|
|
|
|
|
|
|
RegisterCommand('+' .. data.name, function()
|
|
|
|
|
if not data.onReleased or data.disabled or IsPauseMenuActive() then return end
|
|
|
|
|
data:onPressed()
|
2022-10-13 17:58:45 -06:00
|
|
|
end)
|
2022-10-14 11:01:57 +11:00
|
|
|
|
|
|
|
|
RegisterCommand('-' .. data.name, function()
|
|
|
|
|
if not data.onReleased or data.disabled or IsPauseMenuActive() then return end
|
|
|
|
|
data:onReleased()
|
2022-10-13 17:58:45 -06:00
|
|
|
end)
|
2022-10-14 11:01:57 +11:00
|
|
|
|
|
|
|
|
RegisterKeyMapping('+' .. data.name, data.description, 'keyboard', data.keybind)
|
|
|
|
|
|
|
|
|
|
SetTimeout(500, function()
|
|
|
|
|
TriggerEvent('chat:removeSuggestion', ('/+%s'):format(data.name))
|
|
|
|
|
TriggerEvent('chat:removeSuggestion', ('/-%s'):format(data.name))
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
keybinds[data.name] = data
|
|
|
|
|
return data
|
2022-10-13 17:58:45 -06:00
|
|
|
end,
|
|
|
|
|
|
2022-10-14 11:01:57 +11:00
|
|
|
---@return CKeybind?
|
2022-10-13 17:58:45 -06:00
|
|
|
get = function(name)
|
2022-10-14 11:01:57 +11:00
|
|
|
return keybinds[name]
|
2022-10-13 17:58:45 -06:00
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-14 11:01:57 +11:00
|
|
|
return lib.keybinds
|