Skip to content

Commit 7739f41

Browse files
committed
Add debugBlip option to all zones
The debugBlip option will place a blip at the center of the zone, or for ComboZones, place a blip for each zone inside of it, and print a report of the amount of zones in the ComboZone by type.
1 parent 2878fff commit 7739f41

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed

BoxZone.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ end
6262

6363
-- Initialization functions
6464
local function _initDebug(zone, options)
65+
if options.debugBlip then zone:addDebugBlip() end
6566
if not options.debugPoly then
6667
return
6768
end

CircleZone.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ end
1717

1818

1919
local function _initDebug(zone, options)
20+
if options.debugBlip then zone:addDebugBlip() end
2021
if not options.debugPoly then
2122
return
2223
end

ComboZone.lua

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ end
110110

111111

112112
local function _initDebug(zone, options)
113+
if options.debugBlip then zone:addDebugBlip() end
113114
if not options.debugPoly then
114115
return
115116
end
@@ -296,6 +297,28 @@ function ComboZone:onPlayerInOutExhaustive(onPointInOutCb, waitInMS)
296297
self:onPointInOutExhaustive(PolyZone.getPlayerPosition, onPointInOutCb, waitInMS)
297298
end
298299

300+
function ComboZone:addDebugBlip()
301+
local zones = self.zones
302+
local polyCount, boxCount, circleCount, entityCount = 0, 0, 0, 0
303+
for i=1, #zones do
304+
local zone = zones[i]
305+
if zone then
306+
zone:addDebugBlip()
307+
if zone.isPolyZone then polyCount = polyCount + 1 end
308+
if zone.isBoxZone then boxCount = boxCount + 1 end
309+
if zone.isCircleZone then circleCount = circleCount + 1 end
310+
if zone.isEntityZone then entityCount = entityCount + 1 end
311+
end
312+
end
313+
local name = self.name ~= nil and ("\"" .. self.name .. "\"") or nil
314+
print("[PolyZone] Debug for ComboZone { name = " .. tostring(name) .. " }:")
315+
print("[PolyZone] Total zones: " .. #zones)
316+
print("[PolyZone] BoxZones: " .. boxCount)
317+
print("[PolyZone] CircleZones: " .. circleCount)
318+
print("[PolyZone] PolyZones: " .. polyCount)
319+
print("[PolyZone] EntityZones: " .. entityCount)
320+
end
321+
299322
function ComboZone:setPaused(paused)
300323
self.paused = paused
301324
end

EntityZone.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,17 @@ end
3333

3434
-- Initialization functions
3535
local function _initDebug(zone, options)
36-
if not options.debugPoly then
36+
if options.debugBlip then zone:addDebugBlip() end
37+
if not options.debugPoly and not options.debugBlip then
3738
return
3839
end
3940

4041
Citizen.CreateThread(function()
4142
local entity = zone.entity
43+
local shouldDraw = options.debugPoly
4244
while not zone.destroyed do
4345
UpdateOffsets(entity, zone)
44-
zone:draw()
46+
if shouldDraw then zone:draw() end
4547
Citizen.Wait(0)
4648
end
4749
end)
@@ -89,6 +91,7 @@ function UpdateOffsets(entity, zone)
8991
if zone.useZ then
9092
zone.minZ, zone.maxZ = _calculateMinAndMaxZ(entity, zone.dimensions, zone.scaleZ, zone.offsetZ, pos)
9193
end
94+
if zone.debugBlip then SetBlipCoords(zone.debugBlip, pos.x, pos.y, 0.0) end
9295
end
9396

9497

@@ -133,3 +136,9 @@ function EntityZone:destroy()
133136
self.damageEventHandlers = {}
134137
PolyZone.destroy(self)
135138
end
139+
140+
function EntityZone:addDebugBlip()
141+
local blip = PolyZone.addDebugBlip(self)
142+
self.debugBlip = blip
143+
return blip
144+
end

client.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ local function _wn_inner_loop(p0, p1, p2, wn)
3030
return wn
3131
end
3232

33+
function addBlip(pos)
34+
local blip = AddBlipForCoord(pos.x, pos.y, 0.0)
35+
SetBlipColour(blip, 7)
36+
SetBlipDisplay(blip, 8)
37+
SetBlipScale(blip, 1.0)
38+
SetBlipAsShortRange(blip, true)
39+
return blip
40+
end
41+
3342
function clearTbl(tbl)
3443
-- Only works with contiguous (array-like) tables
3544
if tbl == nil then return end
@@ -397,6 +406,7 @@ end
397406

398407

399408
local function _initDebug(poly, options)
409+
if options.debugBlip then poly:addDebugBlip() end
400410
local debugEnabled = options.debugPoly or options.debugGrid
401411
if not debugEnabled then
402412
return
@@ -519,6 +529,10 @@ function PolyZone:onPlayerInOut(onPointInOutCb, waitInMS)
519529
self:onPointInOut(PolyZone.getPlayerPosition, onPointInOutCb, waitInMS)
520530
end
521531

532+
function PolyZone:addDebugBlip()
533+
return addBlip(self.center or self:getBoundingBoxCenter())
534+
end
535+
522536
function PolyZone:setPaused(paused)
523537
self.paused = paused
524538
end

0 commit comments

Comments
 (0)