-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.lua
197 lines (168 loc) · 7.25 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
if Config.Framework:match('QBCore') then -- QBCore Framework
QBCore = exports['qb-core']:GetCoreObject()
end
local isBlackout, blackoutInProgress, setBlackoutTimeout = false, false, false
RegisterServerEvent('msk_blackout:notifyJobs')
AddEventHandler('msk_blackout:notifyJobs', function()
if not Config.notifyJobs.enable then return end
if Config.Framework:match('ESX') then
local xPlayers = ESX.GetExtendedPlayers()
for k, xPlayer in pairs(xPlayers) do
if MSK.Table_Contains(Config.notifyJobs.jobs, xPlayer.job.name) then
Config.Notification(xPlayer.source, Translation[Config.Locale]['job_notify_blackout_started'])
TriggerClientEvent('msk_blackout:sendJobBlipNotify', xPlayer.source)
end
end
elseif Config.Framework:match('QBCore') then
local Players = QBCore.Functions.GetQBPlayers()
for k, Player in pairs(Players) do
if MSK.Table_Contains(Config.notifyJobs.jobs, Player.PlayerData.job.name) then
Config.Notification(Player.PlayerData.source, Translation[Config.Locale]['job_notify_blackout_started'])
TriggerClientEvent('msk_blackout:sendJobBlipNotify', Player.PlayerData.source)
end
end
end
end)
RegisterServerEvent('msk_blackout:syncBlackout')
AddEventHandler('msk_blackout:syncBlackout', function(state)
logging('debug', 'syncBlackout', state)
if Config.useWeatherScript then
Config.weatherScript(state)
end
TriggerClientEvent('msk_blackout:setBlackout', -1, state)
if state then -- If Blackout is enabled
TriggerEvent('msk_blackout:powerOff')
blackoutInProgress = true
local blackoutTimeout = MSK.AddTimeout(Config.Timeout * 60000, function()
blackoutInProgress = false
end)
else -- If Blackout is disabled
TriggerEvent('msk_blackout:powerOn')
end
if not Config.useDoorlock then return end
if not Config.DoorlockScript then return end
if not (GetResourceState(Config.DoorlockScript) == "started") then
return logging('error', ('Doorlock Script ^3%s^0 not found'):format(Config.DoorlockScript))
end
if state then -- If Blackout is enabled
if Config.DoorlockScript:match('doors_creator') then
local doors = exports["doors_creator"]:getAllDoors()
for k, doorData in pairs(doors) do
exports["doors_creator"]:setDoorState(doorData.id, 0)
end
elseif Config.DoorlockScript:match('ox_doorlock') then
MySQL.query('SELECT id FROM ox_doorlock', {}, function(result)
if result then
for i = 1, #result do
local door = exports.ox_doorlock:getDoor(result[i].id)
TriggerEvent('ox_doorlock:setState', door.id, 0)
end
end
end)
else
logging('error', ('Unsupported doorlock script: ^3%s^0'):format(Config.DoorlockScript))
end
else -- If Blackout is disabled
if Config.DoorlockScript:match('doors_creator') then
local doors = exports["doors_creator"]:getAllDoors()
for k, doorData in pairs(doors) do
exports["doors_creator"]:setDoorState(doorData.id, 1)
end
elseif Config.DoorlockScript:match('ox_doorlock') then
MySQL.query('SELECT id FROM ox_doorlock', {}, function(result)
if result then
for i = 1, #result do
local door = exports.ox_doorlock:getDoor(result[i].id)
TriggerEvent('ox_doorlock:setState', door.id, 1)
end
end
end)
else
logging('error', ('Unsupported doorlock script: ^3%s^0'):format(Config.DoorlockScript))
end
end
end)
RegisterServerEvent('msk_blackout:removeItem')
AddEventHandler('msk_blackout:removeItem', function(item)
if not Config.removeItem then return end
local src = source
if Config.Framework:match('ESX') then
local xPlayer = ESX.GetPlayerFromId(src)
xPlayer.removeInventoryItem(item, 1)
elseif Config.Framework:match('QBCore') then
local Player = QBCore.Functions.GetPlayer(src)
Player.Functions.RemoveItem(item, 1)
end
end)
MSK.Register('msk_blackout:getCops', function(source)
local OnlineCops = 0
if Config.Framework:match('ESX') then
local xPlayers = ESX.GetExtendedPlayers()
for k, xPlayer in pairs(xPlayers) do
if MSK.TableContains(Config.Cops.jobs, xPlayer.job.name) then
OnlineCops = OnlineCops + 1
end
end
elseif Config.Framework:match('QBCore') then
local Players = QBCore.Functions.GetQBPlayers()
for k, Player in pairs(Players) do
if MSK.TableContains(Config.Cops.jobs, Player.PlayerData.job.name) then
OnlineCops = OnlineCops + 1
end
end
end
return OnlineCops
end)
MSK.Register('msk_blackout:isBlackoutInProgress', function(source)
return blackoutInProgress
end)
if Config.Command.enable then
MSK.RegisterCommand(Config.Command.command, Config.Command.groups, function(source, args, raw)
if isBlackout then
TriggerEvent('msk_blackout:syncBlackout', false)
else
TriggerEvent('msk_blackout:syncBlackout', true)
end
end, true, false, {help = 'Toggle Blackout'})
end
AddEventHandler('msk_blackout:powerOn', function()
logging('debug', 'Toggled Blackout off')
isBlackout = false
MSK.DelTimeout(setBlackoutTimeout)
end)
AddEventHandler('msk_blackout:powerOff', function()
logging('debug', 'Toggled Blackout on')
isBlackout = true
setBlackoutTimeout = MSK.AddTimeout(Config.Blackout.duration * 60000, function()
isBlackout = false
TriggerEvent('msk_blackout:syncBlackout', false)
end)
end)
logging = function(code, ...)
if not Config.Debug then return end
MSK.Logging(code, ...)
end
GithubUpdater = function()
GetCurrentVersion = function()
return GetResourceMetadata( GetCurrentResourceName(), "version" )
end
local CurrentVersion = GetCurrentVersion()
local resourceName = "^0[^2"..GetCurrentResourceName().."^0]"
if Config.VersionChecker then
PerformHttpRequest('https://raw.githubusercontent.com/MSK-Scripts/msk_blackout/main/VERSION', function(Error, NewestVersion, Header)
print("###############################")
if CurrentVersion == NewestVersion then
print(resourceName .. '^2 ✓ Resource is Up to Date^0 - ^5Current Version: ^2' .. CurrentVersion .. '^0')
elseif CurrentVersion ~= NewestVersion then
print(resourceName .. '^1 ✗ Resource Outdated. Please Update!^0 - ^5Current Version: ^1' .. CurrentVersion .. '^0')
print('^5Newest Version: ^2' .. NewestVersion .. '^0 - ^6Download here:^9 https://github.com/MSK-Scripts/msk_blackout/releases/tag/v'.. NewestVersion .. '^0')
end
print("###############################")
end)
else
print("###############################")
print(resourceName .. '^2 ✓ Resource loaded^0')
print("###############################")
end
end
GithubUpdater()