mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 02:01:31 +00:00
feat(es_extended): Interaction system
This commit is contained in:
@@ -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)
|
||||
@@ -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',
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user