Загрузка данных
script_author('MLycoris')
local imgui = require 'mimgui'
local ffi = require 'ffi'
local encoding = require 'encoding'
encoding.default = 'CP1251'
local u8 = encoding.UTF8
local new, str = imgui.new, ffi.string
local ev = require 'lib.samp.events'
ffi.cdef 'void __stdcall ExitProcess(unsigned int)'
-- == Config == --
local inicfg = require 'inicfg'
local settings = inicfg.load({
shit = {
whenDoIt = 0, -- когда
whatDoIt = 0, -- что
hour = 0,
min = 0,
sec = 0,
}}, 'OFFme.ini')
-- inicfg.save(settings, 'OFFme.ini')
-- == Table == --
local whenDo = {u8'Через время', u8'В опред. время', u8'После ПейДея', u8'После опред. сообщения в чат', u8'При потере соединения с сервером',u8'При опред. игроке в зоне стрима'}
local whatDo = {u8'Выключить ПК', u8'Выйти из игры', u8'Крашнуть игру', u8'Написать в чат (видно всем)', u8'Уведомление в чат (видно только вам)', u8'Перезайти на сервер'}
-- == Settings == --
local script_state, repeat_state, time_settings, repeat_settings, text_settings, go_off = false, false, false, false, false, false
-- == Buffers == --
local WinState = new.bool()
local buf = {
hourTimer = new.int(settings.shit.hour),
minTimer = new.int(settings.shit.min),
secTimer = new.int(settings.shit.sec),
hourCD = new.int(0),
minCD = new.int(0),
secCD = new.int(0),
text = new.char[512](),
findText = new.char[512](),
}
imgui.OnFrame(function() return WinState[0] end,
function(player)
imgui.SetNextWindowPos(imgui.ImVec2(500,500), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
imgui.SetNextWindowSize(imgui.ImVec2(500, 500), imgui.Cond.FirstUseEver)
imgui.Begin('##Window', WinState, imgui.WindowFlags.NoDecoration)
imgui.SetWindowSizeVec2(imgui.ImVec2(499, ((repeat_settings or text_settings or time_settings) and 467 or (not repeat_settings and (not text_settings or not time_settings)) and 278)))
imgui.SetCursorPosX(imgui.GetWindowWidth()/2-17) imgui.CenterText('OFFme') imgui.SameLine()
imgui.SetCursorPosX(imgui.GetWindowWidth()-20) if imgui.Button('##CloseButton', imgui.ImVec2(15, 15)) then WinState[0] = false end imgui.Separator()
repeat_settings = settings.shit.whatDoIt > 3 and settings.shit.whatDoIt < 6 and true or false
time_settings = settings.shit.whenDoIt <= 2 and settings.shit.whenDoIt > 0 and true or false
text_settings = (settings.shit.whenDoIt == 4 or settings.shit.whenDoIt == 6) and true or false
if imgui.BeginChild('##When', imgui.ImVec2(242, 214), true) then
imgui.PushFont(bold) imgui.SetCursorPosX(95)
imgui.CenterText('Когда')
imgui.PopFont() imgui.Separator()
for i = 1, 6 do
if imgui.ColoredButton(whenDo[i],'F94242',(i==settings.shit.whenDoIt and 70 or 20), imgui.ImVec2(230, 24)) then
if settings.shit.whenDoIt ~= i then
settings.shit.whenDoIt = i
else
settings.shit.whenDoIt = 0
end
inicfg.save(settings, 'OFFme.ini')
end
end
imgui.EndChild()
end imgui.SameLine()
if imgui.BeginChild('##What', imgui.ImVec2(242, 214), true) then
imgui.PushFont(bold) imgui.SetCursorPosX(70)
imgui.CenterText('Что сделать')
imgui.PopFont() imgui.Separator()
for i = 1, 6 do
if imgui.ColoredButton(whatDo[i],'F94242',(i==settings.shit.whatDoIt and 70 or 20), imgui.ImVec2(230, 24)) then
if settings.shit.whatDoIt ~= i then
settings.shit.whatDoIt = i
else
settings.shit.whatDoIt = 0
end
inicfg.save(settings, 'OFFme.ini')
end
end
imgui.EndChild()
end
if time_settings then
if imgui.BeginChild('##Timer', imgui.ImVec2(242, 185), true) then
imgui.PushFont(bold) imgui.SetCursorPosX(43)
imgui.Text(u8'Настройки времени')
imgui.PopFont() imgui.Separator()
imgui.SliderInt(u8'Часы', buf.hourTimer, 0, 23)
imgui.SliderInt(u8'Минуты', buf.minTimer, 0, 59)
imgui.SliderInt(u8'Секунды', buf.secTimer, 0, 59)
if imgui.Button(u8'Сохранить', imgui.ImVec2(230, 24)) then
settings.shit.hour = buf.hourTimer[0]
settings.shit.min = buf.minTimer[0]
settings.shit.sec = buf.secTimer[0]
inicfg.save(settings, 'OFFme.ini')
end
if imgui.Button(u8'Сброс времени', imgui.ImVec2(230, 24)) then
buf.hourTimer[0] = 0
buf.minTimer[0] = 0
buf.secTimer[0] = 0
settings.shit.hour = 0
settings.shit.min = 0
settings.shit.sec = 0
inicfg.save(settings, 'OFFme.ini')
end
imgui.EndChild()
end imgui.SameLine()
elseif text_settings then
if imgui.BeginChild('##findText', imgui.ImVec2(242, 185), true) then
imgui.PushFont(bold) imgui.SetCursorPosX(43)
imgui.CenterText(settings.shit.whenDoIt == 6 and 'Введите ник' or 'Введите сообщение')
imgui.PopFont() imgui.Separator()
imgui.PushItemWidth(233)
imgui.InputText('##textt', buf.findText, 512)
imgui.PopItemWidth()
imgui.Button(u8'Сохранить', imgui.ImVec2(233, 24)) -- дада кнопка пустышка ахвхаха
imgui.Separator()
imgui.TextWrapped(settings.shit.whenDoIt == 6 and u8'Введите ник формата:\nNick_Name' or u8'Функция чувствительна к регистру\n\nВ случае большого текста, рекомендуется применять регулярки')
imgui.EndChild()
end imgui.SameLine()
end
if repeat_settings then imgui.SetCursorPos(imgui.ImVec2(252, 249))
if imgui.BeginChild('##CD', imgui.ImVec2(242, 185), true) then
imgui.PushFont(bold) imgui.SetCursorPosX(45)
imgui.Text(u8'Настройки режима')
imgui.PopFont() imgui.Separator()
imgui.SetCursorPosX(88) imgui.Text(u8'Введите текст') imgui.Separator()
imgui.PushItemWidth(180)
imgui.InputText('##texttt', buf.text, 512)
imgui.PopItemWidth() imgui.SameLine()
if imgui.ColoredButton(u8'Повтор',(repeat_state and '32CD32' or 'F94242'),50, imgui.ImVec2(45, 24)) then
repeat_state = not repeat_state
end imgui.Separator()
if repeat_state then
imgui.SliderInt(u8'Часы', buf.hourCD, 0, 23)
imgui.SliderInt(u8'Минуты', buf.minCD, 0, 59)
imgui.SliderInt(u8'Секунды', buf.secCD, 0, 59)
else imgui.TextWrapped(u8'\nПоддерживаются команды других скриптов') end
imgui.EndChild()
end
end
if (not text_settings and not time_settings) or not repeat_settings then
local tX = (not text_settings and not time_settings) and 95 or not repeat_settings and 340
local tY = (not text_settings and not time_settings) and 310 or not repeat_settings and 310
imgui.PushFont(bold) imgui.SetCursorPos(imgui.ImVec2(tX,tY))
imgui.Text(u8'OFFme by\nMLycoris')
imgui.PopFont()
end imgui.SetCursorPos(imgui.ImVec2(6, (not repeat_settings and not text_settings and not time_settings) and 249 or 438))
if imgui.ColoredButton(script_state and u8'Включено' or u8'Выключено', (script_state and '32CD32' or 'F94242'), 50, imgui.ImVec2(488, 24)) then
script_state = not script_state
end
imgui.End()
end
)
function main()
while not isSampAvailable() do wait(100) end
sampRegisterChatCommand('offme', function() WinState[0] = not WinState[0] end)
while true do wait(0)
if script_state then
if settings.shit.whenDoIt == 1 then
wait(buf.hourTimer[0]*3600000)
wait(buf.minTimer[0]*60000)
wait(buf.secTimer[0]*1000)
go_off = true
elseif settings.shit.whenDoIt == 2 then
if os.date('%H:%M:%S') == string.format("%02d", buf.hourTimer[0])..':'..string.format("%02d", buf.minTimer[0])..':'..string.format("%02d", buf.secTimer[0]) then
go_off = true
end
elseif settings.shit.whenDoIt == 3 then
if os.date('%M') == '01' then
go_off = true
end
end
if not script_state then
sampAddChatMessage('{FF634F}[{ffffff}OFFme{FF634F}] {ffffff}Активация {FF634F}отменена',-1)
go_off = false
end
end
if go_off then
if settings.shit.whatDoIt == 1 then -- откл пк
os.execute('shutdown /s /t 5')
elseif settings.shit.whatDoIt == 2 then -- выйти из игры
ffi.C.ExitProcess(0)
elseif settings.shit.whatDoIt == 3 then -- краш жопы
deleteChar(1)
elseif settings.shit.whatDoIt == 4 then -- сообщ в чат
sampProcessChatInput(u8:decode(str(buf.text)))
elseif settings.shit.whatDoIt == 5 then -- увед в чат
sampAddChatMessage(u8:decode(str(buf.text)),-1)
elseif settings.shit.whatDoIt == 6 then -- перезаход
local ip, port = sampGetCurrentServerAddress()
wait(1000)
sampConnectToServer(ip,port)
end
go_off = false
script_state = false
if repeat_state then
wait(buf.hourCD[0]*3600000)
wait(buf.minCD[0]*60000)
wait(buf.secCD[0]*1000)
go_off = true
end
end
end
end
function ev.onPlayerStreamIn(playerId)
if settings.shit.whenDoIt == 6 and script_state then
if sampGetPlayerNickname(playerId) == u8:decode(str(buf.findText)) then
go_off = true
end
end
end
function ev.onServerMessage(color, text)
if script_state and settings.shit.whenDoIt == 4 and text:find(u8:decode(str(buf.findText))) then go_off = true end
end
function onReceivePacket(id)
if id == 32 and settings.shit.whenDoIt == 5 and script_state then
go_off = true
end
end
-- == Other shit == --
function imgui.CenterText(text)
imgui.SetCursorPosX(imgui.GetWindowWidth()/2-imgui.CalcTextSize(u8(text)).x/2)
imgui.Text(u8(text))
end
function imgui.ColoredButton(text,hex,trans,size)
local r,g,b = tonumber("0x"..hex:sub(1,2)), tonumber("0x"..hex:sub(3,4)), tonumber("0x"..hex:sub(5,6))
if tonumber(trans) ~= nil and tonumber(trans) < 101 and tonumber(trans) > 0 then
a = trans
else a = 60 end
imgui.PushStyleColor(imgui.Col.Button, imgui.ImVec4(r/255, g/255, b/255, a/100))
imgui.PushStyleColor(imgui.Col.ButtonHovered, imgui.ImVec4(r/255, g/255, b/255, a/100))
imgui.PushStyleColor(imgui.Col.ButtonActive, imgui.ImVec4(r/255, g/255, b/255, a/100))
local button = imgui.Button(text, size)
imgui.PopStyleColor(3)
return button
end
-- == Theme == --
imgui.OnInitialize(function()
local glyph_ranges = imgui.GetIO().Fonts:GetGlyphRangesCyrillic()
bold = imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14)..'\\impact.ttf', 24, _, glyph_ranges)
theme()
end)
function theme()
imgui.SwitchContext()
local ImVec4 = imgui.ImVec4
imgui.GetStyle().WindowPadding = imgui.ImVec2(5, 5)
imgui.GetStyle().FramePadding = imgui.ImVec2(1, 5)
imgui.GetStyle().ItemSpacing = imgui.ImVec2(5, 5)
imgui.GetStyle().ItemInnerSpacing = imgui.ImVec2(5, 2)
imgui.GetStyle().TouchExtraPadding = imgui.ImVec2(0, 0)
imgui.GetStyle().IndentSpacing = 0
imgui.GetStyle().ScrollbarSize = 10
imgui.GetStyle().GrabMinSize = 10
imgui.GetStyle().WindowBorderSize = 1
imgui.GetStyle().ChildBorderSize = 1
imgui.GetStyle().PopupBorderSize = 1
imgui.GetStyle().FrameBorderSize = 1
imgui.GetStyle().TabBorderSize = 1
imgui.GetStyle().WindowRounding = 8
imgui.GetStyle().ChildRounding = 8
imgui.GetStyle().FrameRounding = 8
imgui.GetStyle().PopupRounding = 8
imgui.GetStyle().ScrollbarRounding = 8
imgui.GetStyle().GrabRounding = 8
imgui.GetStyle().TabRounding = 8
imgui.GetStyle().Colors[imgui.Col.Text] = ImVec4(1.00, 1.00, 1.00, 1.00)
imgui.GetStyle().Colors[imgui.Col.TextDisabled] = ImVec4(0.50, 0.50, 0.50, 1.00)
imgui.GetStyle().Colors[imgui.Col.WindowBg] = ImVec4(0.06, 0.06, 0.06, 0.94)
imgui.GetStyle().Colors[imgui.Col.ChildBg] = ImVec4(1.00, 1.00, 1.00, 0.00)
imgui.GetStyle().Colors[imgui.Col.PopupBg] = ImVec4(0.08, 0.08, 0.08, 0.94)
imgui.GetStyle().Colors[imgui.Col.Border] = ImVec4(0.43, 0.43, 0.50, 0.50)
imgui.GetStyle().Colors[imgui.Col.BorderShadow] = ImVec4(0.00, 0.00, 0.00, 0.00)
imgui.GetStyle().Colors[imgui.Col.FrameBg] = ImVec4(0.48, 0.16, 0.16, 0.54)
imgui.GetStyle().Colors[imgui.Col.FrameBgHovered] = ImVec4(0.98, 0.26, 0.26, 0.40)
imgui.GetStyle().Colors[imgui.Col.FrameBgActive] = ImVec4(0.98, 0.26, 0.26, 0.67)
imgui.GetStyle().Colors[imgui.Col.TitleBg] = ImVec4(0.04, 0.04, 0.04, 1.00)
imgui.GetStyle().Colors[imgui.Col.TitleBgActive] = ImVec4(0.48, 0.16, 0.16, 1.00)
imgui.GetStyle().Colors[imgui.Col.TitleBgCollapsed] = ImVec4(0.00, 0.00, 0.00, 0.51)
imgui.GetStyle().Colors[imgui.Col.MenuBarBg] = ImVec4(0.14, 0.14, 0.14, 1.00)
imgui.GetStyle().Colors[imgui.Col.ScrollbarBg] = ImVec4(0.02, 0.02, 0.02, 0.53)
imgui.GetStyle().Colors[imgui.Col.ScrollbarGrab] = ImVec4(0.31, 0.31, 0.31, 1.00)
imgui.GetStyle().Colors[imgui.Col.ScrollbarGrabHovered] = ImVec4(0.41, 0.41, 0.41, 1.00)
imgui.GetStyle().Colors[imgui.Col.ScrollbarGrabActive] = ImVec4(0.51, 0.51, 0.51, 1.00)
imgui.GetStyle().Colors[imgui.Col.CheckMark] = ImVec4(0.98, 0.26, 0.26, 1.00)
imgui.GetStyle().Colors[imgui.Col.SliderGrab] = ImVec4(0.88, 0.26, 0.24, 1.00)
imgui.GetStyle().Colors[imgui.Col.SliderGrabActive] = ImVec4(0.98, 0.26, 0.26, 1.00)
imgui.GetStyle().Colors[imgui.Col.Button] = ImVec4(0.98, 0.26, 0.26, 0.40)
imgui.GetStyle().Colors[imgui.Col.ButtonHovered] = ImVec4(0.98, 0.26, 0.26, 1.00)
imgui.GetStyle().Colors[imgui.Col.ButtonActive] = ImVec4(0.98, 0.06, 0.06, 1.00)
imgui.GetStyle().Colors[imgui.Col.Header] = ImVec4(0.98, 0.26, 0.26, 0.31)
imgui.GetStyle().Colors[imgui.Col.HeaderHovered] = ImVec4(0.98, 0.26, 0.26, 0.80)
imgui.GetStyle().Colors[imgui.Col.HeaderActive] = ImVec4(0.98, 0.26, 0.26, 1.00)
imgui.GetStyle().Colors[imgui.Col.Separator] = ImVec4(0.43, 0.43, 0.50, 0.50)
imgui.GetStyle().Colors[imgui.Col.SeparatorHovered] = ImVec4(0.75, 0.10, 0.10, 0.78)
imgui.GetStyle().Colors[imgui.Col.SeparatorActive] = ImVec4(0.75, 0.10, 0.10, 1.00)
imgui.GetStyle().Colors[imgui.Col.ResizeGrip] = ImVec4(0.98, 0.26, 0.26, 0.25)
imgui.GetStyle().Colors[imgui.Col.ResizeGripHovered] = ImVec4(0.98, 0.26, 0.26, 0.67)
imgui.GetStyle().Colors[imgui.Col.ResizeGripActive] = ImVec4(0.98, 0.26, 0.26, 0.95)
imgui.GetStyle().Colors[imgui.Col.Tab] = ImVec4(0.98, 0.26, 0.26, 0.40)
imgui.GetStyle().Colors[imgui.Col.TabHovered] = ImVec4(0.98, 0.26, 0.26, 1.00)
imgui.GetStyle().Colors[imgui.Col.TabActive] = ImVec4(0.98, 0.06, 0.06, 1.00)
imgui.GetStyle().Colors[imgui.Col.TabUnfocused] = ImVec4(0.98, 0.26, 0.26, 1.00)
imgui.GetStyle().Colors[imgui.Col.TabUnfocusedActive] = ImVec4(0.98, 0.26, 0.26, 1.00)
imgui.GetStyle().Colors[imgui.Col.PlotLines] = ImVec4(0.61, 0.61, 0.61, 1.00)
imgui.GetStyle().Colors[imgui.Col.PlotLinesHovered] = ImVec4(1.00, 0.43, 0.35, 1.00)
imgui.GetStyle().Colors[imgui.Col.PlotHistogram] = ImVec4(0.90, 0.70, 0.00, 1.00)
imgui.GetStyle().Colors[imgui.Col.PlotHistogramHovered] = ImVec4(1.00, 0.60, 0.00, 1.00)
imgui.GetStyle().Colors[imgui.Col.TextSelectedBg] = ImVec4(0.98, 0.26, 0.26, 0.35)
end