-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathclient.lua
More file actions
123 lines (106 loc) · 3.28 KB
/
client.lua
File metadata and controls
123 lines (106 loc) · 3.28 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
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
QBCore = exports[Config.Core]:GetCoreObject()
local PlayerJob = {}
local Enabled = false
CreateThread(function()
Wait(10)
while not QBCore.Functions.GetPlayerData().job do
Wait(10)
end
PlayerJob = QBCore.Functions.GetPlayerData().job
TriggerServerEvent("fl-dispatch:server:refresh")
end)
RegisterNetEvent('QBCore:Client:OnPlayerLoaded')
AddEventHandler('QBCore:Client:OnPlayerLoaded', function()
PlayerJob = QBCore.Functions.GetPlayerData().job
TriggerServerEvent("fl-dispatch:server:refresh")
end)
RegisterNetEvent('QBCore:Client:OnJobUpdate')
AddEventHandler('QBCore:Client:OnJobUpdate', function(jobInfo)
PlayerJob = jobInfo
if Enabled and not IsJobAllowed(PlayerJob.name) then
SendNUIMessage({ action = "close" })
end
TriggerServerEvent("fl-dispatch:server:refresh")
end)
RegisterNetEvent("fl-dispatch:client:open")
AddEventHandler("fl-dispatch:client:open", function(type)
if type == 'toggle' then
if Enabled then
Enabled = false
SendNUIMessage({ action = 'close' })
else
Enabled = true
SendNUIMessage({ action = 'open' })
end
elseif type == 'drag' then
SetNuiFocus(true, true)
SendNUIMessage({ action = 'drag' })
elseif type == 'force_exit' then
Enabled = false
SendNUIMessage({ action = 'close' })
end
end)
RegisterNUICallback("Close", function()
SetNuiFocus(false, false)
end)
RegisterNetEvent("fl-dispatch:client:refresh")
AddEventHandler("fl-dispatch:client:refresh", function(data)
local id = GetPlayerServerId(PlayerId())
local filteredData = {}
for _, jobData in pairs(data) do
if jobData.job == PlayerJob.name then
for i, v in ipairs(jobData.players) do
if v.src == id then
jobData.players[i].me = true
end
end
table.insert(filteredData, jobData)
end
end
SendNUIMessage({
action = 'refresh',
data = filteredData
})
end)
RegisterNetEvent('fl-dispatch:client:removePlayer')
AddEventHandler('fl-dispatch:client:removePlayer', function(src)
SendNUIMessage({
action = "removePlayer",
data = {
src = src,
},
})
TriggerServerEvent("fl-dispatch:server:refresh")
end)
RegisterNetEvent("fl-dispatch:client:setTalkingOnRadio")
AddEventHandler("fl-dispatch:client:setTalkingOnRadio", function(src, talking)
SendNUIMessage({
action = "setTalkingOnRadio",
data = {
src = src,
talking = talking
},
})
end)
RegisterNetEvent("fl-dispatch:client:setPlayerRadio")
AddEventHandler("fl-dispatch:client:setPlayerRadio", function(src, channel)
SendNUIMessage({
action = "setPlayerRadio",
data = {
src = src,
channel = channel
},
})
end)
RegisterCommand("+dispatch", function()
TriggerServerEvent('fl-dispatch:server:open', GetPlayerServerId(PlayerId()), {})
end, false)
RegisterKeyMapping('+dispatch', 'Opens Job Dispatch List', Config.ToggleKey['group'], Config.ToggleKey['key'])
function IsJobAllowed(job)
for _, allowedJob in ipairs(Config.Jobs) do
if allowedJob == job then
return true
end
end
return false
end