-
Notifications
You must be signed in to change notification settings - Fork 192
/
CircleZone.lua
98 lines (85 loc) · 2.47 KB
/
CircleZone.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
CircleZone = {}
-- Inherits from PolyZone
setmetatable(CircleZone, { __index = PolyZone })
function CircleZone:draw(forceDraw)
if not forceDraw and not self.debugPoly then return end
local center = self.center
local debugColor = self.debugColor
local r, g, b = debugColor[1], debugColor[2], debugColor[3]
if self.useZ then
local radius = self.radius
DrawMarker(28, center.x, center.y, center.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, radius, radius, radius, r, g, b, 48, false, false, 2, nil, nil, false)
else
local diameter = self.diameter
DrawMarker(1, center.x, center.y, -200.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, diameter, diameter, 400.0, r, g, b, 96, false, false, 2, nil, nil, false)
end
end
local function _initDebug(zone, options)
if options.debugBlip then zone:addDebugBlip() end
if not options.debugPoly then
return
end
Citizen.CreateThread(function()
while not zone.destroyed do
zone:draw(false)
Citizen.Wait(0)
end
end)
end
function CircleZone:new(center, radius, options)
options = options or {}
local zone = {
name = tostring(options.name) or nil,
center = center,
radius = radius + 0.0,
diameter = radius * 2.0,
useZ = options.useZ or false,
debugPoly = options.debugPoly or false,
debugColor = options.debugColor or {0, 255, 0},
data = options.data or {},
isCircleZone = true,
}
if zone.useZ then
assert(type(zone.center) == "vector3", "Center must be vector3 if useZ is true {center=" .. center .. "}")
end
setmetatable(zone, self)
self.__index = self
return zone
end
function CircleZone:Create(center, radius, options)
local zone = CircleZone:new(center, radius, options)
_initDebug(zone, options)
return zone
end
function CircleZone:isPointInside(point)
if self.destroyed then
print("[PolyZone] Warning: Called isPointInside on destroyed zone {name=" .. self.name .. "}")
return false
end
local center = self.center
local radius = self.radius
if self.useZ then
return #(point - center) < radius
else
return #(point.xy - center.xy) < radius
end
end
function CircleZone:getRadius()
return self.radius
end
function CircleZone:setRadius(radius)
if not radius or radius == self.radius then
return
end
self.radius = radius
self.diameter = radius * 2.0
end
function CircleZone:getCenter()
return self.center
end
function CircleZone:setCenter(center)
if not center or center == self.center then
return
end
self.center = center
end