forked from StuxxyOfficial/erp_dispatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sv_main.lua
275 lines (211 loc) · 8.68 KB
/
sv_main.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
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
local calls = {}
function GetDispatchCalls() return calls end
exports('GetDispatchCalls', GetDispatchCalls) -- exports['erp_dispatch']:GetDispatchCalls()
RegisterNetEvent("dispatch:svNotify")
AddEventHandler("dispatch:svNotify", function(data)
local newId = #calls + 1
calls[newId] = data
calls[newId]['source'] = source
calls[newId]['callId'] = newId
calls[newId]['units'] = {}
calls[newId]['responses'] = {}
calls[newId]['time'] = os.time() * 1000
TriggerClientEvent('dispatch:clNotify', -1, data, newId, source)
--print(json.encode(data))
if data['dispatchCode'] == '911' or data['dispatchCode'] == '311' or data['dispatchCode'] == '10-99' then
TriggerClientEvent('erp-dispatch:setBlip', -1, data['dispatchCode'], vector3(data['origin']['x'], data['origin']['y'], data['origin']['z']), newId)
end
end)
AddEventHandler("dispatch:addUnit", function(callid, player, cb)
if calls[callid] then
if #calls[callid]['units'] > 0 then
for i=1, #calls[callid]['units'] do
if calls[callid]['units'][i]['cid'] == player.identifier then
cb(#calls[callid]['units'])
return
end
end
end
local callsign = exports['erp_mdt']:GetCallsign(player.identifier)
if player.job.name == 'police' then
table.insert(calls[callid]['units'], { cid = player.identifier, fullname = player.name, job = 'Police', callsign = callsign[1].callsign })
elseif player.job.name == 'ambulance' then
table.insert(calls[callid]['units'], { cid = player.identifier, fullname = player.name, job = 'EMS', callsign = callsign[1].callsign })
elseif player.job.name == 'cmmc' then
table.insert(calls[callid]['units'], { cid = player.identifier, fullname = player.name, job = 'EMS', callsign = callsign[1].callsign })
end
cb(#calls[callid]['units'])
end
end)
AddEventHandler("dispatch:removeUnit", function(callid, player, cb)
if calls[callid] then
if #calls[callid]['units'] > 0 then
for i=1, #calls[callid]['units'] do
if calls[callid]['units'][i]['cid'] == player.identifier then
table.remove(calls[callid]['units'], i)
end
end
end
cb(#calls[callid]['units'])
end
end)
AddEventHandler("dispatch:sendCallResponse", function(player, callid, message, time, cb)
if calls[callid] then
table.insert(calls[callid]['responses'], {
name = player.name,
message = message,
time = time
})
local player = calls[callid]['source']
if GetPlayerPing(player) > 0 then
TriggerClientEvent('dispatch:getCallResponse', player, message)
end
cb(true)
else
cb(false)
end
end)
RegisterCommand('togglealerts', function(source, args, user)
local source = source
local job = ESX.GetPlayerFromId(source).job
if job.name == 'police' or job.name == 'ambulance' or job.name == 'pa' or job.name == 'cmmc' then
TriggerClientEvent('erp-dispatch:manageNotifs', source, args[1])
end
end)
RegisterNetEvent('erp-dispatch:gunshotAlert')
AddEventHandler('erp-dispatch:gunshotAlert', function(sentCoords, isAuto, isCop)
TriggerClientEvent('erp-dispatch:gunshotAlert', -1, sentCoords, isAuto, isCop)
end)
RegisterNetEvent('erp-dispatch:combatAlert')
AddEventHandler('erp-dispatch:combatAlert', function(sentCoords)
TriggerClientEvent('erp-dispatch:combatAlert', -1, sentCoords)
end)
RegisterNetEvent('erp-dispatch:armedperson')
AddEventHandler('erp-dispatch:armedperson', function(sentCoords)
TriggerClientEvent('erp-dispatch:armedperson', -1, sentCoords)
end)
-- VANGELICOS
RegisterNetEvent('rcrp-dispatch:servervangelicos')
AddEventHandler('rcrp-dispatch:servervangelicos', function(sentCoords)
TriggerClientEvent('rcrp-dispatch:VangelicosBlip', -1, sentCoords)
end)
--Store Robberies
RegisterNetEvent('rcrp-dispatch:serverStoreRobberies')
AddEventHandler('rcrp-dispatch:serverStoreRobberies', function(sentCoords)
TriggerClientEvent('rcrp-dispatch:StoreRobberiesBlip', -1, sentCoords)
end)
--Bank Robbery
RegisterNetEvent('rcrp-dispatch:ServerBankRobbery')
AddEventHandler('rcrp-dispatch:ServerBankRobbery', function(sentCoords)
TriggerClientEvent('rcrp-dispatch:BankRobberyBlip', -1, sentCoords)
end)
--Car Thief
RegisterNetEvent('rcrp-dispatch:ChopShopBlip')
AddEventHandler('rcrp-dispatch:ChopShopBlip', function(sentCoords)
TriggerClientEvent('rcrp-dispatch:ChopShopBlip', -1, sentCoords)
end)
--SSDrugs
RegisterNetEvent('rcrp-dispatch:DrugReportsBlip')
AddEventHandler('rcrp-dispatch:DrugReportsBlip', function(sentCoords)
TriggerClientEvent('rcrp-dispatch:DrugReportBlip', -1, sentCoords)
end)
-- rcrp-dispatch:houserobbery
RegisterNetEvent('rcrp-dispatch:houserobbery')
AddEventHandler('rcrp-dispatch:houserobbery', function(sentCoords)
TriggerClientEvent('rcrp-dispatch:houserobberyblip', -1, sentCoords)
end)
--Custom Shit
function getCaller(src)
local xPlayer = ESX.GetPlayerFromId(src)
return xPlayer.getName()
end
ESX.RegisterServerCallback('rcrp:getCharData', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
if not xPlayer then return end
local identifier = xPlayer.getIdentifier()
MySQL.Async.fetchAll('SELECT firstname, lastname, phone_number FROM users WHERE identifier = @identifier', {
['@identifier'] = identifier
}, function(results)
cb(results[1])
end)
end)
AddEventHandler('rcrp-playerdownalert', function(dispatchCode, firstStreet, gender, priority, origin, dispatchMessage, name, number, job, information)
local xPlayer = ESX.GetPlayerFromId(source)
TriggerEvent('dispatch:svNotify', {
dispatchCode = dispatchCode,
firstStreet = firstStreet,
gender = gender,
priority = priority,
origin = origin,
dispatchMessage = dispatchMessage,
name = getCaller(source),
number = plyData['phone_number'],
job = {"police","ambulance"},
information = msg
})
end)
RegisterNetEvent('erp-dispatch:vehiclecrash')
AddEventHandler('erp-dispatch:vehiclecrash', function(sentCoords)
TriggerClientEvent('erp-dispatch:vehiclecrash', -1, sentCoords)
end)
-- erp-dispatch:banktruck
RegisterNetEvent('erp-dispatch:banktruck')
AddEventHandler('erp-dispatch:banktruck', function(sentCoords)
TriggerClientEvent('erp-dispatch:banktruck', -1, sentCoords)
end)
-- erp-dispatch:art
RegisterNetEvent('erp-dispatch:art')
AddEventHandler('erp-dispatch:art', function(sentCoords)
TriggerClientEvent('erp-dispatch:art', -1, sentCoords)
end)
RegisterNetEvent('erp-dispatch:g6')
AddEventHandler('erp-dispatch:g6', function(sentCoords)
TriggerClientEvent('erp-dispatch:g6', -1, sentCoords)
end)
RegisterNetEvent('erp-dispatch:carboosting')
AddEventHandler('erp-dispatch:carboosting', function(sentCoords, vehicle, alert)
TriggerClientEvent('erp-dispatch:carboosting', -1, sentCoords, vehicle, alert)
end)
RegisterNetEvent('erp-dispatch:yachtheist')
AddEventHandler('erp-dispatch:yachtheist', function(sentCoords)
TriggerClientEvent('erp-dispatch:yachtheist', -1, sentCoords)
end)
RegisterNetEvent('erp-dispatch:vehicletheft')
AddEventHandler('erp-dispatch:vehicletheft', function(sentCoords)
TriggerClientEvent('erp-dispatch:vehicletheft', -1, sentCoords)
end)
RegisterNetEvent('erp-dispatch:blip:jailbreak')
AddEventHandler('erp-dispatch:blip:jailbreak', function(sentCoords)
TriggerClientEvent('erp-dispatch:blip:jailbreak', -1, sentCoords)
end)
RegisterNetEvent('erp-dispatch:drugsale')
AddEventHandler('erp-dispatch:drugsale', function(sentCoords)
TriggerClientEvent('erp-dispatch:drugsale', -1, sentCoords)
end)
RegisterNetEvent('erp-dispatch:officerAlert')
AddEventHandler('erp-dispatch:officerAlert', function(pos, name)
TriggerClientEvent('erp-dispatch:officerAlert', -1, pos, name, source)
end)
--[[ Officer downs ]]
RegisterNetEvent('erp-dispatch:policealertA')
AddEventHandler('erp-dispatch:policealertA', function(sentCoords)
TriggerClientEvent('erp-dispatch:policealertA', -1, sentCoords)
end)
RegisterNetEvent('erp-dispatch:policealertB')
AddEventHandler('erp-dispatch:policealertB', function(sentCoords)
TriggerClientEvent('erp-dispatch:policealertB', -1, sentCoords)
end)
CreateThread(function()
while true do
Wait(3600000) -- 1 hour
calls = {}
end
end)
RegisterNetEvent('erp-dispatch:emsalertA')
AddEventHandler('erp-dispatch:emsalertA', function(sentCoords)
TriggerClientEvent('erp-dispatch:emsalertA', -1, sentCoords)
end)
RegisterNetEvent('erp-dispatch:emsalertB')
AddEventHandler('erp-dispatch:emsalertB', function(sentCoords)
TriggerClientEvent('erp-dispatch:emsalertB', -1, sentCoords)
end)