-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathserver.lua
297 lines (274 loc) · 10.2 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
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
--------------------
--- Badssentials ---
--------------------
RegisterNetEvent("Badssentials:AOPChange")
--@desc Sends a message to the client
--@param src The player you want to send the message to
--@param msg The message to send
function sendMsg(src, msg)
TriggerClientEvent('chat:addMessage', src, {args = {Config.Prefix .. msg} });
end
--@desc Checks if a passed ID is an online player
--@param playerID The ID you want to check.
function IsPlayerOnline(playerID)
local playerFound = false
for _, ID in pairs(GetPlayers()) do
if tonumber(ID) == tonumber(playerID) then
playerFound = true
end
end
if playerFound then
return true
else
return false
end
end
-- @desc Check if value is an integer
-- @param number the variable you want to check
function IsInt(number)
if number == tostring(tonumber(number)) then
return true
else
return false
end
end
function GetAOP()
return currentAOP
end
function GetPeaceTimeStatus()
return peacetime
end
--Makes sure resource name is 'Badssentials' so any scripts using exports won't throw errors.
if GetCurrentResourceName() ~= "Badssentials" then
print("[" .. GetCurrentResourceName() .. "] ^3WARNING: This resource needs to be named '^0Badssentials^3' in order for everything to function correctly! Please change this resource's name back to '^0Badssentials^3'!")
end
RegisterCommand(Config.ScreenAffects.AnnounceCommand, function(source, args, raw)
local src = source;
if IsPlayerAceAllowed(src, Config.ScreenAffects.AcePermission) then
-- Allowed to use /announce
if #args > 0 then
local ann = table.concat(args, " ");
TriggerClientEvent('Badssentials:Announce', -1, ann);
end
end
end)
Citizen.CreateThread(function()
while true do
Wait(1000);
TriggerClientEvent('Badssentials:SetAOP', -1, currentAOP);
TriggerClientEvent('Badssentials:SetPT', -1, peacetime);
local time = format_time(os.time(), "%H:%M");
local date = format_time(os.time(), "%m %d %Y");
local timeHour = split(time, ":")[1]
local dateData = split(date, " ");
TriggerClientEvent('Badssentials:SetMonth', -1, dateData[1])
TriggerClientEvent('Badssentials:SetDay', -1, dateData[2])
TriggerClientEvent('Badssentials:SetYear', -1, dateData[3])
if tonumber(timeHour) > 12 then
local timeStr = tostring(tonumber(timeHour) - 12) .. ":" .. split(time, ":")[2]
TriggerClientEvent('Badssentials:SetTime', -1, timeStr);
end
if timeHour == "00" then
local timeStr = "12" .. ":" .. split(time, ":")[2]
TriggerClientEvent('Badssentials:SetTime', -1, timeStr);
end
if timeHour ~= "00" and tonumber(timeHour) <= 12 then
TriggerClientEvent('Badssentials:SetTime', -1, time);
end
end
end)
peacetime = false;
currentAOP = Config.AOPSystem.DefaultAOP; -- By default
RegisterCommand(Config.AOPSystem.AOPCommand, function(source, args, rawCommand)
local src = source;
if IsPlayerAceAllowed(src, Config.AOPSystem.AOP_AcePermission) then
-- Allowed to use /aop <aop>
if #args > 0 then
local oldAOP = currentAOP
currentAOP = table.concat(args, " ");
sendMsg(src, "You have set the AOP to: " .. currentAOP);
TriggerClientEvent('Badssentials:SetAOP', -1, currentAOP);
if Config.AOPSystem.aopAnnouncement ~= nil then
local aopAnnouncement = Config.AOPSystem.AOP_Announcement
aopAnnouncement = aopAnnouncement:gsub("{NEW_AOP}", currentAOP)
sendMsg(-1, aopAnnouncement)
end
TriggerEvent("Badssentials:AOPChange", oldAOP, currentAOP, src)
else
-- Not enough arguments
sendMsg(src, "^1ERROR: Proper usage: /" .. Config.AOPSystem.AOPCommand .. " <zone>");
end
else
sendMsg(src, "^1ERROR: You do not have permission to change the AOP!");
end
end)
timersRev = {}
timersRes = {}
Citizen.CreateThread(function()
while true do
Wait((1000)); -- Each second
for src, timer in pairs(timersRev) do
timersRev[src] = timer - 1;
if (timersRev[src] <= 0) then
timersRev[src] = nil;
end
end
for src, timer in pairs(timersRes) do
timersRes[src] = timer - 1;
if (timersRes[src] <= 0) then
timersRes[src] = nil;
end
end
end
end)
if Config.ReviveSystem.enable then
RegisterNetEvent("Badssentials:DeathTrigger")
AddEventHandler("Badssentials:DeathTrigger", function()
local src = source;
timersRev[src] = Config.ReviveSystem.Revive_Delay;
timersRes[src] = Config.ReviveSystem.Respawn_Delay;
end)
RegisterCommand(Config.ReviveSystem.ReviveCommand, function(source, args, rawCommand)
local src = source;
if #args == 0 or tonumber(args[1]) == src then
-- Revive themselves
if timersRev[src] ~= nil and timersRev[src] >= 0 then
-- They are dead and have a timer
if IsPlayerAceAllowed(src, Config.ReviveSystem.BypassReviveAcePermission) then
-- Can bypass reviving
TriggerClientEvent('Badssentials:RevivePlayer', src);
else
-- Cannot bypass reviving, send they need to wait and what their timer is at
local timeLeft = timersRev[src]
if timeLeft >= 60 then
timeLeft = math.ceil(timeLeft / 60) .. " minute(s)"
else
timeLeft = timeLeft .. " seconds"
end
local errorMessage = Config.ReviveSystem.ReviveErrorMessage
errorMessage = errorMessage:gsub("{REVIVE_TIME_LEFT}", timeLeft)
sendMsg(src, errorMessage);
end
else
-- Their timer is expired or not valid
TriggerClientEvent('Badssentials:RevivePlayer', src);
end
else
-- They are reviving someone else
if IsPlayerAceAllowed(src, Config.ReviveSystem.ReviveOthersAcePermission) then
--Checks if arg is number
if IsInt(args[1]) then
--checks if a player with ID is online
if IsPlayerOnline(args[1]) then
local reviveMessage = Config.ReviveSystem.ReviveOthersMessage
reviveMessage = reviveMessage:gsub("{PLAYER_NAME}", GetPlayerName(src))
TriggerClientEvent('Badssentials:RevivePlayer', tonumber(args[1]));
sendMsg(src, "You have revived player ^5" .. GetPlayerName(tonumber(args[1])) .. " ^3successfully!");
sendMsg(tonumber(args[1]), reviveMessage);
else
--Player isn't online
sendMsg(src, "^1ERROR: No player with that specified ID is online!");
end
else
--Passed Arg is not integer
sendMsg(src, "^1ERROR: You must specify a valid server ID!");
end
else
sendMsg(src, '^1ERROR: You do not have permission to revive others!');
end
end
end)
RegisterCommand(Config.ReviveSystem.RespawnCommand, function(source, args, rawCommand)
local src = source;
if #args == 0 then
-- Respawn themselves
if timersRes[src] ~= nil and timersRes[src] >= 0 then
-- They are dead and have a timer
if IsPlayerAceAllowed(src, Config.ReviveSystem.BypassRespawnAcePermission) then
-- Can bypass reviving
TriggerClientEvent('Badssentials:RespawnPlayer', src);
else
-- Cannot bypass reviving, send they need to wait and what their timer is at
local timeLeft = timersRes[src]
if timeLeft >= 60 then
timeLeft = math.ceil(timeLeft / 60) .. " minute(s)"
else
timeLeft = timeLeft .. " seconds"
end
local errorMessage = Config.ReviveSystem.RespawnErrorMessage
errorMessage = errorMessage:gsub("{RESPAWN_TIME_LEFT}", timeLeft)
sendMsg(src, errorMessage);
end
else
-- Their timer is expired or not valid
TriggerClientEvent('Badssentials:RespawnPlayer', src);
end
end
end)
end
RegisterCommand(Config.Misc.Peacetime, function(source, args, rawCommand)
local src = source;
if IsPlayerAceAllowed(src, Config.Misc.PeacetimeAcePermission) then
peacetime = not peacetime;
TriggerClientEvent('Badssentials:SetPT', -1, peacetime);
if peacetime then
sendMsg(src, "You have set PeaceTime to ^2ON");
else
sendMsg(src, "You have set PeaceTime to ^1OFF");
end
end
end)
RegisterCommand(Config.Misc.PT, function(source, args, rawCommand)
local src = source;
if IsPlayerAceAllowed(src, Config.Misc.PeacetimeAcePermission) then
peacetime = not peacetime;
TriggerClientEvent('Badssentials:SetPT', -1, peacetime);
if peacetime then
sendMsg(src, "You have set PeaceTime to ^2ON");
else
sendMsg(src, "You have set PeaceTime to ^1OFF");
end
end
end)
function split(source, sep)
local result, i = {}, 1
while true do
local a, b = source:find(sep)
if not a then break end
local candidat = source:sub(1, a - 1)
if candidat ~= "" then
result[i] = candidat
end i=i+1
source = source:sub(b + 1)
end
if source ~= "" then
result[i] = source
end
return result
end
function format_time(timestamp, format, tzoffset, tzname)
if tzoffset == "local" then -- calculate local time zone (for the server)
local now = os.time()
local local_t = os.date("*t", now)
local utc_t = os.date("!*t", now)
local delta = (local_t.hour - utc_t.hour)*60 + (local_t.min - utc_t.min)
local h, m = math.modf( delta / 60)
tzoffset = string.format("%+.4d", 100 * h + 60 * m)
end
tzoffset = tzoffset or "GMT"
format = format:gsub("%%z", tzname or tzoffset)
if tzoffset == "GMT" then
tzoffset = "+0000"
end
tzoffset = tzoffset:gsub(":", "")
local sign = 1
if tzoffset:sub(1,1) == "-" then
sign = -1
tzoffset = tzoffset:sub(2)
elseif tzoffset:sub(1,1) == "+" then
tzoffset = tzoffset:sub(2)
end
tzoffset = sign * (tonumber(tzoffset:sub(1,2))*60 +
tonumber(tzoffset:sub(3,4)))*60
return os.date(format, timestamp + tzoffset)
end