Skip to content

Commit

Permalink
feat: first qb-target compatibility test
Browse files Browse the repository at this point in the history
  • Loading branch information
swkeep committed Feb 18, 2024
1 parent e900866 commit 6203ae4
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 1 deletion.
2 changes: 1 addition & 1 deletion interactionMenu/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ files {
'indicator.png'
}

provide 'qb-target'
-- provide 'qb-target'

lua54 'yes'
77 changes: 77 additions & 0 deletions interactionMenu/lua/examples/qbtarget.lua
Original file line number Diff line number Diff line change
@@ -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)
74 changes: 74 additions & 0 deletions interactionMenu/lua/frameworks/qb/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 6203ae4

Please sign in to comment.