-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrapper.lua
More file actions
247 lines (215 loc) · 6.14 KB
/
Copy pathwrapper.lua
File metadata and controls
247 lines (215 loc) · 6.14 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
local characterLoaded = false
local addedZones = {}
local wCombozone
local polyDebug = false
CreateThread(function()
plsr.Callbacks:RegisterClientCallback("Polyzone:GetZoneAtCoords", function(data, cb)
cb(plsr.Polyzone:GetZoneAtCoords(data))
end)
plsr.Callbacks:RegisterClientCallback("Polyzone:GetZonePlayerIn", function(data, cb)
local c = GetEntityCoords(PlayerPedId())
cb(plsr.Polyzone:GetZoneAtCoords(vector3(c.x, c.y, c.z)))
end)
plsr.Callbacks:RegisterClientCallback("Polyzone:GetAllZonesAtCoords", function(data, cb)
cb(plsr.Polyzone:GetAllZonesAtCoords(data))
end)
plsr.Callbacks:RegisterClientCallback("Polyzone:GetAllZonesPlayerIn", function(data, cb)
local c = GetEntityCoords(PlayerPedId())
cb(plsr.Polyzone:GetAllZonesAtCoords(vector3(c.x, c.y, c.z)))
end)
plsr.Callbacks:RegisterClientCallback("Polyzone:IsCoordsInZone", function(data, cb)
cb(plsr.Polyzone:IsCoordsInZone(data.coords, data.id, data.key, data.val))
end)
end)
RegisterNetEvent("Characters:Client:Spawn")
AddEventHandler("Characters:Client:Spawn", function()
characterLoaded = true
InitWrapperZones()
end)
RegisterNetEvent("Characters:Client:Logout")
AddEventHandler("Characters:Client:Logout", function()
characterLoaded = false
for k, v in pairs(addedZones) do
TriggerEvent("Polyzone:Exit", k, false, false, v.data or {})
end
polyDebug = false
TriggerEvent("Targeting:Client:PolyzoneDebug", false)
if wCombozone then
wCombozone:destroy()
wCombozone = nil
plsr.Logger:Trace("Polyzone", "Destroyed All Polyzones (Character Logout)")
end
end)
function CreateZoneForCombo(id, data)
local options = data.options
options.name = id
options.data = (type(data.data) == "table" and data.data or {})
options.data.id = id
if data.type == "circle" then
return CircleZone:Create(data.center, data.radius, data.options)
elseif data.type == "poly" then
return PolyZone:Create(data.points, data.options)
elseif data.type == "box" then
return BoxZone:Create(data.center, data.length, data.width, data.options)
end
end
function InitWrapperZones()
if wCombozone then
return
end
local createdZones = {}
for k, v in pairs(addedZones) do
local zone = CreateZoneForCombo(k, v)
table.insert(createdZones, zone)
end
plsr.Logger:Trace("Polyzone", string.format("Initialized %s Simple Polyzones", #createdZones))
wCombozone = ComboZone:Create(createdZones, {
name = "wrapper_combo",
})
wCombozone:onPlayerInOutExhaustive(function(isPointInside, testedPoint, insideZones, enteredZones, leftZones)
if not characterLoaded then
return
end
if enteredZones then
for id, zone in ipairs(enteredZones) do
if zone.data and zone.data.id then
TriggerEvent("Polyzone:Enter", zone.data.id, testedPoint, insideZones, zone.data)
end
end
end
if leftZones then
for id, zone in ipairs(leftZones) do
if zone.data and zone.data.id then
TriggerEvent("Polyzone:Exit", zone.data.id, testedPoint, insideZones, zone.data)
end
end
end
end)
end
function AddZoneAfterCreation(id, zoneData)
if not wCombozone then
return
end
local zone = CreateZoneForCombo(id, zoneData)
wCombozone:AddZone(zone)
end
_POLYZONE = {
Create = {
Box = function(self, id, center, length, width, options, data)
local existingZone = addedZones[id]
if existingZone and wCombozone then
plsr.Polyzone:Remove(id)
Wait(100)
end
addedZones[id] = {
id = id,
type = "box",
center = center,
width = width,
length = length,
options = options,
data = data,
}
AddZoneAfterCreation(id, addedZones[id])
end,
Poly = function(self, id, points, options, data)
local existingZone = addedZones[id]
if existingZone and wCombozone then
plsr.Polyzone:Remove(id)
Wait(100)
end
addedZones[id] = {
id = id,
type = "poly",
points = points,
options = options,
data = data,
}
AddZoneAfterCreation(id, addedZones[id])
end,
Circle = function(self, id, center, radius, options, data)
local existingZone = addedZones[id]
if existingZone and wCombozone then
plsr.Polyzone:Remove(id)
Wait(100)
end
addedZones[id] = {
id = id,
type = "circle",
center = center,
radius = radius,
options = options,
data = data,
}
AddZoneAfterCreation(id, addedZones[id])
end,
},
Remove = function(self, id)
if addedZones[id] then
if wCombozone then
wCombozone:RemoveZone(id)
TriggerEvent("Polyzone:Exit", id, false, false, addedZones[id].data or {})
end
addedZones[id] = nil
end
return false
end,
Get = function(self, id)
return addedZones[id]
end,
-- !! WARNING WON'T WORK FOR OVERLAPPING ZONES SO BETTER OFF NOT USING IT !!
GetZoneAtCoords = function(self, coords)
if not wCombozone then
return false
end
local isInside, insideZone = wCombozone:isPointInside(coords)
if isInside and insideZone and insideZone.data then
return insideZone.data
end
return false
end,
GetAllZonesAtCoords = function(self, coords)
local withinZonesData = {}
local isInside, insideZones = wCombozone:isPointInsideExhaustive(coords)
if isInside and insideZones and #insideZones > 0 then
for k, v in ipairs(insideZones) do
table.insert(withinZonesData, v.data)
end
end
return withinZonesData
end,
IsCoordsInZone = function(self, coords, id, key, val)
local isInside, insideZones = wCombozone:isPointInsideExhaustive(coords)
if isInside and insideZones and #insideZones > 0 then
for k, v in ipairs(insideZones) do
if
(not id or v.data.id == id)
and (not key or ((val == nil and v.data[key]) or (val ~= nil and v.data[key] == val)))
then
return v.data
end
end
end
return false
end,
}
AddEventHandler("Proxy:Shared:RegisterReady", function()
exports["pulsar_core"]:RegisterComponent("Polyzone", _POLYZONE)
end)
RegisterNetEvent("Polyzone:Client:ToggleDebug", function()
polyDebug = not polyDebug
TriggerEvent("Targeting:Client:PolyzoneDebug", polyDebug)
if polyDebug and plsr.State.flags.isAdmin then
plsr.Logger:Warn("Polyzone", "Polyzone Debug Enabled")
CreateThread(function()
while polyDebug do
if wCombozone then
wCombozone:draw()
else
Wait(500)
end
Wait(0)
end
end)
end
end)