feat(es_extended): Interaction system

This commit is contained in:
Kasey FItton
2024-10-27 01:35:13 +00:00
parent 42a376f974
commit 20250951fb
2 changed files with 39 additions and 0 deletions
@@ -0,0 +1,38 @@
local interactions = {}
local pressedInteractions = {}
function ESX.RemoveInteraction(name)
if not interactions[name] then return end
interactions[name] = nil
end
ESX.ReigsterInteraction = 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
@@ -47,6 +47,7 @@ client_scripts {
'client/modules/actions.lua',
'client/modules/death.lua',
'client/modules/npwd.lua',
'client/modules/interactions.lua',
'client/modules/scaleform.lua',
'client/modules/streaming.lua',
}