Skip to content

Commit c9fdbb2

Browse files
committed
finish and load compat files
1 parent 653fa23 commit c9fdbb2

4 files changed

Lines changed: 59 additions & 57 deletions

File tree

client/compat/interact.lua

Lines changed: 52 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,124 @@
1-
--- compat for https://github.com/darktrovx/interact
2-
3-
-- Utility function to generate UUIDs (for compatibility with the second script)
41
local function generateUUID()
52
return ('xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'):gsub('[xy]', function(c)
63
local v = (c == 'x') and math.random(0, 0xf) or math.random(8, 0xb)
74
return ('%x'):format(v)
85
end)
96
end
107

11-
-- Export handler to register functions as exports
128
local function exportHandler(exportName, func)
139
AddEventHandler(('__cfx_export_interact_%s'):format(exportName), function(setCB)
1410
setCB(func)
1511
end)
1612
end
1713

18-
-- Convert options from the second script to sleepless_interact's Option structure
19-
local function convertOptions(options, resource, id)
14+
local function convert(data, resource)
2015
local converted = {}
21-
for _, option in ipairs(options) do
16+
local id = data.id or generateUUID()
17+
for i = 1, #data.options do
18+
local option = data.options[i]
2219
local newOption = {
2320
label = option.label or "Unnamed Option",
2421
icon = option.icon,
2522
iconColor = option.iconColor,
26-
distance = option.distance,
23+
distance = data.interactDst or 1.0,
2724
canInteract = option.canInteract,
28-
name = option.name or id,
25+
groups = data.groups,
26+
name = id,
2927
resource = resource,
30-
offset = option.offset,
31-
bones = option.bone, -- Map 'bone' to 'bones' in sleepless_interact
32-
onSelect = option.onSelect,
33-
cooldown = option.cooldown,
34-
export = option.export,
28+
offset = data.offset,
29+
bones = (data.bone and { data.bone }) or nil,
30+
onSelect = option.action,
31+
cooldown = 1000,
3532
event = option.event,
3633
serverEvent = option.serverEvent,
37-
command = option.command
3834
}
39-
-- Handle groups (jobs) if present
40-
if option.groups or option.job then
41-
newOption.groups = option.groups or option.job
42-
end
4335
converted[#converted + 1] = newOption
4436
end
45-
return converted
37+
return converted, id
4638
end
4739

48-
-- AddInteraction (coords-based)
4940
exportHandler('AddInteraction', function(data)
5041
local coords = data.coords
51-
local options = convertOptions(data.options, GetInvokingResource())
42+
local options = convert(data, GetInvokingResource())
5243
local id = interact.addCoords(coords, options)
53-
return id -- Returns the coordinate-based ID from sleepless_interact
44+
return id
5445
end)
5546

56-
-- AddLocalEntityInteraction
5747
exportHandler('AddLocalEntityInteraction', function(data)
5848
local entity = data.entity
59-
local options = convertOptions(data.options, GetInvokingResource())
60-
interact.addLocalEntity({ entity }, options)
61-
-- Generate a UUID since addLocalEntity doesn't return an ID
62-
return generateUUID()
49+
local options, id = convert(data, GetInvokingResource())
50+
interact.addLocalEntity(entity, options)
51+
return id
6352
end)
6453

65-
-- AddEntityInteraction (networked entity)
6654
exportHandler('AddEntityInteraction', function(data)
6755
local netId = data.netId
68-
local options = convertOptions(data.options, GetInvokingResource())
69-
interact.addEntity({ netId }, options)
70-
-- Generate a UUID since addEntity doesn't return an ID
71-
return generateUUID()
56+
local options, id = convert(data, GetInvokingResource())
57+
interact.addEntity(netId, options)
58+
return id
7259
end)
7360

74-
-- AddGlobalVehicleInteraction
7561
exportHandler('AddGlobalVehicleInteraction', function(data)
76-
local options = convertOptions(data.options, GetInvokingResource())
62+
local options, id = convert(data, GetInvokingResource())
7763
interact.addGlobalVehicle(options)
78-
-- Generate a UUID since addGlobalVehicle doesn't return an ID
79-
return generateUUID()
64+
return id
8065
end)
8166

82-
-- AddGlobalPlayerInteraction
8367
exportHandler('addGlobalPlayerInteraction', function(data)
84-
local options = convertOptions(data.options, GetInvokingResource())
68+
local options, id = convert(data, GetInvokingResource())
8569
interact.addGlobalPlayer(options)
86-
-- Generate a UUID since addGlobalPlayer doesn't return an ID
87-
return generateUUID()
70+
return id
8871
end)
8972

90-
-- AddModelInteraction
9173
exportHandler('AddModelInteraction', function(data)
9274
local model = data.model
93-
local options = convertOptions(data.options, GetInvokingResource())
75+
local options, id = convert(data, GetInvokingResource())
9476
interact.addModel(model, options)
95-
-- Generate a UUID since addModel doesn't return an ID
96-
return generateUUID()
77+
return id
9778
end)
9879

99-
-- RemoveInteraction (by ID)
10080
exportHandler('RemoveInteraction', function(id)
101-
interact.removeCoords(id, nil, true) -- Remove coords-based interaction by ID
81+
interact.removeCoords(id, nil, true)
10282
end)
10383

104-
-- RemoveLocalEntityInteraction
10584
exportHandler('RemoveLocalEntityInteraction', function(entity, id)
106-
interact.removeLocalEntity({ entity }, id)
85+
interact.removeLocalEntity(entity, id)
10786
end)
10887

109-
-- RemoveEntityInteraction
11088
exportHandler('RemoveEntityInteraction', function(netId, id)
111-
interact.removeEntity({ netId }, id)
89+
interact.removeEntity(netId, id)
11290
end)
11391

114-
-- RemoveModelInteraction
11592
exportHandler('RemoveModelInteraction', function(model, id)
11693
interact.removeModel(model, id)
11794
end)
11895

119-
-- RemoveGlobalVehicleInteraction
12096
exportHandler('RemoveGlobalVehicleInteraction', function(id)
12197
interact.removeGlobalVehicle(id)
12298
end)
12399

124-
-- RemoveGlobalPlayerInteraction
125100
exportHandler('RemoveGlobalPlayerInteraction', function(id)
126101
interact.removeGlobalPlayer(id)
127-
end)
102+
end)
103+
104+
105+
106+
-- local id = exports.interact:AddInteraction({
107+
-- coords = GetEntityCoords(cache.ped),
108+
-- distance = 8.0, -- optional
109+
-- interactDst = 1.0, -- optional
110+
-- id = 'myCoolUniqueId', -- needed for removing interactions
111+
-- name = 'interactionName', -- optional
112+
-- options = {
113+
-- {
114+
-- label = 'Hello World!',
115+
-- action = function(entity, coords, args)
116+
-- print(entity, coords, json.encode(args))
117+
-- end,
118+
-- },
119+
-- }
120+
-- })
121+
122+
-- SetTimeout(3000, function()
123+
-- exports.interact:RemoveInteraction(id)
124+
-- end)

client/main.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ local store = require 'client.modules.store'
33
local config = require 'client.modules.config'
44
local utils = require 'client.modules.utils'
55

6+
require 'client.compat.qtarget'
7+
require 'client.compat.ox_target'
8+
require 'client.compat.interact'
9+
610
---@type boolean
711
local drawLoopRunning = false
812

@@ -418,7 +422,7 @@ local function drawLoop()
418422

419423
SetDrawOrigin(coords.x, coords.y, coords.z)
420424

421-
if not foundValid and data.validCount > 0 then
425+
if not foundValid and data.validOpts and data.validCount > 0 then
422426
foundValid = true
423427
DrawSprite(dui.instance.dictName, dui.instance.txtName, 0.0, 0.0, 1.0, 1.0, 0.0, 255, 255, 255, 255)
424428
local newClosestId = item.bone or item.offset or item.entity or item.coordId

client/modules/config.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ config.themeColor = { 28, 100, 184, 200 } --- r, g, b, a
1111
config.IndicatorSprite = { dict = 'shared', txt = 'emptydot_32' }
1212

1313
-- boolean true/false use a keybind to show and hide the interactions
14-
config.useShowKeyBind = true
14+
config.useShowKeyBind = false
1515

1616
-- string default key mapping for the show interactions keybind
1717
config.defaultShowKeyBind = 'LMENU'

fxmanifest.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ files {
1919
'web/**',
2020
'client/modules/*.lua',
2121
'client/framework/*.lua',
22+
'client/compat/*.lua'
2223
}
2324

2425
provides {

0 commit comments

Comments
 (0)