Skip to content

Commit dae7044

Browse files
committed
feat: add new "zone" tracker method
1 parent d98acb7 commit dae7044

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

‎interactionMenu/lua/client/interact.lua‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,17 +255,26 @@ CreateThread(function()
255255

256256
if isPauseMenuState == 0 and isNuiFocused ~= 1 then
257257
if not closestEntity then
258-
local playerPosition = GetEntityCoords(playerPed)
259258
local model = 0
260259
local entityType = 0
260+
local playerPosition = GetEntityCoords(playerPed)
261261
-- #TODO: Give onPosition priority?!
262262
-- It's going to lower resource usage, BUT if we have two colliding menus, we might not be able to detect them.
263263
-- reason: when the player is inside the `entity detector`, we won't be able to use rayCast to detect other menus.
264264

265265
local hitPosition, playerDistance, entity
266-
if closestZoneId == nil and (not StateManager.get("disableRayCast") or isInVehicle ~= 1) then
266+
if not StateManager.get("disableRayCast") and isInVehicle == false then
267267
hitPosition, entity, playerDistance = Util.rayCast(10, playerPed)
268268

269+
if hitPosition and not StateManager.get("disableZoneRayCast") then
270+
for key, value in pairs(Container.zones) do
271+
if value.tracker == "hit" and value:isPointInside(hitPosition) then
272+
closestZoneId = value.name
273+
break
274+
end
275+
end
276+
end
277+
269278
if entity then
270279
entityType = GetEntityType(entity)
271280
if entityType ~= 0 then
@@ -313,8 +322,10 @@ end)
313322

314323
AddEventHandler("interactionMenu:zoneTracker", function(zone_name, state)
315324
if zone_name and state then
325+
StateManager.set("disableZoneRayCast", true)
316326
closestZoneId = zone_name
317327
else
328+
StateManager.set("disableZoneRayCast", false)
318329
closestZoneId = nil
319330
end
320331
end)
@@ -489,22 +500,33 @@ function Render.onZone(currentMenuId)
489500
local rotation = data.rotation
490501
if not position then return end
491502

503+
local validateSlow
504+
if data.tracker == "hit" then
505+
validateSlow = function()
506+
local hitPosition, entity, playerDistance = Util.rayCast(10, PlayerPedId())
507+
return Container.zones[currentMenuId]:isPointInside(hitPosition)
508+
end
509+
end
510+
492511
Render.generic(data, metadata, {
493512
onEnter = function()
494513
StateManager.set('disableRayCast', true)
495514
scaleform.setForwardVectorLock(false)
496515
scaleform.setPosition(position)
497516

498517
if rotation then
499-
scaleform.setRotation(rotation)
500518
scaleform.set3d(true)
519+
scaleform.setRotation(rotation)
501520
scaleform.setScale(data.scale or 1)
521+
else
522+
scaleform.set3d(false)
502523
end
503524
return true
504525
end,
505526
validate = function()
506527
return StateManager.get('id') == currentMenuId
507528
end,
529+
validateSlow = validateSlow,
508530
onExit = function()
509531
StateManager.set('disableRayCast', false)
510532
end

‎interactionMenu/lua/client/menuContainer.lua‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,17 @@ local function buildOption(data, instance)
203203
job = option.job and transformRestrictions(option.job),
204204
gang = option.gang and transformRestrictions(option.gang),
205205

206+
tts_api = option.tts_api,
207+
tts_voice = option.tts_voice,
208+
206209
flags = {
207210
dynamic = option.dynamic,
208211
disable = false,
209212
action = nil,
210213
event = nil,
211214
hide = option.hide or false,
212215
subMenu = option.subMenu or false,
216+
dialogue = option.dialogue or false,
213217
}
214218
}
215219

@@ -395,14 +399,18 @@ function Container.create(t)
395399
z = t.position.z,
396400
id = id
397401
}
398-
399402
instance.rotation = t.rotation
400403
instance.zone = t.zone
401404
instance.scale = t.scale
405+
instance.tracker = t.tracker or "collision" -- (presence or collision), hit
402406

403407
if instance.zone then
404408
t.zone.name = id
409+
t.zone.tracker = instance.tracker
405410
Container.zones[id] = Util.addZone(t.zone)
411+
if instance.tracker == "hit" then
412+
Container.zones[id].tracker = instance.tracker
413+
end
406414
if not Container.zones[id] then
407415
return
408416
end
@@ -663,6 +671,7 @@ function Container.getMenu(model, entity, menuId)
663671
if menuId then
664672
local menuRef = Container.get(menuId)
665673
if menuRef.type == 'zone' then
674+
container.tracker = menuRef.tracker
666675
combinedIds = Util.table_merge(combinedIds, Container.indexes.globals.zones or {})
667676
end
668677
end
@@ -812,7 +821,8 @@ end
812821
function Container.triggerInteraction(menuId, optionId, ...)
813822
if not Container.data[menuId] or not Container.data[menuId].interactions[optionId] then return end
814823
local func = Container.data[menuId].interactions[optionId].func
815-
if not func or type(func) ~= 'function' then return end
824+
825+
if not func and func["__cfx_functionReference"] then return end
816826
return func(...)
817827
end
818828

0 commit comments

Comments
 (0)