forked from GouveiaXS/angelicxs-metaldetector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.lua
163 lines (154 loc) · 5.7 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
ESX = exports["es_extended"]:getSharedObject()
PlayerData = nil
PlayerJob = nil
PlayerGrade = nil
local DetectorSpawn = false
local DetectorEntity
local CooldownTimer = false
CreateThread(function()
while true do
local sleep = 3000
local nearDetector = false
local playerCoords = GetEntityCoords(PlayerPedId())
for detectorName, detectorLocation in pairs(Config.Detectors) do
for index, detector in pairs(detectorLocation) do
local distance = #(playerCoords - vector3(detector.coords[1],detector.coords[2],detector.coords[3]))
if distance <= 20 then
if detector.entity and not DetectorSpawn then
DetectorSpawn = true
CreateMetalDetector(detector)
end
sleep = 1000
if distance <= (detector.detectRadius*8) then
sleep = 5
if distance <= detector.detectRadius then
sleep = detector.timer
Search(detector)
break
end
end
elseif detector.entity and DoesEntityExist(DetectorEntity) and DetectorSpawn then
if distance > 20 then
DeleteObject(DetectorEntity)
DeleteEntity(DetectorEntity)
DetectorSpawn = false
end
end
end
end
Wait(sleep)
end
end)
function CreateMetalDetector(detector)
local hash = GetHashKey('ch_prop_ch_metal_detector_01a')
RequestModel(hash)
while not HasModelLoaded(hash) do
Wait(10)
end
DetectorEntity = CreateObject(hash, detector.coords[1], detector.coords[2], (detector.coords[3]-1), 0, 0, 0)
SetEntityHeading(DetectorEntity, detector.heading)
FreezeEntityPosition(DetectorEntity, true)
SetEntityInvincible(DetectorEntity, true)
SetModelAsNoLongerNeeded(hash)
end
function Search(detector)
if not Exempt(detector.jobsExempt) then
local hasItem = false
if detector.UseMainList ~= nil and detector.UseMainList then
if Config.UseESX then
PlayerData = ESX.GetPlayerData()
for i = 1, #Config.MetalItems, 1 do
for k, v in ipairs(PlayerData.inventory) do
if v.name == Config.MetalItems[i] and v.count > 0 then
hasItem = true
break
end
end
end
elseif Config.UseQBCore then
PlayerData = QBCore.Functions.GetPlayerData()
for i = 1, #Config.MetalItems, 1 do
for slot, item in pairs(PlayerData.items) do
if PlayerData.items[slot] then
if item.name == Config.MetalItems[i] then
hasItem = true
break
end
end
end
end
end
end
if detector.items ~=nil and next(detector.items) then
if Config.UseESX then
PlayerData = ESX.GetPlayerData()
for i = 1, #detector.items, 1 do
for k, v in ipairs(PlayerData.inventory) do
if v.name == detector.items[i] and v.count > 0 then
hasItem = true
break
end
end
end
elseif Config.UseQBCore then
PlayerData = QBCore.Functions.GetPlayerData()
for i = 1, #detector.items, 1 do
for slot, item in pairs(PlayerData.items) do
if PlayerData.items[slot] then
if item.name == detector.items[i] then
hasItem = true
break
end
end
end
end
end
end
if hasItem then
TriggerServerEvent('angelicxs-MDetector:Server:SoundPlayer', detector)
if not CooldownTimer then
PoliceAlert()
end
end
end
end
function Exempt(data)
if data == nil then return false end
local hasJob = false
if data ~= nil and next(data) then
for jobName, gradeLevel in pairs(data) do
if PlayerJob == jobName and PlayerGrade >= gradeLevel then
hasJob = true
break
end
end
end
return hasJob
end
function PoliceAlert()
CooldownTimer = true
local time = Config.PoliceAlertCooldown
TriggerEvent('angelicxs-MDetector:CustomDisptach')
while true do
Wait(1000)
time = time-1
if time <= 0 then
break
end
end
CooldownTimer = false
end
RegisterNetEvent('angelicxs-MDetector:SoundPlayer', function(detector)
local playerCoords = GetEntityCoords(PlayerPedId())
local distance = #(playerCoords - vector3(detector.coords[1],detector.coords[2],detector.coords[3]))
local soundId = GetSoundId()
local hearing = false
if distance <= detector.soundRadious then
hearing = true
PlaySoundFromCoord(soundId, detector.sound, detector.coords[1], detector.coords[2], detector.coords[3])
end
if hearing then
Wait(detector.timer)
StopSound(soundId)
end
end)