From 86f20c4d7c237a55150df199acce550d04553b88 Mon Sep 17 00:00:00 2001 From: swkeep <49286776+swkeep@users.noreply.github.com> Date: Sat, 10 Feb 2024 11:38:55 +0300 Subject: [PATCH] feat: add PolyZone warning --- interactionMenu/lua/client/menuContainer.lua | 45 ++++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/interactionMenu/lua/client/menuContainer.lua b/interactionMenu/lua/client/menuContainer.lua index aaf185c..1291a84 100644 --- a/interactionMenu/lua/client/menuContainer.lua +++ b/interactionMenu/lua/client/menuContainer.lua @@ -23,21 +23,14 @@ local GetPlayerServerId = GetPlayerServerId local NetworkGetPlayerIndexFromPed = NetworkGetPlayerIndexFromPed local SpatialHashGrid = Util.SpatialHashGrid local grid = SpatialHashGrid:new('position', 100) +local zone_grid = SpatialHashGrid:new('zone', 100) local StateManager = Util.StateManager() local PersistentData = Util.PersistentData() local previous_daytime = false -- enum: used in difference between OBJECTs, PEDs, VEHICLEs -EntityTypes = Util.ENUM { - 'PED', - 'VEHICLE', - 'OBJECT' -} -local set = { - "peds", - "vehicles", - "objects" -} +local set = { "peds", "vehicles", "objects" } +EntityTypes = Util.ENUM { 'PED', 'VEHICLE', 'OBJECT' } -- class: PersistentData -- managing menus @@ -60,6 +53,10 @@ Container = { } } +local function canCreateZone() + return GetResourceState('PolyZone') == 'started' +end + --- Build interaction table for named interactions (canInteract, onSeen, onExit) ---@param data table 'raw menu data' ---@param interactions table 'interactions reference table to add interactions into it' @@ -222,8 +219,6 @@ local function transformJobData(data) end end -local zone_grid = SpatialHashGrid:new('zone', 100) - local function AddBoxZone(o) local z = BoxZone:Create(vec3(o.position.x, o.position.y, o.position.z), o.length or 1.0, o.width or 1.0, { name = o.name, @@ -313,18 +308,22 @@ function Container.create(t) end end elseif t.zone and t.position then - instance.type = 'zone' - instance.position = { - x = t.position.x, - y = t.position.y, - z = t.position.z, - id = id - } + if canCreateZone() then + instance.type = 'zone' + instance.position = { + x = t.position.x, + y = t.position.y, + z = t.position.z, + id = id + } - instance.rotation = t.rotation - instance.zone = t.zone - Container.zones[id] = AddBoxZone(t.zone) - zone_grid:insert(instance.position) + instance.rotation = t.rotation + instance.zone = t.zone + Container.zones[id] = AddBoxZone(t.zone) + zone_grid:insert(instance.position) + else + warn('Could not find `PolyZone`. Make sure it is started before interactionMenu.') + end end buildOption(t, instance)