From 6203ae43ba1ff86e58dbedea8b83d5db392d764b Mon Sep 17 00:00:00 2001 From: swkeep <49286776+swkeep@users.noreply.github.com> Date: Sun, 18 Feb 2024 13:10:41 +0330 Subject: [PATCH] feat: first qb-target compatibility test --- interactionMenu/fxmanifest.lua | 2 +- interactionMenu/lua/examples/qbtarget.lua | 77 ++++++++++++++++++++ interactionMenu/lua/frameworks/qb/client.lua | 74 +++++++++++++++++++ 3 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 interactionMenu/lua/examples/qbtarget.lua diff --git a/interactionMenu/fxmanifest.lua b/interactionMenu/fxmanifest.lua index 9944d6e..cb8271a 100644 --- a/interactionMenu/fxmanifest.lua +++ b/interactionMenu/fxmanifest.lua @@ -49,6 +49,6 @@ files { 'indicator.png' } -provide 'qb-target' +-- provide 'qb-target' lua54 'yes' diff --git a/interactionMenu/lua/examples/qbtarget.lua b/interactionMenu/lua/examples/qbtarget.lua new file mode 100644 index 0000000..fd18c64 --- /dev/null +++ b/interactionMenu/lua/examples/qbtarget.lua @@ -0,0 +1,77 @@ +-- _ +-- | | +-- _____ _| | _____ ___ _ __ +-- / __\ \ /\ / / |/ / _ \/ _ \ '_ \ +-- \__ \\ V V /| < __/ __/ |_) | +-- |___/ \_/\_/ |_|\_\___|\___| .__/ +-- | | +-- |_| +-- https://github.com/swkeep +if not DEVMODE then return end +CreateThread(function() + Wait(1000) + + local ped_position = vector4(-2037.74, 3179.25, 31.81, 241.19) + local ped_ = Util.spawnPed(GetHashKey('cs_brad'), ped_position) + + -- keep-hunting + exports['qb-target']:AddTargetEntity(ped_, { + options = { + { + icon = "fas fa-sack-dollar", + label = "slaughter", + canInteract = function(entity, distance, coords, name, bone) + print(entity, distance, coords, name, bone) + return IsEntityDead(entity) + end, + action = function(entity, distance) + if IsEntityDead(entity) == false then + return false + end + TriggerEvent('keep-hunting:client:slaughterAnimal', entity) + return true + end + } + }, + distance = 1.5 + }) + + -- qb-banking + Zones = { + [1] = { + position = vector4(154.52, -1035.78, 29.3, 250.43), + length = 6.2, + width = 2.0, + heading = 250, + minZ = 27.17, + maxZ = 31.17 + }, + [2] = { + position = vector4(154.52, -1035.78, 29.3, 250.43), + length = 6.6, + width = 2.0, + heading = 250, + minZ = 51.97, + maxZ = 55.97 + }, + } + + for k, v in pairs(Config.Zones) do + exports["qb-target"]:AddBoxZone("Bank_" .. k, v.position, v.length, v.width, { + name = "Bank_" .. k, + heading = v.heading, + minZ = v.minZ, + maxZ = v.maxZ + }, { + options = { + { + type = "client", + event = "qb-banking:openBankScreen", + icon = "fas fa-university", + label = "Access Bank", + } + }, + distance = 1.5 + }) + end +end) diff --git a/interactionMenu/lua/frameworks/qb/client.lua b/interactionMenu/lua/frameworks/qb/client.lua index d51553e..b533844 100644 --- a/interactionMenu/lua/frameworks/qb/client.lua +++ b/interactionMenu/lua/frameworks/qb/client.lua @@ -33,3 +33,77 @@ end) RegisterNetEvent('QBCore:Player:SetPlayerData', function(val) end) + +local function exportHandler(exportName, func) + AddEventHandler(('__cfx_export_qb-target_%s'):format(exportName), function(setCB) + setCB(func) + end) +end + +exportHandler('AddTargetEntity', function(entities, data) + local menu = { + entity = entities, + options = {}, + maxDistance = data.distance or 3 + } + + if type(entities) == 'table' then + + else + for key, value in pairs(data.options) do + local option = {} + menu.options[#menu.options + 1] = option + + if value.canInteract then + option['canInteract'] = value.canInteract + end + + if value.action then + option['action'] = { + type = 'sync', + func = value.action + } + end + + option['icon'] = value.icon + option['label'] = value.label + end + end + + exports['interactionMenu']:Create(menu) +end) + +exportHandler('AddBoxZone', function(name, center, length, width, options, targetoptions) + local menu = { + id = name, + position = center, + options = {}, + maxDistance = targetoptions.distance or 3 + } + + for key, value in pairs(targetoptions.options) do + local option = {} + menu.options[#menu.options + 1] = option + + if value.canInteract then + option['canInteract'] = value.canInteract + end + + if value.action then + option['action'] = { + type = 'sync', + func = value.action + } + elseif value.event then + option['event'] = { + type = value['type'], + name = value['event'] + } + end + + option['icon'] = value.icon + option['label'] = value.label + end + + exports['interactionMenu']:Create(menu) +end)