Repository navigation
Expand file tree
/
Copy pathserver.lua
More file actions
93 lines (81 loc) · 4.36 KB
/
Copy pathserver.lua
File metadata and controls
93 lines (81 loc) · 4.36 KB
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
QBCore = exports['qb-core']:GetCoreObject()
-- Commands
QBCore.Commands.Add('comserv', 'Send To Community Service', {{name='id', help='Target ID'}, {name='amount', help='Action Amount'}}, true, function(source, args)
local src = source
local target = tonumber(args[1])
local targetPlayer = GetPlayerPed(target)
local amount = tonumber(args[2])
local Player = QBCore.Functions.GetPlayer(src)
if Player.PlayerData.job.name == "police" then
if targetPlayer ~= 0 then
if amount > 0 then
TriggerEvent('qb-communityservice:server:sendToCommunityService', target, amount)
TriggerClientEvent('QBCore:Notify', source, 'This citizen has been sentenced to community service!', 'success')
TriggerClientEvent('QBCore:Notify', target, 'You Have Been Sentenced To '..amount.. ' Month(s) of Community Service')
else
TriggerClientEvent('QBCore:Notify', source, 'Invalid amount of months', 'error')
end
else
TriggerClientEvent('QBCore:Notify', source, 'Invalid citizen ID', 'error')
end
else
TriggerClientEvent('QBCore:Notify', source, 'You are not a police officer', 'error')
end
end)
QBCore.Commands.Add('endcomserv', 'End Community Service', {{name='id', help='Target ID'}}, true, function(source, args)
local src = source
local target = tonumber(args[1])
local targetPlayer = GetPlayerPed(target)
local Player = QBCore.Functions.GetPlayer(src)
if Player.PlayerData.job.name == "police" then
if targetPlayer ~= 0 then
Release(target)
else
TriggerClientEvent('QBCore:Notify', source, 'Invalid citizen ID', 'error')
end
else
TriggerClientEvent('QBCore:Notify', source, 'You are not a police officer', 'error')
end
end)
RegisterServerEvent('qb-communityservice:server:finishCommunityService')
AddEventHandler('qb-communityservice:server:finishCommunityService', function(source)
local src = source
Release(src)
end)
-- Events
RegisterServerEvent('qb-communityservice:server:checkIfSentenced')
AddEventHandler('qb-communityservice:server:checkIfSentenced', function()
local src = source
local citizenid = QBCore.Functions.GetPlayer(src).PlayerData.citizenid
local result = MySQL.Sync.fetchAll('SELECT * FROM communityservice WHERE citizenid = ?', {citizenid})
if result[1] ~= nil and result[1].actions_remaining > 0 then
TriggerClientEvent('qb-communityservice:client:inCommunityService', src, tonumber(result[1].actions_remaining))
end
end)
RegisterServerEvent('qb-communityservice:server:completeService')
AddEventHandler('qb-communityservice:server:completeService', function()
local src = source
local citizenid = QBCore.Functions.GetPlayer(src).PlayerData.citizenid
MySQL.Async.execute('UPDATE communityservice SET actions_remaining = actions_remaining - 1 WHERE citizenid = ?', {citizenid})
end)
RegisterServerEvent('qb-communityservice:server:extendService')
AddEventHandler('qb-communityservice:server:extendService', function()
local src = source
local citizenid = QBCore.Functions.GetPlayer(src).PlayerData.citizenid
MySQL.Async.execute('UPDATE communityservice SET actions_remaining = actions_remaining + @extension_value WHERE citizenid = ?', {citizenid, Config.ServiceExtensionOnEscape})
end)
RegisterServerEvent('qb-communityservice:server:sendToCommunityService')
AddEventHandler('qb-communityservice:server:sendToCommunityService', function(target, actions_count)
local Ply = QBCore.Functions.GetPlayer(target)
local citizenid = Ply.PlayerData.citizenid
MySQL.Async.insert('INSERT INTO communityservice (citizenid, actions_remaining) VALUES (?, ?) ON DUPLICATE KEY UPDATE actions_remaining = ?', {citizenid, actions_count})
TriggerClientEvent('qb-communityservice:client:inCommunityService', target, actions_count)
end)
-- Functions
function Release(target)
local Ply = QBCore.Functions.GetPlayer(target)
local citizenid = Ply.PlayerData.citizenid
MySQL.Async.execute('DELETE FROM communityservice WHERE citizenid = ?', {citizenid})
TriggerClientEvent('QBCore:Notify', target, 'Community service completed', 'success')
TriggerClientEvent('qb-communityservice:client:finishCommunityService', target)
end