-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.lua
185 lines (150 loc) · 5.08 KB
/
client.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
--on top of client.lua
---@field onnearEnter fun(self: CZone)?
---@field onnearExit fun(self: CZone)?
---@type table<number, CZone>
local insideZones = {}
---@type table<number, CZone>
local enteringZones = {}
---@type table<number, CZone>
local exitingZones = {}
local enteringSize = 0
local exitingSize = 0
local nearZones = {}
---@type table<number, CZone>
local enteringnearZones = {}
---@type table<number, CZone>
local exitingnearZones = {}
local enteringnearSize = 0
local exitingnearSize = 0
local tick
local glm_polygon_contains = glm.polygon.contains
local function removeZone(self)
Zones[self.id] = nil
insideZones[self.id] = nil
enteringZones[self.id] = nil
exitingZones[self.id] = nil
enteringnearZones[self.id] = nil
exitingnearZones[self.id] = nil
end
CreateThread(function()
while true do
local coords = GetEntityCoords(cache.ped)
cache.coords = coords
for _, zone in pairs(Zones) do
zone.distance = #(zone.coords - coords)
local radius, contains = zone.radius, nil
if radius then
contains = zone.distance < radius
else
contains = glm_polygon_contains(zone.polygon, coords, zone.thickness / 4)
end
if contains then
if not zone.insideZone then
zone.insideZone = true
if zone.onEnter then
enteringSize += 1
enteringZones[enteringSize] = zone
end
if zone.inside or zone.debug then
insideZones[zone.id] = zone
end
end
else
if zone.insideZone then
zone.insideZone = false
insideZones[zone.id] = nil
if zone.onExit then
exitingSize += 1
exitingZones[exitingSize] = zone
end
end
if zone.debug then
insideZones[zone.id] = zone
end
end
if zone.benear ~= nil and zone.distance < zone.benear then
if not zone.nearZone then
zone.nearZone = true
if zone.onEnter then
enteringnearSize += 1
enteringnearZones[enteringnearSize] = zone
end
if zone.inside or zone.debug then
nearZones[zone.id] = zone
end
end
elseif zone.benear ~= nil then
if zone.nearZone then
zone.nearZone = false
nearZones[zone.id] = nil
if zone.onExit then
exitingnearSize += 1
exitingnearZones[exitingnearSize] = zone
end
end
if zone.debug then
nearZones[zone.id] = zone
end
end
end
if exitingSize > 0 then
table.sort(exitingZones, function(a, b)
return a.distance > b.distance
end)
for i = 1, exitingSize do
exitingZones[i]:onExit()
end
exitingSize = 0
table.wipe(exitingZones)
end
if enteringSize > 0 then
table.sort(enteringZones, function(a, b)
return a.distance < b.distance
end)
for i = 1, enteringSize do
enteringZones[i]:onEnter()
end
enteringSize = 0
table.wipe(enteringZones)
end
if exitingnearSize > 0 then
table.sort(exitingnearZones, function(a, b)
return a.distance > b.distance
end)
for i = 1, exitingnearSize do
exitingnearZones[i]:onnearExit()
end
exitingnearSize = 0
table.wipe(exitingnearZones)
end
if enteringnearSize > 0 then
table.sort(enteringnearZones, function(a, b)
return a.distance < b.distance
end)
for i = 1, enteringnearSize do
enteringnearZones[i]:onnearEnter()
end
enteringnearSize = 0
table.wipe(enteringnearZones)
end
if not tick then
if next(insideZones) then
tick = SetInterval(function()
for _, zone in pairs(insideZones) do
if zone.debug then
zone:debug()
if zone.inside and zone.insideZone then
zone:inside()
end
else
zone:inside()
end
end
end)
end
elseif not next(insideZones) then
tick = ClearInterval(tick)
end
Wait(300)
end
end)