local se = require 'lib.samp.events'
local imgui = require 'imgui'
local inicfg = require 'inicfg'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local cfg = inicfg.load({
settings = {
auto_start = false,
open_inventory = false,
connected = false
}
}, 'sawnoff_auto_collector')
if not doesFileExist('sawnoff_auto_collector.ini') then
inicfg.save(cfg, 'sawnoff_auto_collector.ini')
end
local sw, sh = getScreenResolution()
local main_window = imgui.ImBool(false)
local work = false
local inventory_fix = false
local inventory_id = nil
local first_start = true
local delay_time = nil
local sawnoff = {_, _, _, false, false}
local auto_start = imgui.ImBool(cfg.settings.auto_start)
local connected = cfg.settings.connected
local open_inventory = imgui.ImBool(cfg.settings.open_inventory)
local timer = imgui.ImBool(false)
local timer_time = imgui.ImBuffer(tostring(''), 4)
function main()
if not isSampLoaded() or not isSampfuncsLoaded() then return end
while not isSampAvailable() do wait(100) end
sampRegisterChatCommand('sawnoff',
function()
main_window.v = not main_window.v
imgui.Process = main_window.v
end)
while true do
wait(0)
if work then
if first_start and timer.v then
wait(timer_time.v*60000)
timer_time.v = ''
end
if first_start then
sampSendClickTextdraw(65535)
sampAddChatMessage('[Информация] {FFFFFF}Сейчас откроется инвентарь.', 0xFFFF00)
elseif not first_start and not open_inventory.v then
sampSendClickTextdraw(65535)
sampAddChatMessage('[Информация] {FFFFFF}Сейчас откроется инвентарь.', 0xFFFF00)
end
wait(500)
inventory_fix = true
sampSendChat('/donate')
wait(1000)
if first_start then
sampSendChat('/invent')
elseif not first_start and not open_inventory.v then
sampSendChat('/invent')
elseif not first_start and open_inventory.v and not sampTextdrawIsExists(inventory_id) then
sampSendChat('/invent')
end
repeat wait(1) until sampTextdrawIsExists(inventory_id)
wait(500)
if sawnoff[1] ~= nil then
if not sampTextdrawIsExists(inventory_id) then
repeat
sampSendChat('/invent')
wait(1000)
until sampTextdrawIsExists(inventory_id)
end
sawnoff[5] = true
repeat
sampSendClickTextdraw(sawnoff[1])
repeat wait(1) until sampTextdrawIsExists(sawnoff[2]) or sampTextdrawIsExists(sawnoff[3])
wait(500)
if sawnoff[4] == false then
sampSendClickTextdraw(sawnoff[2])
wait(1000)
sampSendClickTextdraw(sawnoff[1])
repeat wait(1) until sampTextdrawIsExists(sawnoff[2]) or sampTextdrawIsExists(sawnoff[3])
wait(500)
end
sampSendClickTextdraw(sawnoff[3])
wait(500)
until sawnoff[5] == false
else
sampSendClickTextdraw(65535)
showCursor(false)
thisScript():reload()
sampAddChatMessage('[Информация] {FFFFFF}«Обрез (активный аксессуар)» не найден.', 0xFFFF00)
sampAddChatMessage('[Информация] {FFFFFF}Автоматический сбор обреза: {FF0000}выключен{FFFFFF}.', 0xFFFF00)
end
wait(500)
if not open_inventory.v then
sampSendClickTextdraw(65535)
end
if delay_time ~= nil then
wait(delay_time*60000+60000)
delay_time = nil
else
wait(61*60000)
end
first_start = false
end
end
end
function imgui.OnDrawFrame()
if not main_window.v then imgui.Process = false end
if main_window.v then
imgui.SetNextWindowPos(imgui.ImVec2(sw/2, sh/2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
imgui.SetNextWindowSize(imgui.ImVec2(218, 204), imgui.Cond.FirstUseEver)
imgui.Begin(u8'Автоматический сбор обреза', main_window, imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoResize)
imgui.BeginChild('##main', imgui.ImVec2(202, 168), true)
imgui.CenterText(u8'Настройки')
imgui.Separator()
imgui.Checkbox(u8'Запуск при подключении', auto_start)
if auto_start.v then
cfg.settings.auto_start = true
inicfg.save(cfg, 'sawnoff_auto_collector.ini')
else
cfg.settings.auto_start = false
inicfg.save(cfg, 'sawnoff_auto_collector.ini')
end
imgui.Checkbox(u8'Не закрывать инвентарь', open_inventory)
if open_inventory.v then
cfg.settings.open_inventory = true
inicfg.save(cfg, 'sawnoff_auto_collector.ini')
else
cfg.settings.open_inventory = false
inicfg.save(cfg, 'sawnoff_auto_collector.ini')
end
imgui.Checkbox(u8'Запустить через:', timer)
imgui.SameLine()
imgui.PushItemWidth(26)
imgui.InputText(u8'мин.##timer', timer_time, imgui.InputTextFlags.CharsDecimal)
if timer_time.v ~= '' then
timer.v = true
else
timer.v = false
end
imgui.PopItemWidth()
imgui.Separator()
if work then
imgui.PushStyleColor(imgui.Col.Button, imgui.ImVec4(0.13, 0.13, 0.13, 1.00))
imgui.PushStyleColor(imgui.Col.ButtonHovered, imgui.ImVec4(0.66, 0.00, 0.00, 1.00))
imgui.PushStyleColor(imgui.Col.ButtonActive, imgui.ImVec4(0.50, 0.00, 0.00, 1.00))
else
imgui.PushStyleColor(imgui.Col.Button, imgui.ImVec4(0.13, 0.13, 0.13, 1.00))
imgui.PushStyleColor(imgui.Col.ButtonHovered, imgui.ImVec4(0.00, 0.66, 0.00, 1.00))
imgui.PushStyleColor(imgui.Col.ButtonActive, imgui.ImVec4(0.00, 0.50, 0.00, 1.00))
end
if imgui.Button(work and u8'Выключить' or u8'Включить', imgui.ImVec2(186, 30)) then
if not work then
if cfg.settings.connected and sampGetGamestate() == 3 and sampIsLocalPlayerSpawned() then
work = true
showCursor(false)
main_window.v = false
if timer.v and timer_time.v ~= '' then
sampAddChatMessage('[Информация] {FFFFFF}Автоматический сбор обреза: {00FF00}включен{FFFFFF}.', 0xFFFF00)
sampAddChatMessage('[Информация] {FFFFFF}Запуск через {FFFF00}'..timer_time.v..' {FFFFFF}мин.', 0xFFFF00)
else
sampAddChatMessage('[Информация] {FFFFFF}Автоматический сбор обреза: {00FF00}включен{FFFFFF}.', 0xFFFF00)
end
else
sampAddChatMessage('[Информация] {FFFFFF}Вы не подключены к серверу.', 0xFFFF00)
end
else
sampSendClickTextdraw(65535)
showCursor(false)
thisScript():reload()
sampAddChatMessage('[Информация] {FFFFFF}Автоматический сбор обреза: {FF0000}выключен{FFFFFF}.', 0xFFFF00)
end
end
imgui.PopStyleColor(3)
imgui.Separator()
if imgui.Link(u8'Автор скрипта: Severus') then
os.execute(('explorer.exe "%s"'):format('https://www.blast.hk/members/490500/'))
end
imgui.EndChild()
imgui.End()
end
end
function se.onShowTextDraw(id, data)
if data.text == 'INVENTORY' or data.text == '…H‹EHЏAP’' and data.letterColor == -1 and data.style == 2 then
inventory_id = id
end
if work then
if data.modelId == 350 and data.rotation.x == -20 and data.rotation.y == 0 and data.rotation.z == 75 and data.backgroundColor == -13469276 then
sawnoff[1] = id
end
if data.modelId == 350 and data.rotation.x == -20 and data.rotation.y == 0 and data.rotation.z == 75 and data.backgroundColor == -13149076 then
sawnoff[1] = id
end
if data.text == 'PUT' or data.text == 'HAѓEЏ’' then
sawnoff[4] = false
sawnoff[2] = id + 1
end
if data.text == 'USE' or data.text == '…CЊO‡’€O‹AЏ’' then
sawnoff[4] = true
sawnoff[3] = id + 1
end
end
end
function se.onShowDialog(dialogId, style, title, b1, b2, text)
if inventory_fix and text:find('Курс пополнения счета') then
sampSendDialogResponse(dialogId, 0, nil, nil)
inventory_fix = false
return false
end
end
function se.onServerMessage(color, text)
if work and sawnoff[5] then
if text:find('Для использования этого аксессуара должно пройти ещё (.+) минут!') then
delay_time = text:match('Для использования этого аксессуара должно пройти ещё (.+) минут!')
sawnoff[5] = false
end
end
end
function se.onApplyPlayerAnimation(playerId, animLib, animName, frameDelta, loop, lockX, lockY, freeze, time)
if work and sawnoff[5] then
local _, id = sampGetPlayerIdByCharHandle(playerPed)
if playerId == id and animLib == 'BOMBER' then
sawnoff[5] = false
end
end
end
function onReceivePacket(id)
if id == 31 or id == 32 or id == 33 or id == 35 or id == 36 or id == 37 then
cfg.settings.connected = false
inicfg.save(cfg, 'sawnoff_auto_collector.ini')
if work then work = false end
elseif id == 34 then
cfg.settings.connected = true
inicfg.save(cfg, 'sawnoff_auto_collector.ini')
if auto_start.v then
lua_thread.create(function()
repeat wait(12000) until sampIsLocalPlayerSpawned() and sampGetGamestate() == 3
if cfg.settings.connected ~= false then
if not work then
work = true
sampAddChatMessage('[Информация] {FFFFFF}Автоматический сбор обреза: {00FF00}включен{FFFFFF}.', 0xFFFF00)
end
end
end)
end
end
end
function onQuitGame()
cfg.settings.connected = false
inicfg.save(cfg, 'sawnoff_auto_collector.ini')
end
function imgui.CenterText(text)
local width = imgui.GetWindowWidth()
local size = imgui.CalcTextSize(text)
imgui.SetCursorPosX(width/2-size.x/2)
imgui.Text(text)
end
function imgui.Link(label, description)
local width = imgui.GetWindowWidth()
local size = imgui.CalcTextSize(label)
local p = imgui.GetCursorScreenPos()
local p2 = imgui.GetCursorPos()
local result = imgui.InvisibleButton(label, imgui.ImVec2(width-16, size.y))
imgui.SetCursorPos(p2)
imgui.SetCursorPosX(width/2-size.x/2)
if imgui.IsItemHovered() then
if description then
imgui.BeginTooltip()
imgui.PushTextWrapPos(500)
imgui.TextUnformatted(description)
imgui.PopTextWrapPos()
imgui.EndTooltip()
end
imgui.TextColored(imgui.GetStyle().Colors[imgui.Col.CheckMark], label)
imgui.GetWindowDrawList():AddLine(imgui.ImVec2(width/2-size.x/2+p.x-8, p.y + size.y), imgui.ImVec2(width/2-size.x/2+p.x-8 + size.x, p.y + size.y), imgui.GetColorU32(imgui.GetStyle().Colors[imgui.Col.CheckMark]))
else
imgui.TextColored(imgui.GetStyle().Colors[imgui.Col.CheckMark], label)
end
return result
end
function theme()
imgui.SwitchContext()
local style = imgui.GetStyle()
local colors = style.Colors
local clr = imgui.Col
local ImVec4 = imgui.ImVec4
local ImVec2 = imgui.ImVec2
style.WindowPadding = ImVec2(8, 8)
style.WindowRounding = 5.0
style.ChildWindowRounding = 5.0
style.FramePadding = ImVec2(2, 2)
style.FrameRounding = 5.0
style.ItemSpacing = ImVec2(5, 5)
style.ItemInnerSpacing = ImVec2(5, 5)
style.TouchExtraPadding = ImVec2(0, 0)
style.IndentSpacing = 5.0
style.ScrollbarSize = 13.0
style.ScrollbarRounding = 5.0
style.GrabMinSize = 20.0
style.GrabRounding = 5.0
style.WindowTitleAlign = ImVec2(0.5, 0.5)
colors[clr.Text] = ImVec4(1.00, 1.00, 1.00, 1.00)
colors[clr.TextDisabled] = ImVec4(0.20, 0.20, 0.20, 1.00)
colors[clr.WindowBg] = ImVec4(0.05, 0.05, 0.05, 1.00)
colors[clr.ChildWindowBg] = ImVec4(0.05, 0.05, 0.05, 1.00)
colors[clr.PopupBg] = ImVec4(0.05, 0.05, 0.05, 1.00)
colors[clr.Border] = ImVec4(1.00, 1.00, 1.00, 1.00)
colors[clr.BorderShadow] = ImVec4(0.05, 0.05, 0.05, 1.00)
colors[clr.FrameBg] = ImVec4(0.13, 0.13, 0.13, 1.00)
colors[clr.FrameBgHovered] = ImVec4(0.20, 0.20, 0.20, 1.00)
colors[clr.FrameBgActive] = ImVec4(0.13, 0.13, 0.13, 1.00)
colors[clr.TitleBg] = ImVec4(0.13, 0.13, 0.13, 1.00)
colors[clr.TitleBgCollapsed] = ImVec4(0.13, 0.13, 0.13, 1.00)
colors[clr.TitleBgActive] = ImVec4(0.13, 0.13, 0.13, 1.00)
colors[clr.MenuBarBg] = ImVec4(0.13, 0.13, 0.13, 1.00)
colors[clr.ScrollbarBg] = ImVec4(0.05, 0.05, 0.05, 1.00)
colors[clr.ScrollbarGrab] = ImVec4(0.13, 0.13, 0.13, 1.00)
colors[clr.ScrollbarGrabHovered] = ImVec4(0.20, 0.20, 0.20, 1.00)
colors[clr.ScrollbarGrabActive] = ImVec4(0.13, 0.13, 0.13, 1.00)
colors[clr.ComboBg] = ImVec4(0.13, 0.13, 0.13, 1.00)
colors[clr.CheckMark] = ImVec4(1.00, 1.00, 1.00, 1.00)
colors[clr.SliderGrab] = ImVec4(1.00, 1.00, 1.00, 1.00)
colors[clr.SliderGrabActive] = ImVec4(1.00, 1.00, 1.00, 1.00)
colors[clr.Button] = ImVec4(0.13, 0.13, 0.13, 1.00)
colors[clr.ButtonHovered] = ImVec4(0.20, 0.20, 0.20, 1.00)
colors[clr.ButtonActive] = ImVec4(0.13, 0.13, 0.13, 1.00)
colors[clr.Header] = ImVec4(0.13, 0.13, 0.13, 1.00)
colors[clr.HeaderHovered] = ImVec4(0.20, 0.20, 0.20, 1.00)
colors[clr.HeaderActive] = ImVec4(0.13, 0.13, 0.13, 1.00)
colors[clr.ResizeGrip] = ImVec4(0.13, 0.13, 0.13, 1.00)
colors[clr.ResizeGripHovered] = ImVec4(0.20, 0.20, 0.20, 1.00)
colors[clr.ResizeGripActive] = ImVec4(0.13, 0.13, 0.13, 1.00)
colors[clr.CloseButton] = ImVec4(0.05, 0.05, 0.05, 1.00)
colors[clr.CloseButtonHovered] = ImVec4(0.05, 0.05, 0.05, 1.00)
colors[clr.CloseButtonActive] = ImVec4(0.05, 0.05, 0.05, 1.00)
colors[clr.PlotLines] = ImVec4(0.13, 0.13, 0.13, 1.00)
colors[clr.PlotLinesHovered] = ImVec4(0.20, 0.20, 0.20, 1.00)
colors[clr.PlotHistogram] = ImVec4(0.13, 0.13, 0.13, 1.00)
colors[clr.PlotHistogramHovered] = ImVec4(0.20, 0.20, 0.20, 1.00)
colors[clr.TextSelectedBg] = ImVec4(0.05, 0.05, 0.05, 1.00)
colors[clr.ModalWindowDarkening] = ImVec4(1.00, 1.00, 1.00, 1.00)
end
theme()