-
Notifications
You must be signed in to change notification settings - Fork 12
/
sh_demmylock.lua
102 lines (93 loc) · 2.87 KB
/
sh_demmylock.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
LOCKS = {}
CENTERS = {}
SIZES = {}
function CalculateSizeAndCenter(area)
if LOCKS[area] then
local center = vector3(0,0,0)
local itemCount = 0
for lockName, lockData in pairs(LOCKS[area]) do
if lockData.doors then
for _, door in pairs(lockData.doors) do
itemCount = itemCount + 1
center = center + door.coords
end
end
if lockData.keypads then
for _, keypad in pairs(lockData.keypads) do
if keypad.coords then
itemCount = itemCount + 1
center = center + keypad.coords
end
end
end
end
if itemCount > 0 then
center = center / itemCount
CENTERS[area] = center
end
local maxDistance = 0
for lockName, lockData in pairs(LOCKS[area]) do
if lockData.doors then
for _, door in pairs(lockData.doors) do
local distance = #( door.coords - CENTERS[area] )
if distance > maxDistance then
maxDistance = distance
end
end
end
if lockData.keypads then
for _, keypad in pairs(lockData.keypads) do
if keypad.coords then
local distance = #( keypad.coords - CENTERS[area] )
if distance > maxDistance then
maxDistance = distance
end
end
end
end
end
SIZES[area] = maxDistance + CONFIG.range.areaMargin
end
end
function AddLocks(area, locks)
if not LOCKS[area] then
LOCKS[area] = {}
end
local added = 0
local doorCount = 0
for name, data in pairs(locks) do
if LOCKS[area][name] then
log('WARNING: Duplicate lock definiton for ',area,'/',name)
else
if data.doors then
doorCount = doorCount + #data.doors
end
added = added + 1
end
LOCKS[area][name] = data
end
if IsDuplicityVersion() then
log('Added',added,'locks with',doorCount,'doors to',area)
else
CalculateSizeAndCenter(area)
end
end
function log (...)
local numElements = select('#', ...)
local elements = {...}
local line
local prefix = ''
if IsDuplicityVersion() then
prefix = '['..os.date("%H:%M:%S")..'] <'..GetCurrentResourceName()..'> '
end
suffix = '\n'
for i=1,numElements do
local entry = elements[i]
if line then
line = line..' '..tostring(entry)
else
line = tostring(entry)
end
end
Citizen.Trace(prefix..line..suffix)
end