diff --git a/[core]/es_extended/client/compat.lua b/[core]/es_extended/client/compat.lua index 02948a23..cca17842 100644 --- a/[core]/es_extended/client/compat.lua +++ b/[core]/es_extended/client/compat.lua @@ -63,3 +63,7 @@ ESX.RemovePointInternal = xLib.points.remove ESX.HidePointInternal = xLib.points.hide StartPointsLoop = xLib.points.startLoop ESX.Point = xLib.point + +ESX.RegisterInteraction = xLib.interactions.register +ESX.RemoveInteraction = xLib.interactions.remove +ESX.GetInteractKey = xLib.interactions.getInteractKey diff --git a/[core]/es_extended/client/modules/interactions.lua b/[core]/es_extended/client/modules/interactions.lua deleted file mode 100644 index 0a1a31fe..00000000 --- a/[core]/es_extended/client/modules/interactions.lua +++ /dev/null @@ -1,38 +0,0 @@ -local interactions = {} -local pressedInteractions = {} - -function ESX.RemoveInteraction(name) - if not interactions[name] then return end - interactions[name] = nil -end - -ESX.RegisterInteraction = function(name, onPress, condition) - interactions[name] = { - condition = condition or function() return true end, - onPress = onPress, - creator = GetInvokingResource() or "es_extended" - } -end - -function ESX.GetInteractKey() - local hash = joaat('esx_interact') | 0x80000000 - return GetControlInstructionalButton(0, hash, true):sub(3) -end - -ESX.RegisterInput("esx_interact", "Interact", "keyboard", "e", function() - for _, interaction in pairs(interactions) do - local success, result = pcall(interaction.condition) - if success and result then - pressedInteractions[#pressedInteractions+1] = interaction - interaction.onPress() - end - end -end) - -AddEventHandler("onResourceStop", function(resource) - for name, interaction in pairs(interactions) do - if interaction.creator == resource then - interactions[name] = nil - end - end -end) \ No newline at end of file diff --git a/[core]/es_extended/fxmanifest.lua b/[core]/es_extended/fxmanifest.lua index bf9cea0b..72c552eb 100644 --- a/[core]/es_extended/fxmanifest.lua +++ b/[core]/es_extended/fxmanifest.lua @@ -55,7 +55,6 @@ client_scripts { 'client/modules/actions.lua', 'client/modules/death.lua', 'client/modules/npwd.lua', - 'client/modules/interactions.lua', } ui_page { diff --git a/[core]/esx_lib/imports/interactions/client.lua b/[core]/esx_lib/imports/interactions/client.lua new file mode 100644 index 00000000..01b88c09 --- /dev/null +++ b/[core]/esx_lib/imports/interactions/client.lua @@ -0,0 +1,54 @@ +---@class interactionslib +xLib.interactions = {} + +local interactions = {} +local pressedInteractions = {} + +---@param name string +function xLib.interactions.remove(name) + if not interactions[name] then return end + interactions[name] = nil +end + +---@param name string +---@param onPress function +---@param condition? function +function xLib.interactions.register(name, onPress, condition) + interactions[name] = { + condition = condition or function() return true end, + onPress = onPress, + creator = GetInvokingResource() or "es_extended" + } +end + +---@return string +function xLib.interactions.getInteractKey() + local hash = joaat("esx_interact") | 0x80000000 + return GetControlInstructionalButton(0, hash, true):sub(3) +end + +xLib.addKeybind({ + name = "esx_interact", + description = "Interact", + defaultMapper = "keyboard", + defaultKey = "e", + onPressed = function() + for _, interaction in pairs(interactions) do + local success, result = pcall(interaction.condition) + if success and result then + pressedInteractions[#pressedInteractions + 1] = interaction + interaction.onPress() + end + end + end +}) + +AddEventHandler("onResourceStop", function(resource) + for name, interaction in pairs(interactions) do + if interaction.creator == resource then + interactions[name] = nil + end + end +end) + +return xLib.interactions