-
-
Notifications
You must be signed in to change notification settings - Fork 749
/
Copy pathmain.lua
696 lines (606 loc) · 25.4 KB
/
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
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
SetMapName('San Andreas')
SetGameType('ESX Legacy')
local newPlayer = 'INSERT INTO `users` SET `accounts` = ?, `identifier` = ?, `group` = ?'
local loadPlayer = 'SELECT `accounts`, `job`, `job_grade`, `group`, `position`, `inventory`, `skin`, `loadout`'
if Config.Multichar then
newPlayer = newPlayer .. ', `firstname` = ?, `lastname` = ?, `dateofbirth` = ?, `sex` = ?, `height` = ?'
end
if Config.Multichar or Config.Identity then
loadPlayer = loadPlayer .. ', `firstname`, `lastname`, `dateofbirth`, `sex`, `height`'
end
loadPlayer = loadPlayer .. ' FROM `users` WHERE identifier = ?'
if Config.Multichar then
AddEventHandler('esx:onPlayerJoined', function(src, char, data)
while not next(ESX.Jobs) do
Wait(50)
end
if not ESX.Players[src] then
local identifier = char .. ':' .. ESX.GetIdentifier(src)
if data then
createESXPlayer(identifier, src, data)
else
loadESXPlayer(identifier, src, false)
end
end
end)
else
RegisterNetEvent('esx:onPlayerJoined')
AddEventHandler('esx:onPlayerJoined', function()
local _source = source
while not next(ESX.Jobs) do
Wait(50)
end
if not ESX.Players[_source] then
onPlayerJoined(_source)
end
end)
end
function onPlayerJoined(playerId)
local identifier = ESX.GetIdentifier(playerId)
if identifier then
if ESX.GetPlayerFromIdentifier(identifier) then
DropPlayer(playerId,
('there was an error loading your character!\nError code: identifier-active-ingame\n\nThis error is caused by a player on this server who has the same identifier as you have. Make sure you are not playing on the same Rockstar account.\n\nYour Rockstar identifier: %s'):format(
identifier))
else
local result = MySQL.scalar.await('SELECT 1 FROM users WHERE identifier = ?', {identifier})
if result then
loadESXPlayer(identifier, playerId, false)
else
createESXPlayer(identifier, playerId)
end
end
else
DropPlayer(playerId,
'there was an error loading your character!\nError code: identifier-missing-ingame\n\nThe cause of this error is not known, your identifier could not be found. Please come back later or report this problem to the server administration team.')
end
end
function createESXPlayer(identifier, playerId, data)
local accounts = {}
for account, money in pairs(Config.StartingAccountMoney) do
accounts[account] = money
end
if Core.IsPlayerAdmin(playerId) then
print(('^2[INFO] ^0 Player ^5%s ^0Has been granted admin permissions via ^5Ace Perms.^7'):format(playerId))
defaultGroup = "admin"
else
defaultGroup = "user"
end
if not Config.Multichar then
MySQL.prepare(newPlayer, {json.encode(accounts), identifier, defaultGroup}, function()
loadESXPlayer(identifier, playerId, true)
end)
else
MySQL.prepare(newPlayer,
{json.encode(accounts), identifier, defaultGroup, data.firstname, data.lastname, data.dateofbirth, data.sex,
data.height}, function()
loadESXPlayer(identifier, playerId, true)
end)
end
end
if not Config.Multichar then
AddEventHandler('playerConnecting', function(name, setCallback, deferrals)
deferrals.defer()
local playerId = source
local identifier = ESX.GetIdentifier(playerId)
if identifier then
if ESX.GetPlayerFromIdentifier(identifier) then
deferrals.done(
('There was an error loading your character!\nError code: identifier-active\n\nThis error is caused by a player on this server who has the same identifier as you have. Make sure you are not playing on the same account.\n\nYour identifier: %s'):format(
identifier))
else
deferrals.done()
end
else
deferrals.done(
'There was an error loading your character!\nError code: identifier-missing\n\nThe cause of this error is not known, your identifier could not be found. Please come back later or report this problem to the server administration team.')
end
end)
end
function loadESXPlayer(identifier, playerId, isNew)
local userData = {
accounts = {},
inventory = {},
job = {},
loadout = {},
playerName = GetPlayerName(playerId),
weight = 0
}
local result = MySQL.prepare.await(loadPlayer, {identifier})
local job, grade, jobObject, gradeObject = result.job, tostring(result.job_grade)
local foundAccounts, foundItems = {}, {}
-- Accounts
if result.accounts and result.accounts ~= '' then
local accounts = json.decode(result.accounts)
for account, money in pairs(accounts) do
foundAccounts[account] = money
end
end
for account, label in pairs(Config.Accounts) do
table.insert(userData.accounts, {
name = account,
money = foundAccounts[account] or Config.StartingAccountMoney[account] or 0,
label = label
})
end
-- Job
if ESX.DoesJobExist(job, grade) then
jobObject, gradeObject = ESX.Jobs[job], ESX.Jobs[job].grades[grade]
else
print(('[^3WARNING^7] Ignoring invalid job for %s [job: %s, grade: %s]'):format(identifier, job, grade))
job, grade = 'unemployed', '0'
jobObject, gradeObject = ESX.Jobs[job], ESX.Jobs[job].grades[grade]
end
userData.job.id = jobObject.id
userData.job.name = jobObject.name
userData.job.label = jobObject.label
userData.job.grade = tonumber(grade)
userData.job.grade_name = gradeObject.name
userData.job.grade_label = gradeObject.label
userData.job.grade_salary = gradeObject.salary
userData.job.onDuty = Config.OnDuty
userData.job.skin_male = {}
userData.job.skin_female = {}
if gradeObject.skin_male then
userData.job.skin_male = json.decode(gradeObject.skin_male)
end
if gradeObject.skin_female then
userData.job.skin_female = json.decode(gradeObject.skin_female)
end
-- Inventory
if not Config.OxInventory then
if result.inventory and result.inventory ~= '' then
local inventory = json.decode(result.inventory)
for name, count in pairs(inventory) do
local item = ESX.Items[name]
if item then
foundItems[name] = count
else
print(('[^3WARNING^7] Ignoring invalid item "%s" for "%s"'):format(name, identifier))
end
end
end
for name, item in pairs(ESX.Items) do
local count = foundItems[name] or 0
if count > 0 then
userData.weight = userData.weight + (item.weight * count)
end
table.insert(userData.inventory, {
name = name,
count = count,
label = item.label,
weight = item.weight,
usable = Core.UsableItemsCallbacks[name] ~= nil,
rare = item.rare,
canRemove = item.canRemove
})
end
table.sort(userData.inventory, function(a, b)
return a.label < b.label
end)
else
if result.inventory and result.inventory ~= '' then
userData.inventory = json.decode(result.inventory)
else
userData.inventory = {}
end
end
-- Group
if result.group then
if result.group == "superadmin" then
userData.group = "admin"
else
userData.group = result.group
end
else
userData.group = 'user'
end
-- Loadout
if not Config.OxInventory then
if result.loadout and result.loadout ~= '' then
local loadout = json.decode(result.loadout)
for name, weapon in pairs(loadout) do
local label = ESX.GetWeaponLabel(name)
if label then
if not weapon.components then
weapon.components = {}
end
if not weapon.tintIndex then
weapon.tintIndex = 0
end
table.insert(userData.loadout, {
name = name,
ammo = weapon.ammo,
label = label,
components = weapon.components,
tintIndex = weapon.tintIndex
})
end
end
end
end
-- Position
if result.position and result.position ~= '' then
userData.coords = json.decode(result.position)
else
print(
'[^3WARNING^7] Column ^5"position"^0 in ^5"users"^0 table is missing required default value. Using backup coords, fix your database.')
userData.coords = {
x = -269.4,
y = -955.3,
z = 31.2,
heading = 205.8
}
end
-- Skin
if result.skin and result.skin ~= '' then
userData.skin = json.decode(result.skin)
else
if userData.sex == 'f' then
userData.skin = {
sex = 1
}
else
userData.skin = {
sex = 0
}
end
end
-- Identity
if result.firstname and result.firstname ~= '' then
userData.firstname = result.firstname
userData.lastname = result.lastname
userData.playerName = userData.firstname .. ' ' .. userData.lastname
if result.dateofbirth then
userData.dateofbirth = result.dateofbirth
end
if result.sex then
userData.sex = result.sex
end
if result.height then
userData.height = result.height
end
end
local xPlayer = CreateExtendedPlayer(playerId, identifier, userData.group, userData.accounts, userData.inventory,
userData.weight, userData.job, userData.loadout, userData.playerName, userData.coords)
ESX.Players[playerId] = xPlayer
if userData.firstname then
xPlayer.set('firstName', userData.firstname)
xPlayer.set('lastName', userData.lastname)
if userData.dateofbirth then
xPlayer.set('dateofbirth', userData.dateofbirth)
end
if userData.sex then
xPlayer.set('sex', userData.sex)
end
if userData.height then
xPlayer.set('height', userData.height)
end
end
TriggerEvent('esx:playerLoaded', playerId, xPlayer, isNew)
xPlayer.triggerEvent('esx:playerLoaded', {
accounts = xPlayer.getAccounts(),
coords = xPlayer.getCoords(),
identifier = xPlayer.getIdentifier(),
inventory = xPlayer.getInventory(),
job = xPlayer.getJob(),
loadout = xPlayer.getLoadout(),
maxWeight = xPlayer.getMaxWeight(),
money = xPlayer.getMoney(),
dead = false
}, isNew, userData.skin)
if not Config.OxInventory then
xPlayer.triggerEvent('esx:createMissingPickups', Core.Pickups)
else
exports.ox_inventory:setPlayerInventory(xPlayer, userData.inventory)
end
xPlayer.triggerEvent('esx:registerSuggestions', Core.RegisteredCommands)
print(('[^2INFO^0] Player ^5"%s" ^0has connected to the server. ID: ^5%s^7'):format(xPlayer.getName(), playerId))
end
AddEventHandler('chatMessage', function(playerId, author, message)
local xPlayer = ESX.GetPlayerFromId(playerId)
if message:sub(1, 1) == '/' and playerId > 0 then
CancelEvent()
local commandName = message:sub(1):gmatch("%w+")()
xPlayer.showNotification(_U('commanderror_invalidcommand', commandName))
end
end)
AddEventHandler('playerDropped', function(reason)
local playerId = source
local xPlayer = ESX.GetPlayerFromId(playerId)
if xPlayer then
TriggerEvent('esx:playerDropped', playerId, reason)
Core.SavePlayer(xPlayer, function()
ESX.Players[playerId] = nil
end)
end
end)
AddEventHandler('esx:playerLogout', function(playerId, cb)
local xPlayer = ESX.GetPlayerFromId(playerId)
if xPlayer then
TriggerEvent('esx:playerDropped', playerId)
Core.SavePlayer(xPlayer, function()
ESX.Players[playerId] = nil
if cb then
cb()
end
end)
end
TriggerClientEvent("esx:onPlayerLogout", playerId)
end)
RegisterNetEvent('esx:updateCoords')
AddEventHandler('esx:updateCoords', function(coords)
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer then
xPlayer.updateCoords(coords)
end
end)
if not Config.OxInventory then
RegisterNetEvent('esx:updateWeaponAmmo')
AddEventHandler('esx:updateWeaponAmmo', function(weaponName, ammoCount)
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer then
xPlayer.updateWeaponAmmo(weaponName, ammoCount)
end
end)
RegisterNetEvent('esx:giveInventoryItem')
AddEventHandler('esx:giveInventoryItem', function(target, type, itemName, itemCount)
local playerId = source
local sourceXPlayer = ESX.GetPlayerFromId(playerId)
local targetXPlayer = ESX.GetPlayerFromId(target)
local distance = #(GetEntityCoords(GetPlayerPed(playerId)) - GetEntityCoords(GetPlayerPed(target)))
if not sourceXPlayer then
return
end
if not targetXPlayer then
print("Cheating: " .. GetPlayerName(playerId))
return
end
if distance > Config.DistanceGive then
print("Cheating: " .. GetPlayerName(playerId))
return
end
if type == 'item_standard' then
local sourceItem = sourceXPlayer.getInventoryItem(itemName)
if itemCount > 0 and sourceItem.count >= itemCount then
if targetXPlayer.canCarryItem(itemName, itemCount) then
sourceXPlayer.removeInventoryItem(itemName, itemCount)
targetXPlayer.addInventoryItem(itemName, itemCount)
sourceXPlayer.showNotification(_U('gave_item', itemCount, sourceItem.label, targetXPlayer.name))
targetXPlayer.showNotification(_U('received_item', itemCount, sourceItem.label, sourceXPlayer.name))
else
sourceXPlayer.showNotification(_U('ex_inv_lim', targetXPlayer.name))
end
else
sourceXPlayer.showNotification(_U('imp_invalid_quantity'))
end
elseif type == 'item_account' then
if itemCount > 0 and sourceXPlayer.getAccount(itemName).money >= itemCount then
sourceXPlayer.removeAccountMoney(itemName, itemCount)
targetXPlayer.addAccountMoney(itemName, itemCount)
sourceXPlayer.showNotification(_U('gave_account_money', ESX.Math.GroupDigits(itemCount),
Config.Accounts[itemName], targetXPlayer.name))
targetXPlayer.showNotification(_U('received_account_money', ESX.Math.GroupDigits(itemCount),
Config.Accounts[itemName], sourceXPlayer.name))
else
sourceXPlayer.showNotification(_U('imp_invalid_amount'))
end
elseif type == 'item_weapon' then
if sourceXPlayer.hasWeapon(itemName) then
local weaponLabel = ESX.GetWeaponLabel(itemName)
if not targetXPlayer.hasWeapon(itemName) then
local _, weapon = sourceXPlayer.getWeapon(itemName)
local _, weaponObject = ESX.GetWeapon(itemName)
itemCount = weapon.ammo
local weaponComponents = ESX.Table.Clone(weapon.components)
local weaponTint = weapon.tintIndex
if weaponTint then
targetXPlayer.setWeaponTint(itemName, weaponTint)
end
if weaponComponents then
for k, v in pairs(weaponComponents) do
targetXPlayer.addWeaponComponent(itemName, v)
end
end
sourceXPlayer.removeWeapon(itemName)
targetXPlayer.addWeapon(itemName, itemCount)
if weaponObject.ammo and itemCount > 0 then
local ammoLabel = weaponObject.ammo.label
sourceXPlayer.showNotification(_U('gave_weapon_withammo', weaponLabel, itemCount, ammoLabel,
targetXPlayer.name))
targetXPlayer.showNotification(_U('received_weapon_withammo', weaponLabel, itemCount, ammoLabel,
sourceXPlayer.name))
else
sourceXPlayer.showNotification(_U('gave_weapon', weaponLabel, targetXPlayer.name))
targetXPlayer.showNotification(_U('received_weapon', weaponLabel, sourceXPlayer.name))
end
else
sourceXPlayer.showNotification(_U('gave_weapon_hasalready', targetXPlayer.name, weaponLabel))
targetXPlayer.showNotification(_U('received_weapon_hasalready', sourceXPlayer.name, weaponLabel))
end
end
elseif type == 'item_ammo' then
if sourceXPlayer.hasWeapon(itemName) then
local weaponNum, weapon = sourceXPlayer.getWeapon(itemName)
if targetXPlayer.hasWeapon(itemName) then
local _, weaponObject = ESX.GetWeapon(itemName)
if weaponObject.ammo then
local ammoLabel = weaponObject.ammo.label
if weapon.ammo >= itemCount then
sourceXPlayer.removeWeaponAmmo(itemName, itemCount)
targetXPlayer.addWeaponAmmo(itemName, itemCount)
sourceXPlayer.showNotification(_U('gave_weapon_ammo', itemCount, ammoLabel, weapon.label,
targetXPlayer.name))
targetXPlayer.showNotification(_U('received_weapon_ammo', itemCount, ammoLabel,
weapon.label, sourceXPlayer.name))
end
end
else
sourceXPlayer.showNotification(_U('gave_weapon_noweapon', targetXPlayer.name))
targetXPlayer.showNotification(_U('received_weapon_noweapon', sourceXPlayer.name, weapon.label))
end
end
end
end)
RegisterNetEvent('esx:removeInventoryItem')
AddEventHandler('esx:removeInventoryItem', function(type, itemName, itemCount)
local playerId = source
local xPlayer = ESX.GetPlayerFromId(source)
if type == 'item_standard' then
if itemCount == nil or itemCount < 1 then
xPlayer.showNotification(_U('imp_invalid_quantity'))
else
local xItem = xPlayer.getInventoryItem(itemName)
if (itemCount > xItem.count or xItem.count < 1) then
xPlayer.showNotification(_U('imp_invalid_quantity'))
else
xPlayer.removeInventoryItem(itemName, itemCount)
local pickupLabel = ('%s [%s]'):format(xItem.label, itemCount)
ESX.CreatePickup('item_standard', itemName, itemCount, pickupLabel, playerId)
xPlayer.showNotification(_U('threw_standard', itemCount, xItem.label))
end
end
elseif type == 'item_account' then
if itemCount == nil or itemCount < 1 then
xPlayer.showNotification(_U('imp_invalid_amount'))
else
local account = xPlayer.getAccount(itemName)
if (itemCount > account.money or account.money < 1) then
xPlayer.showNotification(_U('imp_invalid_amount'))
else
xPlayer.removeAccountMoney(itemName, itemCount)
local pickupLabel = ('%s [%s]'):format(account.label, _U('locale_currency', ESX.Math
.GroupDigits(itemCount)))
ESX.CreatePickup('item_account', itemName, itemCount, pickupLabel, playerId)
xPlayer.showNotification(_U('threw_account', ESX.Math.GroupDigits(itemCount),
string.lower(account.label)))
end
end
elseif type == 'item_weapon' then
itemName = string.upper(itemName)
if xPlayer.hasWeapon(itemName) then
local _, weapon = xPlayer.getWeapon(itemName)
local _, weaponObject = ESX.GetWeapon(itemName)
local components, pickupLabel = ESX.Table.Clone(weapon.components)
xPlayer.removeWeapon(itemName)
if weaponObject.ammo and weapon.ammo > 0 then
local ammoLabel = weaponObject.ammo.label
pickupLabel = ('%s [%s %s]'):format(weapon.label, weapon.ammo, ammoLabel)
xPlayer.showNotification(_U('threw_weapon_ammo', weapon.label, weapon.ammo, ammoLabel))
else
pickupLabel = ('%s'):format(weapon.label)
xPlayer.showNotification(_U('threw_weapon', weapon.label))
end
ESX.CreatePickup('item_weapon', itemName, weapon.ammo, pickupLabel, playerId, components,
weapon.tintIndex)
end
end
end)
RegisterNetEvent('esx:useItem')
AddEventHandler('esx:useItem', function(itemName)
local xPlayer = ESX.GetPlayerFromId(source)
local count = xPlayer.getInventoryItem(itemName).count
if count > 0 then
ESX.UseItem(source, itemName)
else
xPlayer.showNotification(_U('act_imp'))
end
end)
RegisterNetEvent('esx:onPickup')
AddEventHandler('esx:onPickup', function(pickupId)
local pickup, xPlayer, success = Core.Pickups[pickupId], ESX.GetPlayerFromId(source)
if pickup then
if pickup.type == 'item_standard' then
if xPlayer.canCarryItem(pickup.name, pickup.count) then
xPlayer.addInventoryItem(pickup.name, pickup.count)
success = true
else
xPlayer.showNotification(_U('threw_cannot_pickup'))
end
elseif pickup.type == 'item_account' then
success = true
xPlayer.addAccountMoney(pickup.name, pickup.count)
elseif pickup.type == 'item_weapon' then
if xPlayer.hasWeapon(pickup.name) then
xPlayer.showNotification(_U('threw_weapon_already'))
else
success = true
xPlayer.addWeapon(pickup.name, pickup.count)
xPlayer.setWeaponTint(pickup.name, pickup.tintIndex)
for k, v in ipairs(pickup.components) do
xPlayer.addWeaponComponent(pickup.name, v)
end
end
end
if success then
Core.Pickups[pickupId] = nil
TriggerClientEvent('esx:removePickup', -1, pickupId)
end
end
end)
end
ESX.RegisterServerCallback('esx:getPlayerData', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
cb({
identifier = xPlayer.identifier,
accounts = xPlayer.getAccounts(),
inventory = xPlayer.getInventory(),
job = xPlayer.getJob(),
loadout = xPlayer.getLoadout(),
money = xPlayer.getMoney(),
position = xPlayer.getCoords(true)
})
end)
ESX.RegisterServerCallback('esx:isUserAdmin', function(source, cb)
cb(Core.IsPlayerAdmin(source))
end)
ESX.RegisterServerCallback('esx:getOtherPlayerData', function(source, cb, target)
local xPlayer = ESX.GetPlayerFromId(target)
cb({
identifier = xPlayer.identifier,
accounts = xPlayer.getAccounts(),
inventory = xPlayer.getInventory(),
job = xPlayer.getJob(),
loadout = xPlayer.getLoadout(),
money = xPlayer.getMoney(),
position = xPlayer.getCoords(true)
})
end)
ESX.RegisterServerCallback('esx:getPlayerNames', function(source, cb, players)
players[source] = nil
for playerId, v in pairs(players) do
local xPlayer = ESX.GetPlayerFromId(playerId)
if xPlayer then
players[playerId] = xPlayer.getName()
else
players[playerId] = nil
end
end
cb(players)
end)
AddEventHandler('txAdmin:events:scheduledRestart', function(eventData)
if eventData.secondsRemaining == 60 then
CreateThread(function()
Wait(50000)
Core.SavePlayers()
end)
end
end)
AddEventHandler('txAdmin:events:serverShuttingDown', function()
Core.SavePlayers()
end)
RegisterNetEvent('esx:setDuty')
AddEventHandler('esx:setDuty', function(bool)
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer.job.onDuty == bool then
return
end
if bool then
xPlayer.setDuty(true)
xPlayer.triggerEvent('esx:showNotification', _U('started_duty'))
else
xPlayer.setDuty(false)
xPlayer.triggerEvent('esx:showNotification', _U('stopped_duty'))
end
TriggerClientEvent('esx:setJob', xPlayer.source, xPlayer.job)
end)