feat(esx_lib/interactions): move interactions to xLib

This commit is contained in:
ASTROWwwW
2026-06-16 21:03:41 +02:00
parent ca278be1da
commit 3fd3bf7877
4 changed files with 58 additions and 39 deletions
+4
View File
@@ -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
@@ -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)
-1
View File
@@ -55,7 +55,6 @@ client_scripts {
'client/modules/actions.lua',
'client/modules/death.lua',
'client/modules/npwd.lua',
'client/modules/interactions.lua',
}
ui_page {
@@ -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