-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.lua
299 lines (236 loc) · 9.12 KB
/
server.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
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
ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
TriggerEvent('esx_society:registerSociety', 'police', 'Police', 'society_police', 'society_police', 'society_police', {type = 'public'})
RegisterServerEvent("esx_policejob:giveWeapon")
AddEventHandler("esx_policejob:giveWeapon", function(weapon)
local player = ESX.GetPlayerFromId(source)
if player then
player.addWeapon(weapon, Config.ReceiveAmmo)
TriggerClientEvent("esx:showNotification", source, "You just received 1x " .. ESX.GetWeaponLabel(weapon) .. " with " .. Config.ReceiveAmmo .. "x ammo.")
end
end)
RegisterServerEvent("esx_policejob:GetKit")
AddEventHandler("esx_policejob:GetKit", function()
local xPlayer = ESX.GetPlayerFromId(source)
local xGPS = xPlayer.getInventoryItem('gps')
if xGPS.count > 0 then
TriggerClientEvent('mythic_notify:client:SendAlert', source, { type = 'inform', text = 'You were not given a GPS as you already have one'})
else
xPlayer.addInventoryItem('gps', 1)
end
local xGPS = xPlayer.getInventoryItem('fixkit')
if xGPS.count > 1 then
TriggerClientEvent('mythic_notify:client:SendAlert', source, { type = 'inform', text = 'You were not given Repair Kits as you already have two'})
else
xPlayer.addInventoryItem('fixkit', 1)
end
local xGPS = xPlayer.getInventoryItem('radio')
if xGPS.count > 0 then
TriggerClientEvent('mythic_notify:client:SendAlert', source, { type = 'inform', text = 'You were not given a radio as you already have one'})
else
xPlayer.addInventoryItem('radio', 1)
end
local xGPS = xPlayer.getInventoryItem('phone')
if xGPS.count > 0 then
TriggerClientEvent('mythic_notify:client:SendAlert', source, { type = 'inform', text = 'You were not given a phone as you already have one'})
else
xPlayer.addInventoryItem('phone', 1)
end
local xGPS = xPlayer.getInventoryItem('bread')
if xGPS.count > 4 then
TriggerClientEvent('mythic_notify:client:SendAlert', source, { type = 'inform', text = 'You were not given bread as you already have five'})
else
xPlayer.addInventoryItem('bread', 1)
end
local xGPS = xPlayer.getInventoryItem('water')
if xGPS.count > 4 then
TriggerClientEvent('mythic_notify:client:SendAlert', source, { type = 'inform', text = 'You were not given a water as you already have five'})
else
xPlayer.addInventoryItem('water', 1)
end
local xGPS = xPlayer.getInventoryItem('weabox')
if xGPS.count > 1 then
TriggerClientEvent('mythic_notify:client:SendAlert', source, { type = 'inform', text = 'You were not given an ammo box as you already have one'})
else
xPlayer.addInventoryItem('weabox', 1)
end
end)
RegisterServerEvent('esx_policejob:CuffPlayer')
AddEventHandler('esx_policejob:CuffPlayer', function(target)
local xPlayer = ESX.GetPlayerFromId(source)
local xItem = xPlayer.getInventoryItem("cuffs")
if target ~= -1 then
if xItem.count >= 1 then
TriggerClientEvent('esx_policejob:CuffPlayer', target)
else
TriggerClientEvent('mythic_notify:client:SendAlert', source, { type = 'error', text = 'You need cuffs to cuff someone'})
end
else
TriggerClientEvent('mythic_notify:client:SendAlert', source, { type = 'error', text = 'No Player Found!'})
end
end)
RegisterNetEvent('esx_policejob:drag')
AddEventHandler('esx_policejob:drag', function(target)
local xPlayer = ESX.GetPlayerFromId(source)
if target ~= -1 then
TriggerClientEvent('esx_policejob:drag', target, source)
else
TriggerClientEvent('mythic_notify:client:SendAlert', source, { type = 'error', text = 'No Player Found!'})
end
end)
RegisterNetEvent('esx_policejob:putInVehicle')
AddEventHandler('esx_policejob:putInVehicle', function(target)
local xPlayer = ESX.GetPlayerFromId(source)
TriggerClientEvent('esx_policejob:putInVehicle', target)
end)
RegisterNetEvent('esx_policejob:OutVehicle')
AddEventHandler('esx_policejob:OutVehicle', function(target)
local xPlayer = ESX.GetPlayerFromId(source)
if target ~= -1 then
TriggerClientEvent('esx_policejob:OutVehicle', target)
else
TriggerClientEvent('mythic_notify:client:SendAlert', source, { type = 'error', text = 'No Player Found!'})
end
end)
RegisterServerEvent('esx_policejob:putStockItems')
AddEventHandler('esx_policejob:putStockItems', function(itemName, count)
local xPlayer = ESX.GetPlayerFromId(source)
TriggerEvent('esx_addoninventory:getSharedInventory', 'society_police', function(inventory)
local item = inventory.getItem(itemName)
if item.count >= 0 then
xPlayer.removeInventoryItem(itemName, count)
inventory.addItem(itemName, count)
else
--TriggerClientEvent('esx:showNotification', xPlayer.source, _U('quantity_invalid'))
end
--TriggerClientEvent('esx:showNotification', xPlayer.source, _U('added') .. count .. ' ' .. item.label)
end)
end)
--[[ RegisterServerEvent('esx_policejob:logBill')
AddEventHandler("esx_policejob:logBill", function(issuer, Recipient, sharedAccountName, label, amount)
--print(GetPlayerName(Recipient))
local issuerID = issuer.identifier
MySQL.Async.fetchAll("SELECT * FROM users where identifier = @issuer", {
["@issuer"] = issuerID
}, function(result)
if result ~= nil then
--print("Officer Name: "..result[1].name)
else
print("No Officer Found, please clip this and report to admin")
end
end)
end) ]]
--Put weapon in armory
ESX.RegisterServerCallback('esx_policejob:addArmoryWeapon', function(source, cb, weaponName, removeWeapon)
local xPlayer = ESX.GetPlayerFromId(source)
if removeWeapon then
xPlayer.removeWeapon(weaponName)
end
TriggerEvent('esx_datastore:getSharedDataStore', 'society_police', function(store)
local weapons = store.get('weapons')
if weapons == nil then
weapons = {}
end
local foundWeapon = false
for i=1, #weapons, 1 do
if weapons[i].name == weaponName then
weapons[i].count = weapons[i].count + 1
foundWeapon = true
end
end
if not foundWeapon then
table.insert(weapons, {
name = weaponName,
count = 1
})
end
store.set('weapons', weapons)
cb()
end)
end)
--Get Player Inventory
ESX.RegisterServerCallback('esx_policejob:getPlayerInventory', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
local items = xPlayer.inventory
cb({
items = items
})
end)
--Sell drugs to researchers
RegisterServerEvent('DA&D92nD_293kTeu:sell82jdgh26drug')
AddEventHandler('DA&D92nD_293kTeu:sell82jdgh26drug', function(itemName, amount)
local xPlayer = ESX.GetPlayerFromId(source)
local price = Config.DrugPrices[itemName]
local xItem = xPlayer.getInventoryItem(itemName)
if not price then
print(('esx_illegal: %s attempted to sell an invalid drug!'):format(xPlayer.identifier))
return
end
if xItem.count < amount then
TriggerClientEvent('esx:showNotification', source, _U('dealer_notenough'))
return
end
price = ESX.Math.Round(price * amount)
xPlayer.addMoney(price)
xPlayer.removeInventoryItem(xItem.name, amount)
end)
RegisterServerEvent('637D_dmlo:WashMoney*nn2jdad')
AddEventHandler('637D_dmlo:WashMoney*nn2jdad', function()
local xPlayer = ESX.GetPlayerFromId(source)
local amount = xPlayer.GetAccount('black_money')
xPlayer.removeAccountMoney(amount)
xPlayer.addMoney(amount)
end)
RegisterServerEvent('esx_policejob:getStockItem')
AddEventHandler('esx_policejob:getStockItem', function(itemName, count)
local xPlayer = ESX.GetPlayerFromId(source)
TriggerEvent('esx_addoninventory:getSharedInventory', 'society_police', function(inventory)
local item = inventory.getItem(itemName)
if item.count >= count then
inventory.removeItem(itemName, count)
xPlayer.addInventoryItem(itemName, count)
else
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('quantity_invalid'))
end
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('have_withdrawn') .. count .. ' ' .. item.label)
end)
end)
ESX.RegisterServerCallback('esx_policejob:getArmoryWeapons', function(source, cb)
TriggerEvent('esx_datastore:getSharedDataStore', 'society_police', function(store)
local weapons = store.get('weapons')
if weapons == nil then
weapons = {}
end
cb(weapons)
end)
end)
ESX.RegisterServerCallback('esx_policejob:removeArmoryWeapon', function(source, cb, weaponName)
local xPlayer = ESX.GetPlayerFromId(source)
xPlayer.addWeapon(weaponName, 250)
TriggerEvent('esx_datastore:getSharedDataStore', 'society_police', function(store)
local weapons = store.get('weapons')
if weapons == nil then
weapons = {}
end
local foundWeapon = false
for i=1, #weapons, 1 do
if weapons[i].name == weaponName then
weapons[i].count = (weapons[i].count > 0 and weapons[i].count - 1 or 0)
foundWeapon = true
end
end
if not foundWeapon then
table.insert(weapons, {
name = weaponName,
count = 0
})
end
store.set('weapons', weapons)
cb()
end)
end)
ESX.RegisterServerCallback('esx_policejob:getStockItems', function(source, cb)
TriggerEvent('esx_addoninventory:getSharedInventory', 'society_police', function(inventory)
cb(inventory.items)
end)
end)