-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathserver.lua
199 lines (196 loc) · 7.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
-- CONFIG --
roleList = Config.RoleList;
-- CODE --
Citizen.CreateThread(function()
while true do
-- We wait a second and add it to their timeTracker
Wait(1000); -- Wait a second
for k, v in pairs(timeTracker) do
timeTracker[k] = timeTracker[k] + 1;
end
end
end)
timeTracker = {}
hasPerms = {}
permTracker = {}
activeBlip = {}
onDuty = {}
prefix = '^9[^5Badger-Blips^9] ^3';
AddEventHandler("playerDropped", function()
if onDuty[source] ~= nil then
local tag = activeBlip[source];
local webHook = roleList[activeBlip[source]][3];
if webHook ~= nil then
local time = timeTracker[source];
local now = os.time();
local startPlusNow = now + time;
local minutesActive = os.difftime(now, startPlusNow) / 60;
minutesActive = math.floor(math.abs(minutesActive))
sendToDisc('Player ' .. GetPlayerName(source) .. ' is now off duty', 'Player ' .. GetPlayerName(source) .. ' has gone off duty as ' .. tag,
'Duration: ' .. minutesActive .. ' minutes',
webHook, 16711680)
end
end
timeTracker[source] = nil;
onDuty[source] = nil;
permTracker[source] = nil;
hasPerms[source] = nil;
activeBlip[source] = nil;
-- Remove them from Blips:
TriggerEvent('eblips:remove', source)
end)
function sendToDisc(title, message, footer, webhookURL, color)
local embed = {}
embed = {
{
["color"] = color, -- GREEN = 65280 --- RED = 16711680
["title"] = "**".. title .."**",
["description"] = "** " .. message .. " **",
["footer"] = {
["text"] = footer,
},
}
}
-- Start
-- TODO Input Webhook
PerformHttpRequest(webhookURL,
function(err, text, headers) end, 'POST', json.encode({username = name, embeds = embed}), { ['Content-Type'] = 'application/json' })
-- END
end
RegisterCommand('duty', function(source, args, rawCommand)
-- The /blip command to toggle on and off the cop blip
if hasPerms[source] ~= nil then
if onDuty[source] == nil then
local colorr = roleList[activeBlip[source]][2];
local tag = activeBlip[source];
local webHook = roleList[activeBlip[source]][3];
if webHook ~= nil then
sendToDisc('Player ' .. GetPlayerName(source) .. ' is now on duty', 'Player ' .. GetPlayerName(source) .. ' has gone on duty as ' .. tag, '',
webHook, 65280)
end
TriggerEvent('eblips:add', {name = tag .. GetPlayerName(source), src = source, color = colorr});
sendMsg(source, 'You have toggled your emergency blip ^2ON ^3and your Blip-Tag is: ' .. tag)
onDuty[source] = true;
timeTracker[source] = 0;
TriggerClientEvent('PoliceEMSActivity:GiveWeapons', source);
else
onDuty[source] = nil;
local tag = activeBlip[source];
local webHook = roleList[activeBlip[source]][3];
if webHook ~= nil then
local time = timeTracker[source];
local now = os.time();
local startPlusNow = now + time;
local minutesActive = os.difftime(now, startPlusNow) / 60;
minutesActive = math.floor(math.abs(minutesActive))
sendToDisc('Player ' .. GetPlayerName(source) .. ' is now off duty', 'Player ' .. GetPlayerName(source) .. ' has gone off duty as ' .. tag,
'Duration: ' .. minutesActive .. ' minutes',
webHook, 16711680)
end
TriggerClientEvent('PoliceEMSActivity:TakeWeapons', source);
timeTracker[source] = nil;
sendMsg(source, 'You have toggled your emergency blip ^1OFF')
TriggerEvent('eblips:remove', source)
end
else
-- You are not a cop, you must be a cop in our discord to use it
sendMsg(source, '^1ERROR: You must be an LEO on our discord to use this...')
end
end)
RegisterCommand('cops', function(source, args, rawCommand)
-- Prints the active cops online with a /blip that is on
sendMsg(source, 'The active cops on are:')
for id, _ in pairs(onDuty) do
TriggerClientEvent('chatMessage', source, '^9[^4' .. id .. '^9] ^0' .. GetPlayerName(id));
end
end)
function sendMsg(src, msg)
TriggerClientEvent('chatMessage', src, prefix .. msg);
end
RegisterCommand('bliptag', function(source, args, rawCommand)
-- The /blipTag command to toggle on and off the cop blip
if hasPerms[source] ~= nil then
if #args == 0 then
-- List out which ones they have access to
sendMsg(source, 'You have access to the following Blip-Tags:');
for i = 1, #permTracker[source] do
-- List
TriggerClientEvent('chatMessage', source, '^9[^4' .. i .. '^9] ^0' .. permTracker[source][i]);
end
else
-- Choose their bliptag
local selection = args[1];
if tonumber(selection) ~= nil then
local sel = tonumber(selection);
local theirBlips = permTracker[source];
if sel <= #theirBlips then
-- Set up their tag
local tag = activeBlip[source];
local webHook = roleList[activeBlip[source]][3];
if onDuty[source] ~= nil then
local time = timeTracker[source];
local now = os.time();
local startPlusNow = now + time;
local minutesActive = os.difftime(now, startPlusNow) / (60);
minutesActive = math.floor(math.abs(minutesActive))
sendToDisc('Player ' .. GetPlayerName(source) .. ' is now off duty', 'Player ' .. GetPlayerName(source)
.. ' has gone off duty as ' .. tag, 'Duration: ' .. minutesActive,
webHook, 16711680)
timeTracker[source] = 0;
end
activeBlip[source] = permTracker[source][sel];
sendMsg(source, 'You have set your Blip-Tag to ^1' .. permTracker[source][sel]);
if onDuty[source] ~= nil then
tag = activeBlip[source];
webHook = roleList[activeBlip[source]][3];
sendToDisc('Player ' .. GetPlayerName(source) .. ' is now on duty', 'Player ' .. GetPlayerName(source) .. ' has gone on duty as ' .. tag, '',
webHook, 65280)
local colorr = roleList[activeBlip[source]][2]
TriggerEvent('eblips:remove', source)
TriggerEvent('eblips:add', {name = tag .. GetPlayerName(source), src = source, color = colorr});
end
else
-- That is not a valid selection
sendMsg(source, '^1ERROR: That is not a valid selection...')
end
else
-- Not a number
sendMsg(source, '^1ERROR: That is not a number...')
end
end
else
-- You are not a cop, you must be a cop in our discord to use this
sendMsg(source, '^1ERROR: You must be an LEO on our discord to use this...')
end
end)
RegisterNetEvent('PoliceEMSActivity:RegisterUser')
AddEventHandler('PoliceEMSActivity:RegisterUser', function()
local src = source
for k, v in ipairs(GetPlayerIdentifiers(src)) do
if string.sub(v, 1, string.len("discord:")) == "discord:" then
identifierDiscord = v
end
end
local perms = {}
if identifierDiscord then
local roleIDs = exports.Badger_Discord_API:GetDiscordRoles(src)
if not (roleIDs == false) then
for k, v in pairs(roleList) do
for j = 1, #roleIDs do
if exports.Badger_Discord_API:CheckEqual(v[1], roleIDs[j]) then
table.insert(perms, k);
activeBlip[src] = k;
hasPerms[src] = true;
print("[PEA] Gave Perms Sucessfully")
end
end
end
permTracker[src] = perms;
else
print("[PoliceEMSActivity] " .. GetPlayerName(src) .. " has not gotten their permissions cause roleIDs == false")
end
else
print("[PoliceEMSActivity] " .. GetPlayerName(src) .. " has not gotten their permissions cause discord was not detected...")
end
permTracker[src] = perms;
end)