-
-
Notifications
You must be signed in to change notification settings - Fork 219
Expand file tree
/
Copy pathregistration.lua
More file actions
364 lines (294 loc) · 11.2 KB
/
Copy pathregistration.lua
File metadata and controls
364 lines (294 loc) · 11.2 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
local Config = Config
local pairs = pairs
-- SetOptions is a private helper; all Add* functions funnel through it
local function SetOptions(tbl, distance, options)
for _, v in pairs(options) do
if v.required_item then
v.item = v.required_item
v.required_item = nil
end
if not v.distance or v.distance > distance then v.distance = distance end
tbl[v.label] = v
end
end
-- Zones
function AddCircleZone(name, center, radius, options, targetoptions)
local centerType = type(center)
center = (centerType == 'table' or centerType == 'vector4') and vec3(center.x, center.y, center.z) or center
Zones[name] = CircleZone:Create(center, radius, options)
targetoptions.distance = targetoptions.distance or Config.MaxDistance
Zones[name].targetoptions = targetoptions
return Zones[name]
end
exports('AddCircleZone', AddCircleZone)
function AddBoxZone(name, center, length, width, options, targetoptions)
local centerType = type(center)
center = (centerType == 'table' or centerType == 'vector4') and vec3(center.x, center.y, center.z) or center
Zones[name] = BoxZone:Create(center, length, width, options)
targetoptions.distance = targetoptions.distance or Config.MaxDistance
Zones[name].targetoptions = targetoptions
return Zones[name]
end
exports('AddBoxZone', AddBoxZone)
function AddPolyZone(name, points, options, targetoptions)
local _points = {}
local pointsType = type(points[1])
if pointsType == 'table' or pointsType == 'vector3' or pointsType == 'vector4' then
for i = 1, #points do
_points[i] = vec2(points[i].x, points[i].y)
end
end
Zones[name] = PolyZone:Create(#_points > 0 and _points or points, options)
targetoptions.distance = targetoptions.distance or Config.MaxDistance
Zones[name].targetoptions = targetoptions
return Zones[name]
end
exports('AddPolyZone', AddPolyZone)
function AddComboZone(zones, options, targetoptions)
Zones[options.name] = ComboZone:Create(zones, options)
targetoptions.distance = targetoptions.distance or Config.MaxDistance
Zones[options.name].targetoptions = targetoptions
return Zones[options.name]
end
exports('AddComboZone', AddComboZone)
function AddEntityZone(name, entity, options, targetoptions)
Zones[name] = EntityZone:Create(entity, options)
targetoptions.distance = targetoptions.distance or Config.MaxDistance
Zones[name].targetoptions = targetoptions
return Zones[name]
end
exports('AddEntityZone', AddEntityZone)
function RemoveZone(name)
if not Zones[name] then return end
if Zones[name].destroy then Zones[name]:destroy() end
Zones[name] = nil
end
exports('RemoveZone', RemoveZone)
-- Bones
function AddTargetBone(bones, parameters)
local distance, options = parameters.distance or Config.MaxDistance, parameters.options
if type(bones) == 'table' then
for _, bone in pairs(bones) do
if not Bones.Options[bone] then Bones.Options[bone] = {} end
SetOptions(Bones.Options[bone], distance, options)
end
elseif type(bones) == 'string' then
if not Bones.Options[bones] then Bones.Options[bones] = {} end
SetOptions(Bones.Options[bones], distance, options)
end
end
exports('AddTargetBone', AddTargetBone)
function RemoveTargetBone(bones, labels)
if type(bones) == 'table' then
for _, bone in pairs(bones) do
if labels then
if type(labels) == 'table' then
for _, v in pairs(labels) do
if Bones.Options[bone] then Bones.Options[bone][v] = nil end
end
elseif type(labels) == 'string' then
if Bones.Options[bone] then Bones.Options[bone][labels] = nil end
end
else
Bones.Options[bone] = nil
end
end
else
if labels then
if type(labels) == 'table' then
for _, v in pairs(labels) do
if Bones.Options[bones] then Bones.Options[bones][v] = nil end
end
elseif type(labels) == 'string' then
if Bones.Options[bones] then Bones.Options[bones][labels] = nil end
end
else
Bones.Options[bones] = nil
end
end
end
exports('RemoveTargetBone', RemoveTargetBone)
-- Entities
function AddTargetEntity(entities, parameters)
local distance, options = parameters.distance or Config.MaxDistance, parameters.options
if type(entities) == 'table' then
for _, entity in pairs(entities) do
if NetworkGetEntityIsNetworked(entity) then entity = NetworkGetNetworkIdFromEntity(entity) end
if not Entities[entity] then Entities[entity] = {} end
SetOptions(Entities[entity], distance, options)
end
elseif type(entities) == 'number' then
if NetworkGetEntityIsNetworked(entities) then entities = NetworkGetNetworkIdFromEntity(entities) end
if not Entities[entities] then Entities[entities] = {} end
SetOptions(Entities[entities], distance, options)
end
end
exports('AddTargetEntity', AddTargetEntity)
function RemoveTargetEntity(entities, labels)
if type(entities) == 'table' then
for _, entity in pairs(entities) do
if NetworkGetEntityIsNetworked(entity) then entity = NetworkGetNetworkIdFromEntity(entity) end
if labels then
if type(labels) == 'table' then
for _, v in pairs(labels) do
if Entities[entity] then Entities[entity][v] = nil end
end
elseif type(labels) == 'string' then
if Entities[entity] then Entities[entity][labels] = nil end
end
else
Entities[entity] = nil
end
end
elseif type(entities) == 'number' then
if NetworkGetEntityIsNetworked(entities) then entities = NetworkGetNetworkIdFromEntity(entities) end
if labels then
if type(labels) == 'table' then
for _, v in pairs(labels) do
if Entities[entities] then Entities[entities][v] = nil end
end
elseif type(labels) == 'string' then
if Entities[entities] then Entities[entities][labels] = nil end
end
else
Entities[entities] = nil
end
end
end
exports('RemoveTargetEntity', RemoveTargetEntity)
-- Models
function AddTargetModel(models, parameters)
local distance, options = parameters.distance or Config.MaxDistance, parameters.options
if type(models) == 'table' then
for _, model in pairs(models) do
if type(model) == 'string' then model = joaat(model) end
if not Models[model] then Models[model] = {} end
SetOptions(Models[model], distance, options)
end
else
if type(models) == 'string' then models = joaat(models) end
if not Models[models] then Models[models] = {} end
SetOptions(Models[models], distance, options)
end
end
exports('AddTargetModel', AddTargetModel)
function RemoveTargetModel(models, labels)
if type(models) == 'table' then
for _, model in pairs(models) do
if type(model) == 'string' then model = joaat(model) end
if labels then
if type(labels) == 'table' then
for _, v in pairs(labels) do
if Models[model] then Models[model][v] = nil end
end
elseif type(labels) == 'string' then
if Models[model] then Models[model][labels] = nil end
end
else
Models[model] = nil
end
end
else
if type(models) == 'string' then models = joaat(models) end
if labels then
if type(labels) == 'table' then
for _, v in pairs(labels) do
if Models[models] then Models[models][v] = nil end
end
elseif type(labels) == 'string' then
if Models[models] then Models[models][labels] = nil end
end
else
Models[models] = nil
end
end
end
exports('RemoveTargetModel', RemoveTargetModel)
-- Global types
function AddGlobalType(type, parameters)
local distance, options = parameters.distance or Config.MaxDistance, parameters.options
SetOptions(Types[type], distance, options)
end
exports('AddGlobalType', AddGlobalType)
function AddGlobalPed(parameters) AddGlobalType(1, parameters) end
exports('AddGlobalPed', AddGlobalPed)
function AddGlobalVehicle(parameters) AddGlobalType(2, parameters) end
exports('AddGlobalVehicle', AddGlobalVehicle)
function AddGlobalObject(parameters) AddGlobalType(3, parameters) end
exports('AddGlobalObject', AddGlobalObject)
function AddGlobalPlayer(parameters)
local distance, options = parameters.distance or Config.MaxDistance, parameters.options
SetOptions(Players, distance, options)
end
exports('AddGlobalPlayer', AddGlobalPlayer)
function RemoveGlobalType(typ, labels)
if labels then
if type(labels) == 'table' then
for _, v in pairs(labels) do Types[typ][v] = nil end
elseif type(labels) == 'string' then
Types[typ][labels] = nil
end
else
Types[typ] = {}
end
end
exports('RemoveGlobalType', RemoveGlobalType)
function RemoveGlobalPed(labels) RemoveGlobalType(1, labels) end
exports('RemoveGlobalPed', RemoveGlobalPed)
function RemoveGlobalVehicle(labels) RemoveGlobalType(2, labels) end
exports('RemoveGlobalVehicle', RemoveGlobalVehicle)
function RemoveGlobalObject(labels) RemoveGlobalType(3, labels) end
exports('RemoveGlobalObject', RemoveGlobalObject)
function RemoveGlobalPlayer(labels)
if labels then
if type(labels) == 'table' then
for _, v in pairs(labels) do Players[v] = nil end
elseif type(labels) == 'string' then
Players[labels] = nil
end
else
Players = {}
end
end
exports('RemoveGlobalPlayer', RemoveGlobalPlayer)
-- Getters
local function GetGlobalTypeData(type, label) return Types[type][label] end
exports('GetGlobalTypeData', GetGlobalTypeData)
local function GetZoneData(name) return Zones[name] end
exports('GetZoneData', GetZoneData)
local function GetTargetBoneData(bone, label) return Bones.Options[bone][label] end
exports('GetTargetBoneData', GetTargetBoneData)
local function GetTargetEntityData(entity, label) return Entities[entity][label] end
exports('GetTargetEntityData', GetTargetEntityData)
local function GetTargetModelData(model, label) return Models[model][label] end
exports('GetTargetModelData', GetTargetModelData)
local function GetGlobalPedData(label) return Types[1][label] end
exports('GetGlobalPedData', GetGlobalPedData)
local function GetGlobalVehicleData(label) return Types[2][label] end
exports('GetGlobalVehicleData', GetGlobalVehicleData)
local function GetGlobalObjectData(label) return Types[3][label] end
exports('GetGlobalObjectData', GetGlobalObjectData)
local function GetGlobalPlayerData(label) return Players[label] end
exports('GetGlobalPlayerData', GetGlobalPlayerData)
-- Setters
local function UpdateGlobalTypeData(type, label, data) Types[type][label] = data end
exports('UpdateGlobalTypeData', UpdateGlobalTypeData)
local function UpdateZoneData(name, data)
data.distance = data.distance or Config.MaxDistance
Zones[name].targetoptions = data
end
exports('UpdateZoneData', UpdateZoneData)
local function UpdateTargetBoneData(bone, label, data) Bones.Options[bone][label] = data end
exports('UpdateTargetBoneData', UpdateTargetBoneData)
local function UpdateTargetEntityData(entity, label, data) Entities[entity][label] = data end
exports('UpdateTargetEntityData', UpdateTargetEntityData)
local function UpdateTargetModelData(model, label, data) Models[model][label] = data end
exports('UpdateTargetModelData', UpdateTargetModelData)
local function UpdateGlobalPedData(label, data) Types[1][label] = data end
exports('UpdateGlobalPedData', UpdateGlobalPedData)
local function UpdateGlobalVehicleData(label, data) Types[2][label] = data end
exports('UpdateGlobalVehicleData', UpdateGlobalVehicleData)
local function UpdateGlobalObjectData(label, data) Types[3][label] = data end
exports('UpdateGlobalObjectData', UpdateGlobalObjectData)
local function UpdateGlobalPlayerData(label, data) Players[label] = data end
exports('UpdateGlobalPlayerData', UpdateGlobalPlayerData)