From 20250951fbc6ee4248f8dbeacbeaa5ef685b047b Mon Sep 17 00:00:00 2001 From: Kasey FItton Date: Sun, 27 Oct 2024 01:35:13 +0000 Subject: [PATCH] feat(es_extended): Interaction system --- .../client/modules/interactions.lua | 38 +++++++++++++++++++ [core]/es_extended/fxmanifest.lua | 1 + 2 files changed, 39 insertions(+) create mode 100644 [core]/es_extended/client/modules/interactions.lua diff --git a/[core]/es_extended/client/modules/interactions.lua b/[core]/es_extended/client/modules/interactions.lua new file mode 100644 index 00000000..64599e4f --- /dev/null +++ b/[core]/es_extended/client/modules/interactions.lua @@ -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) \ No newline at end of file diff --git a/[core]/es_extended/fxmanifest.lua b/[core]/es_extended/fxmanifest.lua index b4b28bf1..48afd7e3 100644 --- a/[core]/es_extended/fxmanifest.lua +++ b/[core]/es_extended/fxmanifest.lua @@ -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', }