Created
June 13, 2017 10:20
-
-
Save AMD-NICK/e6563709e4f9e28ebc7160e015373c33 to your computer and use it in GitHub Desktop.
это. просто. пиздец. 2015 год. Мой первый большой Lua скрипт, который я тогда писал много часов
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[********************************************************** | |
Конфигурационная зона | |
**************************************************************]] | |
local CanEnterCmd = {"governor", "admin", "superadmin", "minister"} -- Таблица, содержащая названия групп, которые могут вводить команду | |
local WarnTime = 10 --60 * 5 -- Время, через которое будет проводиться напоминание игрокам о рестарте | |
--[[********************************************************** | |
Оповещание "вводителя" команды | |
**************************************************************]] | |
local function report(activator, num, time, message) | |
if activator:IsPlayer() then | |
return DarkRP.notify(activator, num, time, message) | |
else | |
-- если команда вводилась через консоль | |
return print(message) | |
end -- если активировал команду игрок | |
end | |
--[[********************************************************** | |
Подбор слова для отображения времени до рестарта | |
**************************************************************]] | |
local function MinOrSec(time) | |
if time < 60 then | |
return " сек." | |
else | |
return " мин." | |
end | |
end | |
--[[********************************************************** | |
Команда запуска планового рестарта | |
**************************************************************]] | |
concommand.Add("planned_restart", function(activator, cmd, time) | |
local SixHun, ThreeHun, OneHunEig, OneHunTw, Sixty, Thirty, Twenty, Ten = false | |
if timer.Exists("TRIGON:planned_restart") then | |
report(activator, 1, 10, "Один рестарт уже запланирован") | |
return | |
end | |
if time[1] then | |
-- Если человек введет буквы вместо цифр, то вылезет ошибка | |
if tonumber(time[1]) == nil then | |
report(activator, 1, 10, "Нужно вводить целое число. Пример: planned_restart 30") | |
return | |
end | |
-- Если время до рестарта установлено на меньше минуты, то сделать минуту | |
if tonumber(time[1]) < 1 then | |
time[1] = 1 | |
end | |
local TimeLeft = time[1] * 60 - WarnTime -- оставшееся до рестарта время. Меняющаяся переменная | |
local ArgInSeconds = time[1] * 60 -- превращаем минутный аргумент в секунды | |
-- Если время напоминаний меньше минуты, то установить минуту | |
--if WarnTime < 60 then WarnTime = 60 end | |
local function preparing() | |
DarkRP.notifyAll(0, 30, "ВНИМАНИЕ. Через " .. time[1] .. " мин. произойдет рестарт сервера") | |
DarkRP.notifyAll(0, 30, "Если быстро перезайдете - пропы и профа сохранятся") | |
report(activator, 1, 10, "ВНИМАНИЕ. Через " .. time[1] .. " мин. произойдет рестарт сервера") | |
timer.Create("TRIGON:planned_restart", ArgInSeconds, 0, function() | |
--BroadcastLua("LocalPlayer():ConCommand(\"disconnect; snd_restart; retry\")") | |
--BroadcastLua("LocalPlayer():ConCommand(\"money_back\")") | |
RunConsoleCommand("ulx", "maprestart") | |
end) | |
--DarkRP.notifyAll(1, 10, "Серв рестартнулся, вас типа отключило") | |
-- конец таймера до рестарта | |
timer.Create("TRIGON:planned_restart_warn", WarnTime, 0, function() | |
DarkRP.notifyAll(0, 5, "До рестарта осталось " .. string.ToMinutesSeconds(TimeLeft) .. MinOrSec(TimeLeft)) | |
if not activator:IsPlayer() then | |
print("До рестарта осталось " .. string.ToMinutesSeconds(TimeLeft) .. MinOrSec(TimeLeft)) | |
end | |
TimeLeft = TimeLeft - WarnTime | |
if tonumber(time[1]) >= 10 and TimeLeft + 10 <= 600 and not SixHun then | |
BroadcastLua("surface.PlaySound(\"trigon-im/restart/600sec.wav\")") | |
SixHun = true | |
elseif tonumber(time[1]) >= 5 and TimeLeft + 10 <= 300 and not ThreeHun then | |
BroadcastLua("surface.PlaySound(\"trigon-im/restart/300sec.wav\")") | |
ThreeHun = true | |
elseif tonumber(time[1]) >= 3 and TimeLeft + 10 <= 180 and not OneHunEig then | |
BroadcastLua("surface.PlaySound(\"trigon-im/restart/180sec.wav\")") | |
OneHunEig = true | |
elseif tonumber(time[1]) >= 2 and TimeLeft + 10 <= 120 and not OneHunTw then | |
BroadcastLua("surface.PlaySound(\"trigon-im/restart/120sec.wav\")") | |
OneHunTw = true | |
elseif tonumber(time[1]) >= 1 and TimeLeft + 10 <= 60 and not Sixty then | |
BroadcastLua("surface.PlaySound(\"trigon-im/restart/60sec.wav\")") | |
Sixty = true | |
elseif tonumber(time[1]) >= 1 and TimeLeft + 10 <= 30 and not Thirty then | |
BroadcastLua("surface.PlaySound(\"trigon-im/restart/30sec.wav\")") | |
Thirty = true | |
elseif tonumber(time[1]) >= 1 and TimeLeft + 10 <= 20 and not Twenty then | |
BroadcastLua("surface.PlaySound(\"trigon-im/restart/20sec.wav\")") | |
Twenty = true | |
elseif tonumber(time[1]) >= 1 and TimeLeft + 10 <= 10 and not Ten then | |
BroadcastLua("surface.PlaySound(\"trigon-im/restart/10sec.wav\")") | |
Ten = true | |
end | |
-- конец проверок для выбора воспроизведения конкретного звука | |
if TimeLeft < 0 then | |
timer.Remove("TRIGON:planned_restart_warn") | |
timer.Remove("TRIGON:planned_restart") | |
end -- не обязательно. Просто при тестировании было полезным | |
end) | |
end | |
-- конец если времени не осталось | |
-- конец таймера звуковых предупреждений | |
-- конец функции оповещаний о рестартах | |
if not activator:IsPlayer() then | |
preparing() | |
elseif table.HasValue(CanEnterCmd, activator:GetUserGroup()) then | |
preparing() | |
else | |
report(activator, 1, 10, "У вас недостаточно прав для использования этой команды") -- если игрок не админ | |
end | |
else | |
report(activator, 1, 10, "Введите время в минутах до рестарта. Пример: planned_restart 30") -- если не указать аргумент | |
end -- если указано время | |
end) -- принимает в качестве аргумента время до рестарта | |
--[[********************************************************** | |
Команда остановки планового рестарта | |
**************************************************************]] | |
concommand.Add("planned_restart_stop", function(activator) | |
if activator:IsPlayer() and timer.Exists("TRIGON:planned_restart") then | |
if table.HasValue(CanEnterCmd, activator:GetUserGroup()) then | |
timer.Remove("TRIGON:planned_restart") | |
timer.Remove("TRIGON:planned_restart_warn") | |
DarkRP.notifyAll(1, 30, activator:Nick() .. " отменил рестарт сервера") | |
else | |
report(activator, 1, 5, "У вас недостаточно прав для использования этой команды") | |
end | |
elseif not activator:IsPlayer() and timer.Exists("TRIGON:planned_restart") then | |
timer.Remove("TRIGON:planned_restart") | |
timer.Remove("TRIGON:planned_restart_warn") | |
DarkRP.notifyAll(1, 30, "CONSOLE отменила рестарт сервера") | |
print("CONSOLE отменила рестарт сервера") | |
else | |
report(activator, 1, 5, "Рестарт не запланирован") | |
end | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment