Помощь с исправлением кода

kereewka

Участник
Автор темы
66
19
Версия MoonLoader
.026-beta
1734811454261.png

Можете в коде исправить ограничение символов в строчке /vr до 100 символов?
banani:
script_version('1.4.2');
script_author('https://vk.com/id620137656');

local sampev = require('lib.samp.events')
local imgui = require('mimgui');
local encoding = require('encoding');
encoding.default = 'CP1251'
u8 = encoding.UTF8
local inicfg = require('inicfg');
local ffi = require('ffi');
local keys = require('vkeys');

local directIni = 'AutoAdByDiscq192.ini'
local lastSendKeyMessage = os.time()
local stateLastSendKeyMessage = false

local ini = inicfg.load(inicfg.load({
    main = {
        enabled = false,
        vrAdvertisementSend = true,
        inactiveShutdown = false,
        sleepInactiveShutdown = 1
    },
    delays = {
        s = 30,
        j = 30,
        vr = 30,
        fb = 30,
        f = 30,
        fam = 30,
        rb = 30,
        al = 30,
        jb = 30,
        ad = 30,
    },
    toggle = {
        s = false,
        j = false,
        vr = false,
        fb = false,
        f = false,
        fam = false,
        rb = false,
        al = false,
        jb = false,
        ad = false,
    },
    ad = {
        type = 1,
        centr = 1
    },
    input = {
        s = "",
        j = "",
        vr = "",
        fb = "",
        f = "",
        fam = "",
        rb = "",
        al = "",
        jb = "",
        ad = "",
    },
    lastSend = {
        s = 0,
        j = 0,
        vr = 0,
        fb = 0,
        f = 0,
        fam = 0,
        rb = 0,
        al = 0,
        jb = 0,
        ad = 0,
    }
}, directIni))
inicfg.save(ini, directIni)

local SaveCfg = function()
    inicfg.save(ini, directIni)
end


local vrAdvertisementSend = imgui.new.bool(ini.main.vrAdvertisementSend)
local inactiveShutdown = imgui.new.bool(ini.main.inactiveShutdown)
local sleepInactiveShutdown = imgui.new.int(tonumber(ini.main.sleepInactiveShutdown))
local toggleScript = imgui.new.bool(ini.main.enabled)
local delays = {
    ["s"] = imgui.new.int(ini.delays.s),
    ["j"] = imgui.new.int(ini.delays.j),
    ["vr"] = imgui.new.int(ini.delays.vr),
    ["fb"] = imgui.new.int(ini.delays.fb),
    ["f"] = imgui.new.int(ini.delays.f),
    ["fam"] = imgui.new.int(ini.delays.fam),
    ["rb"] = imgui.new.int(ini.delays.rb),
    ["al"] = imgui.new.int(ini.delays.al),
    ["jb"] = imgui.new.int(ini.delays.jb),
    ["ad"] = imgui.new.int(ini.delays.ad)
}

local toggle = {
    ["s"] = imgui.new.bool(ini.toggle.s),
    ["j"] = imgui.new.bool(ini.toggle.j),
    ["vr"] = imgui.new.bool(ini.toggle.vr),
    ["fb"] = imgui.new.bool(ini.toggle.fb),
    ["f"] = imgui.new.bool(ini.toggle.f),
    ["fam"] = imgui.new.bool(ini.toggle.fam),
    ["rb"] = imgui.new.bool(ini.toggle.rb),
    ["al"] = imgui.new.bool(ini.toggle.al),
    ["jb"] = imgui.new.bool(ini.toggle.jb),
    ["ad"] = imgui.new.bool(ini.toggle.ad)
}

local ad = {
    ["type"] = imgui.new.int(ini.ad.type),
    ["centr"] = imgui.new.int(ini.ad.centr),
}


local input = {
    ["s"] = imgui.new.char[256](tostring(ini.input.s)),
    ["j"] = imgui.new.char[256](tostring(ini.input.j)),
    ["vr"] = imgui.new.char[256](tostring(ini.input.vr)),
    ["fb"] = imgui.new.char[256](tostring(ini.input.fb)),
    ["f"] = imgui.new.char[256](tostring(ini.input.f)),
    ["fam"] = imgui.new.char[256](tostring(ini.input.fam)),
    ["rb"] = imgui.new.char[256](tostring(ini.input.rb)),
    ["al"] = imgui.new.char[256](tostring(ini.input.al)),
    ["jb"] = imgui.new.char[256](tostring(ini.input.jb)),
    ["ad"] = imgui.new.char[256](tostring(ini.input.ad))
}

local item_listTypeCombo = {u8('Обычное'), u8('VIP'), u8('Реклама бизнеса')}
local ImItemsTypeCombo = imgui.new['const char*'][#item_listTypeCombo](item_listTypeCombo)

local item_listCentrCombo = {u8('Автоматически'), u8('SF'), u8('LV'), u8('LS')}
local ImItemsCentrCombo = imgui.new['const char*'][#item_listCentrCombo](item_listCentrCombo)

local vrSended = false
local advSended = {
    ["state"] = false,
    ["msg"] = ""
}

local ui_meta = {
    __index = function(self, v)
        if v == "switch" then
            local switch = function()
                if self.process and self.process:status() ~= "dead" then
                    return false -- // Предыдущая анимация ещё не завершилась!
                end
                self.timer = os.clock()
                self.state = not self.state

                self.process = lua_thread.create(function()
                    local bringFloatTo = function(from, to, start_time, duration)
                        local timer = os.clock() - start_time
                        if timer >= 0.00 and timer <= duration then
                            local count = timer / (duration / 100)
                            return count * ((to - from) / 100)
                        end
                        return (timer > duration) and to or from
                    end

                    while true do wait(0)
                        local a = bringFloatTo(0.00, 1.00, self.timer, self.duration)
                        self.alpha = self.state and a or 1.00 - a
                        if a == 1.00 then break end
                    end
                end)
                return true -- // Состояние окна изменено!
            end
            return switch
        end
 
        if v == "alpha" then
            return self.state and 1.00 or 0.00
        end
    end
}

local menu = { state = false, duration = 0.5 }
setmetatable(menu, ui_meta)


imgui.OnInitialize(function()
    imgui.GetIO().IniFilename = nil
    theme()
end)

imgui.OnFrame(
    function() return menu.alpha > 0.00 end,
    function(player)
        local resX, resY = getScreenResolution()
        local sizeX, sizeY = 500, 400
        imgui.SetNextWindowPos(imgui.ImVec2(resX / 2, resY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(sizeX, sizeY), imgui.Cond.FirstUseEver)
        player.HideCursor = not menu.state
        imgui.PushStyleVarFloat(imgui.StyleVar.Alpha, menu.alpha)
        if imgui.Begin('AutoAdByDiscq192 | ' .. thisScript().version, _, imgui.WindowFlags.NoResize) then
           
            imgui.PushItemWidth(175)
            if imgui.InputText("###inputS", input["s"], 99) then ini.input.s = ffi.string(input["s"]) ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.SameLine()
            if imgui.ToggleButton("/s###OnOrDisableS", toggle["s"]) then ini.lastSend["s"] = 0 ini.toggle.s = toggle["s"][0] SaveCfg() end
            imgui.SameLine()
            imgui.SetCursorPos(imgui.ImVec2(imgui.GetCursorPos().x + 16, imgui.GetCursorPos().y))
            imgui.PushItemWidth(234)
            if imgui.SliderInt("###Slider1", delays["s"], 1, 660, u8'%d cек') then ini.delays.s = delays["s"][0] SaveCfg() end

            imgui.PushItemWidth(175)
            if imgui.InputText("###inputJ", input["j"], 177) then ini.input.j = ffi.string(input["j"]) ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.SameLine()
            if imgui.ToggleButton("/j###OnOrDisableJ", toggle["j"]) then ini.lastSend["j"] = 0 ini.toggle.j = toggle["j"][0] SaveCfg() end
            imgui.SameLine()
            imgui.SetCursorPos(imgui.ImVec2(imgui.GetCursorPos().x + 16, imgui.GetCursorPos().y))
            imgui.PushItemWidth(234)
            if imgui.SliderInt("###Slider2", delays["j"], 1, 660, u8'%d cек') then ini.delays.j = delays["j"][0] SaveCfg() end
           
            imgui.PushItemWidth(175)
            if imgui.InputText("###inputVr", input["vr"], 105) then ini.input.vr = ffi.string(input["vr"]) print(ini.input.vr) print(ffi.string(input["vr"])) ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.SameLine()
            if imgui.ToggleButton("/vr###OnOrDisableVR", toggle["vr"]) then ini.lastSend["vr"] = 0 ini.toggle.vr = toggle["vr"][0] SaveCfg() end
            imgui.SameLine()
            imgui.SetCursorPos(imgui.ImVec2(imgui.GetCursorPos().x + 9, imgui.GetCursorPos().y))
            imgui.PushItemWidth(234)
            if imgui.SliderInt("###Slider3", delays["vr"], 1, 660, u8'%d cек') then ini.delays.vr = delays["vr"][0] SaveCfg() end
           
            imgui.PushItemWidth(175)
            if imgui.InputText("###inputFb", input["fb"], 90) then ini.input.fb = ffi.string(input["fb"]) ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.SameLine()
            if imgui.ToggleButton("/fb###OnOrDisableFB", toggle["fb"]) then ini.lastSend["fb"] = 0 ini.toggle.fb = toggle["fb"][0] SaveCfg() end
            imgui.SameLine()
            imgui.SetCursorPos(imgui.ImVec2(imgui.GetCursorPos().x + 9, imgui.GetCursorPos().y))
            imgui.PushItemWidth(234)
            if imgui.SliderInt("###Slider4", delays["fb"], 1, 660, u8'%d cек') then ini.delays.fb = delays["fb"][0] SaveCfg() end
           
            imgui.PushItemWidth(175)
            if imgui.InputText("###inputF", input["f"], 90) then ini.input.f = ffi.string(input["f"]) ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.SameLine()
            if imgui.ToggleButton("/f###OnOrDisableF", toggle["f"]) then ini.lastSend["f"] = 0 ini.toggle.f = toggle["f"][0] SaveCfg() end
            imgui.SameLine()
            imgui.SetCursorPos(imgui.ImVec2(imgui.GetCursorPos().x + 16, imgui.GetCursorPos().y))
            imgui.PushItemWidth(234)
            if imgui.SliderInt("###Slider5", delays["f"], 1, 660, u8'%d cек') then ini.delays.f = delays["f"][0] SaveCfg() end
           
            imgui.PushItemWidth(175)
            if imgui.InputText("###inputFam", input["fam"], 89) then ini.input.fam = ffi.string(input["fam"]) ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.SameLine()
            if imgui.ToggleButton("/fam###OnOrDisableFAM", toggle["fam"]) then ini.lastSend["fam"] = 0 ini.toggle.fam = toggle["fam"][0] SaveCfg() end
            imgui.SameLine()
            imgui.PushItemWidth(234)
            if imgui.SliderInt("###Slider6", delays["fam"], 1, 660, u8'%d cек') then ini.delays.fam = delays["fam"][0] SaveCfg() end
           
            imgui.PushItemWidth(175)
            if imgui.InputText("###inputRb", input["rb"], 90) then ini.input.rb = ffi.string(input["rb"]) ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.SameLine()
            if imgui.ToggleButton("/rb###OnOrDisableRB", toggle["rb"]) then ini.lastSend["rb"] = 0 ini.toggle.rb = toggle["rb"][0] SaveCfg() end
            imgui.SameLine()
            imgui.SetCursorPos(imgui.ImVec2(imgui.GetCursorPos().x + 9, imgui.GetCursorPos().y))
            imgui.PushItemWidth(234)
            if imgui.SliderInt("###Slider7", delays["rb"], 1, 660, u8'%d cек') then ini.delays.rb = delays["rb"][0] SaveCfg() end
           
            imgui.PushItemWidth(175)
            if imgui.InputText("###inputAl", input["al"], 94) then ini.input.al = ffi.string(input["al"]) ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.SameLine()
            if imgui.ToggleButton("/al###OnOrDisableAL", toggle["al"]) then ini.lastSend["al"] = 0 ini.toggle.al = toggle["al"][0] SaveCfg() end
            imgui.SameLine()
            imgui.SetCursorPos(imgui.ImVec2(imgui.GetCursorPos().x + 11, imgui.GetCursorPos().y))
            imgui.PushItemWidth(234)
            if imgui.SliderInt("###Slider8", delays["al"], 1, 660, u8'%d cек') then ini.delays.al = delays["al"][0] SaveCfg() end
           
            imgui.PushItemWidth(175)
            if imgui.InputText("###inputJb", input["jb"], 175) then ini.input.jb = ffi.string(input["jb"]) ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.SameLine()
            if imgui.ToggleButton("/jb###OnOrDisableJB", toggle["jb"]) then ini.lastSend["jb"] = 0 ini.toggle.jb = toggle["jb"][0] SaveCfg() end
            imgui.SameLine()
            imgui.SetCursorPos(imgui.ImVec2(imgui.GetCursorPos().x + 9, imgui.GetCursorPos().y))
            imgui.PushItemWidth(234)
            if imgui.SliderInt("###Slider9", delays["jb"], 1, 660, u8'%d cек') then ini.delays.jb = delays["jb"][0] SaveCfg() end
           
            imgui.Separator()

            imgui.PushItemWidth(175)
            if imgui.InputText("###inputAd", input["ad"], 80) then ini.input.ad = ffi.string(input["ad"]) ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.SameLine()
            if imgui.ToggleButton("/ad###OnOrDisableAD", toggle["ad"]) then ini.lastSend["ad"] = 0 ini.toggle.ad = toggle["ad"][0] SaveCfg() end
            imgui.SameLine()
            imgui.PushItemWidth(241)
            if imgui.SliderInt("###Slider10", delays["ad"], 30, 660, u8'%d cек') then ini.delays.ad = delays["ad"][0] SaveCfg() end

            imgui.SetCursorPos(imgui.ImVec2(250, 295))
            imgui.PushItemWidth(120)
            if imgui.Combo("##com3", ad["type"], ImItemsTypeCombo, #item_listTypeCombo) then ini.ad.type = ad["type"][0] ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.SameLine()
            imgui.PushItemWidth(117)
            if imgui.Combo("##com4", ad["centr"], ImItemsCentrCombo, #item_listCentrCombo) then ini.ad.centr = ad["centr"][0] ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.Tooltip(u8('"Автоматически" - Скрипт будет кидать в радиоцентр где была последняя редакция'))

            imgui.Separator()

            if imgui.Checkbox(u8('Отправка рекламой в випчат'), vrAdvertisementSend) then ini.main.vrAdvertisementSend = vrAdvertisementSend[0] ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.Tooltip(u8('При активности скрипт будет оплачивать рекламу в випчат'))

            if imgui.Checkbox(u8('Отключение состояния скрипта через'), inactiveShutdown) then ini.main.inactiveShutdown = inactiveShutdown[0] ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.Tooltip(u8('Данная функция полезна для серверов, где автореклама разрешена только у ПК.'))
            imgui.SameLine()
            -- imgui.PushItemWidth(50)
            if imgui.InputInt("###sleepInactiveShutdown", sleepInactiveShutdown, 1, 100, imgui.InputTextFlags.AutoSelectAll) then ini.main.sleepInactiveShutdown = sleepInactiveShutdown[0] ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.Tooltip(u8('В минутах.'))
            imgui.SameLine()
            imgui.Text(u8('не активности'))
            imgui.Tooltip(u8('Данная функция полезна для серверов, где автореклама разрешена только у ПК.'))

            if imgui.ToggleButton(u8("Состояние скрипта###scriptToggle"), toggleScript) then ini.main.enabled = toggleScript[0] SaveCfg() end
            imgui.SameLine()
            imgui.Link("https://vk.com/id620137656", u8("Автор скрипта"))
           
            imgui.SameLine()

            local text = u8('Команды скрипта')
            local tSize = imgui.CalcTextSize(text)
            local p = imgui.GetCursorScreenPos()
            local DL = imgui.GetWindowDrawList()
            local col = { 0xFFFF7700, 0xFFFF9900 }
            if imgui.InvisibleButton("##commands", tSize) then
                sms('/autoad - Меню скрипта')
                sms('/adv [message] - Быстрая отправка объявления с указанными настройками в скрипте')
            end
            local color = imgui.IsItemHovered() and col[1] or col[2]
            DL:AddText(p, color, text)
            DL:AddLine(imgui.ImVec2(p.x, p.y + tSize.y), imgui.ImVec2(p.x + tSize.x, p.y + tSize.y), color)

            imgui.End()
        end
        imgui.PopStyleVar()
    end
)

function imgui.Tooltip(text)
    if imgui.IsItemHovered() then
        imgui.BeginTooltip()
        imgui.Text(text)
        imgui.EndTooltip()
    end
end

function imgui.ToggleButton(str_id, bool)
    local rBool = false

    if LastActiveTime == nil then
        LastActiveTime = {}
    end
    if LastActive == nil then
        LastActive = {}
    end

    local function ImSaturate(f)
        return f < 0.0 and 0.0 or (f > 1.0 and 1.0 or f)
    end

    local p = imgui.GetCursorScreenPos()
    local dl = imgui.GetWindowDrawList()

    local height = imgui.GetTextLineHeightWithSpacing()
    local width = height * 1.70
    local radius = height * 0.50
    local ANIM_SPEED = type == 2 and 0.10 or 0.15
    local butPos = imgui.GetCursorPos()

    if imgui.InvisibleButton(str_id, imgui.ImVec2(width, height)) then
        bool[0] = not bool[0]
        rBool = true
        LastActiveTime[tostring(str_id)] = os.clock()
        LastActive[tostring(str_id)] = true
    end

    imgui.SetCursorPos(imgui.ImVec2(butPos.x + width + 8, butPos.y + 2.5))
    imgui.Text( str_id:gsub('##.+', '') )

    local t = bool[0] and 1.0 or 0.0

    if LastActive[tostring(str_id)] then
        local time = os.clock() - LastActiveTime[tostring(str_id)]
        if time <= ANIM_SPEED then
            local t_anim = ImSaturate(time / ANIM_SPEED)
            t = bool[0] and t_anim or 1.0 - t_anim
        else
            LastActive[tostring(str_id)] = false
        end
    end

    local col_circle = bool[0] and imgui.ColorConvertFloat4ToU32(imgui.ImVec4(imgui.GetStyle().Colors[imgui.Col.ButtonActive])) or imgui.ColorConvertFloat4ToU32(imgui.ImVec4(imgui.GetStyle().Colors[imgui.Col.TextDisabled]))
    dl:AddRectFilled(p, imgui.ImVec2(p.x + width, p.y + height), imgui.ColorConvertFloat4ToU32(imgui.GetStyle().Colors[imgui.Col.FrameBg]), height * 0.5)
    dl:AddCircleFilled(imgui.ImVec2(p.x + radius + t * (width - radius * 2.0), p.y + radius), radius - 1.5, col_circle)
    return rBool
end

function imgui.Link(link, text)
    text = text or link
    local tSize = imgui.CalcTextSize(text)
    local p = imgui.GetCursorScreenPos()
    local DL = imgui.GetWindowDrawList()
    local col = { 0xFFFF7700, 0xFFFF9900 }
    if imgui.InvisibleButton("##" .. link, tSize) then os.execute("explorer " .. link) end
    local color = imgui.IsItemHovered() and col[1] or col[2]
    DL:AddText(p, color, text)
    DL:AddLine(imgui.ImVec2(p.x, p.y + tSize.y), imgui.ImVec2(p.x + tSize.x, p.y + tSize.y), color)
end

function sms(text)
    local text = text:gsub('{mc}', '{3487ff}')
    sampAddChatMessage('[AutoAdByDiscq192] {FFFFFF}' .. tostring(text), 0x3487ff)
end

function main()
    while true do if isSampAvailable() and sampIsLocalPlayerSpawned() then break end wait(0) end
    sms("Успешно загружено! Активация: {mc}/autoad")
    sampRegisterChatCommand('autoad', function()
        menu.switch()
    end)

    sampRegisterChatCommand('adv', function (arg)
        if #arg < 1 then
            sms('Использование команды: {mc}/adv [message]')
        elseif toggle["ad"][0] and toggleScript[0] then
            sms('Данную команду можно использовать при отключенной авторекламе во избежание багов.')
        elseif #arg < 20 or #arg > 80 then
            sms('В тексте объявления должно быть от 20 до 80 символов.')
        else
            advSended.state = true
            advSended.msg = arg
            sampSendChat('/ad')
        end
    end)

    wait(3000)

    while true do
        if toggleScript[0] then
            print(os.time() - lastSendKeyMessage)
            if not stateLastSendKeyMessage and inactiveShutdown[0] and os.time() - lastSendKeyMessage > tonumber(sleepInactiveShutdown[0]) * 60 then
                stateLastSendKeyMessage = true
                sms('Состояние скрипта {mc}приостоновлено{FFFFFF}! Обнаружена не активность в течение {mc}' .. sleepInactiveShutdown[0] * 60 .. '{FFFFFF} секунд!')
            elseif not stateLastSendKeyMessage then
                for index, value in pairs(toggle) do
                    if value[0] and ini.lastSend[index] < os.time() then
                        ini.lastSend[index] = os.time() + delays[index][0]
                        SaveCfg()
                        if index == 'vr' then
                            vrSended = true
                        end
                        sampSendChat('/'..index..' '..u8:decode(ffi.string(input[index])))
                        wait(100)
                    end
                end
            end
        end
        wait(0)
    end
end


function sampev.onServerMessage(clr, text)
    if toggle["ad"][0] and toggleScript[0] and not advSended.state then
        local text = text:gsub("{......}","")
        if text:find("Объявление") and text:find(sampGetPlayerNickname(select(2, sampGetPlayerIdByCharHandle(PLAYER_PED)))) and clr == 1941201407 then
            lua_thread.create(function()
                local currentTime = os.time()
                local difference = os.difftime(currentTime, startTime)
                wait(1000)
                if difference >= delays["ad"][0] + 1 then
                    sampSendChat('/ad')
                else
                    local timeLeft = delays["ad"][0] + 1 - difference
                    sms("/ad - Еще не прошло "..delays["ad"][0].." секунд, отправлю через {mc}"..timeLeft.." секунд")
                    ini.lastSend["ad"] = os.time() + timeLeft
                end
            end)
        end
        if (text:find("Используйте: /ad %[текст объявления%]") or text:find("Ваше сообщение зарегистрировано в системе и будет опубликовано после редакции!")) then
            return false
        end
    end
end

function sampev.onShowDialog(id, style, title, button1, button2, text)
    if (toggle["ad"][0] and toggleScript[0]) or advSended.state then
        if title:find("Подача объявления") and text:find("Напишите текст объявление") and not advSended.state then
            sampSendDialogResponse(id, 1, 65535, u8:decode(ffi.string(input['ad'])))
            return false
        elseif title:find("Подача объявления") and text:find("Напишите текст объявление") and advSended.state then
            sampSendDialogResponse(id, 1, 65535, advSended.msg)
            return false
        end
        if title:find("Выберите радиостанцию") and text:find("Радиостанция") then
            local lines = {}
            local line_count = 0
            for line in text:gmatch("[^\r\n]+") do
                if not line:find("{[a-fA-F0-9]+}") then
                    line_count = line_count + 1
                    lines[line_count] = line
                end
            end
            local line1, line2, line3 = lines[1], lines[2], lines[3]
            local hour1, hour2, hour3, min1, min2, min3, sec1, sec2, sec3
            local totalsec1, totalsec2, totalsec3 = 9999, 9998, 9997
            if line1:find("час") then
                hour1, min1, sec1 = line1:match("(%d+) час (%d+) мин (%d+) сек")
                totalsec1 = hour1 * 360 + min1 * 60 + sec1
            elseif line1:find("мин") and not line1:find("час") then
                min1, sec1 = line1:match("(%d+) мин (%d+) сек")
                totalsec1 = min1 * 60 + sec1
            elseif line1:find("сек") and not line1:find("мин") then
                sec1 = line1:match("(%d+) сек")
                totalsec1 = sec1
            end
            if line2:find("час") then
                hour2, min2, sec2 = line2:match("(%d+) час (%d+) мин (%d+) сек")
                totalsec2 = hour2 * 360 + min2 * 60 + sec2
            elseif line2:find("мин") and not line2:find("час") then
                min2, sec2 = line2:match("(%d+) мин (%d+) сек")
                totalsec2 = min2 * 60 + sec2
            elseif line2:find("сек") and not line2:find("мин") then
                sec2 = line2:match("(%d+) сек")
                totalsec2 = sec2
            end
            if line3:find("час") then
                hour3, min3, sec3 = line3:match("(%d+) час (%d+) мин (%d+) сек")
                totalsec3 = hour3 * 360 + min3 * 60 + sec3
            elseif line3:find("мин") and not line3:find("час") then
                min3, sec3 = line3:match("(%d+) мин (%d+) сек")
                totalsec3 = min3 * 60 + sec3
            elseif line3:find("сек") and not line3:find("мин") then
                sec3 = line3:match("(%d+) сек")
                totalsec3 = sec3
            end

            if tonumber(totalsec1) < tonumber(totalsec2) and tonumber(totalsec1) < tonumber(totalsec3) and ad["centr"][0] == 0 then
                sampSendDialogResponse(id,1,0,"")
                sms('/ad - Последняя редакция была в Радиоцентре Лос-Сантос')
            elseif tonumber(totalsec2) < tonumber(totalsec1) and tonumber(totalsec2) < tonumber(totalsec3) and ad["centr"][0] == 0 then
                sampSendDialogResponse(id,1,1,"")
                sms('/ad - Последняя редакция была в Радиоцентре Лас-Вентурас')
            elseif tonumber(totalsec3) < tonumber(totalsec1) and tonumber(totalsec3) < tonumber(totalsec2) and ad["centr"][0] == 0 then
                sampSendDialogResponse(id,1,2,"")
                sms('/ad - Последняя редакция была в Радиоцентре Сан-Фиерро')
            else
                if ad["centr"][0] == 1 then
                    sampSendDialogResponse(id,1,2,"")
                elseif ad["centr"][0] == 2 then
                    sampSendDialogResponse(id,1,1,"")
                elseif ad["centr"][0] == 3 then
                    sampSendDialogResponse(id,1,0,"")
                end
            end
            return false
        end
        if title:find("Подача объявления") and text:find("Выберите тип объявления") then
            if ad["type"][0] == 0 then
                sampSendDialogResponse(id,1,0,"")
            elseif ad["type"][0] == 1 then
                sampSendDialogResponse(id,1,1,"")
            else
                sampSendDialogResponse(id,1,3,"")
            end
            return false
        end
        if title:find("Подача объявления %| Подтверждение") then
            sampSendDialogResponse(id,1,65535,"")
            startTime = os.time()
            return false
        end
    end
    if id == 25623 and vrSended then
        vrSended = false
        sampSendDialogResponse(id, ini.main.vrAdvertisementSend and 1 or 0, 65535, "")
        return false
    end
    if id == 15379 and ini.toggle.ad and toggleScript[0] and not advSended.state then
        ini.lastSend['ad'] = os.time() + delays['ad'][0]
        sms('/ad - Объявление не отредактировали, повторная попытка через {mc}'.. delays['ad'][0] .. ' секунд')
        sampSendDialogResponse(id, 0, 65535, "")
        return false
    end
end

function onWindowMessage(msg, wparam, lparam)
    if msg == 0x100 or msg == 0x101 or msg == 523 or msg == 513 or msg == 516 then
        if (wparam == keys.VK_ESCAPE and menu.state) and not isPauseMenuActive() then
            consumeWindowMessage(true, false);
            if msg == 0x101 then menu.switch() end
        end
        lastSendKeyMessage = os.time()

        if stateLastSendKeyMessage then
            sms('Работа скрипта {mc}возобновлена{FFFFFF}!')
            stateLastSendKeyMessage = false
        end
    end
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 = imgui.ImVec2(8, 8)
    style.WindowRounding = 6
    style.ChildRounding = 5
    style.FramePadding = imgui.ImVec2(5, 3)
    style.FrameRounding = 3.0
    style.ItemSpacing = imgui.ImVec2(5, 4)
    style.ItemInnerSpacing = imgui.ImVec2(4, 4)
    style.IndentSpacing = 21
    style.ScrollbarSize = 10.0
    style.ScrollbarRounding = 13
    style.GrabMinSize = 8
    style.GrabRounding = 1
    style.WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
    style.ButtonTextAlign = imgui.ImVec2(0.5, 0.5)

    colors[clr.Text]                   = ImVec4(0.95, 0.96, 0.98, 1.00);
    colors[clr.TextDisabled]           = ImVec4(0.29, 0.29, 0.29, 1.00);
    colors[clr.WindowBg]               = ImVec4(0.14, 0.14, 0.14, 1.00);
    colors[clr.ChildBg]          = ImVec4(0.17, 0.17, 0.17, 1.00);
    colors[clr.PopupBg]                = ImVec4(0.08, 0.08, 0.08, 0.94);
    colors[clr.Border]                 = ImVec4(0.14, 0.14, 0.14, 1.00);
    colors[clr.BorderShadow]           = ImVec4(1.00, 1.00, 1.00, 0.10);
    colors[clr.FrameBg]                = ImVec4(0.22, 0.22, 0.22, 1.00);
    colors[clr.FrameBgHovered]         = ImVec4(0.18, 0.18, 0.18, 1.00);
    colors[clr.FrameBgActive]          = ImVec4(0.10, 0.10, 0.10, 1.00);
    colors[clr.TitleBg]                = ImVec4(0.14, 0.14, 0.14, 0.81);
    colors[clr.TitleBgActive]          = ImVec4(0.12, 0.12, 0.12, 1.00);
    colors[clr.TitleBgCollapsed]       = ImVec4(0.00, 0.00, 0.00, 0.51);
    colors[clr.MenuBarBg]              = ImVec4(0.20, 0.20, 0.20, 1.00);
    colors[clr.ScrollbarBg]            = ImVec4(0.02, 0.02, 0.02, 0.39);
    colors[clr.ScrollbarGrab]          = ImVec4(0.36, 0.36, 0.36, 1.00);
    colors[clr.ScrollbarGrabHovered]   = ImVec4(0.18, 0.22, 0.25, 1.00);
    colors[clr.ScrollbarGrabActive]    = ImVec4(0.24, 0.24, 0.24, 1.00);
    colors[clr.CheckMark]              = ImVec4(1.00, 0.28, 0.28, 1.00);
    colors[clr.SliderGrab]             = ImVec4(1.00, 0.28, 0.28, 1.00);
    colors[clr.SliderGrabActive]       = ImVec4(1.00, 0.28, 0.28, 1.00);
    colors[clr.Button]                 = ImVec4(1.00, 0.28, 0.28, 1.00);
    colors[clr.ButtonHovered]          = ImVec4(1.00, 0.39, 0.39, 1.00);
    colors[clr.ButtonActive]           = ImVec4(1.00, 0.21, 0.21, 1.00);
    colors[clr.Header]                 = ImVec4(1.00, 0.28, 0.28, 1.00);
    colors[clr.HeaderHovered]          = ImVec4(1.00, 0.39, 0.39, 1.00);
    colors[clr.HeaderActive]           = ImVec4(1.00, 0.21, 0.21, 1.00);
    colors[clr.ResizeGrip]             = ImVec4(1.00, 0.28, 0.28, 1.00);
    colors[clr.ResizeGripHovered]      = ImVec4(1.00, 0.39, 0.39, 1.00);
    colors[clr.ResizeGripActive]       = ImVec4(1.00, 0.19, 0.19, 1.00);
    colors[clr.PlotLines]              = ImVec4(0.61, 0.61, 0.61, 1.00);
    colors[clr.PlotLinesHovered]       = ImVec4(1.00, 0.43, 0.35, 1.00);
    colors[clr.PlotHistogram]          = ImVec4(1.00, 0.21, 0.21, 1.00);
    colors[clr.PlotHistogramHovered]   = ImVec4(1.00, 0.18, 0.18, 1.00);
    colors[clr.TextSelectedBg]         = ImVec4(1.00, 0.32, 0.32, 1.00);
    colors[clr.ModalWindowDimBg]   = ImVec4(0.26, 0.26, 0.26, 0.60);
end
 

Вложения

  • 1734811421824.png
    1734811421824.png
    38.2 KB · Просмотры: 5
Решение
Ещё хуже стало

небольшой костыль, т.к. в imgui кириллица занимает 2 байта в буфере (потому и лимит в 105, установленный в скрипте, превращался фактически в 52 символа):
Lua:
script_version('1.4.2');
script_author('https://vk.com/id620137656');

local sampev = require('lib.samp.events')
local imgui = require('mimgui');
local encoding = require('encoding');
encoding.default = 'CP1251'
u8 = encoding.UTF8
local inicfg = require('inicfg');
local ffi = require('ffi');
local keys = require('vkeys');

local directIni = 'AutoAdByDiscq192.ini'
local lastSendKeyMessage = os.time()
local stateLastSendKeyMessage = false

local ini = inicfg.load(inicfg.load({
    main = {
        enabled = false,
        vrAdvertisementSend = true...

wojciech?

Известный
Проверенный
355
237
Ещё хуже стало

небольшой костыль, т.к. в imgui кириллица занимает 2 байта в буфере (потому и лимит в 105, установленный в скрипте, превращался фактически в 52 символа):
Lua:
script_version('1.4.2');
script_author('https://vk.com/id620137656');

local sampev = require('lib.samp.events')
local imgui = require('mimgui');
local encoding = require('encoding');
encoding.default = 'CP1251'
u8 = encoding.UTF8
local inicfg = require('inicfg');
local ffi = require('ffi');
local keys = require('vkeys');

local directIni = 'AutoAdByDiscq192.ini'
local lastSendKeyMessage = os.time()
local stateLastSendKeyMessage = false

local ini = inicfg.load(inicfg.load({
    main = {
        enabled = false,
        vrAdvertisementSend = true,
        inactiveShutdown = false,
        sleepInactiveShutdown = 1
    },
    delays = {
        s = 30,
        j = 30,
        vr = 30,
        fb = 30,
        f = 30,
        fam = 30,
        rb = 30,
        al = 30,
        jb = 30,
        ad = 30,
    },
    toggle = {
        s = false,
        j = false,
        vr = false,
        fb = false,
        f = false,
        fam = false,
        rb = false,
        al = false,
        jb = false,
        ad = false,
    },
    ad = {
        type = 1,
        centr = 1
    },
    input = {
        s = "",
        j = "",
        vr = "",
        fb = "",
        f = "",
        fam = "",
        rb = "",
        al = "",
        jb = "",
        ad = "",
    },
    lastSend = {
        s = 0,
        j = 0,
        vr = 0,
        fb = 0,
        f = 0,
        fam = 0,
        rb = 0,
        al = 0,
        jb = 0,
        ad = 0,
    }
}, directIni))
inicfg.save(ini, directIni)

local SaveCfg = function()
    inicfg.save(ini, directIni)
end


local vrAdvertisementSend = imgui.new.bool(ini.main.vrAdvertisementSend)
local inactiveShutdown = imgui.new.bool(ini.main.inactiveShutdown)
local sleepInactiveShutdown = imgui.new.int(tonumber(ini.main.sleepInactiveShutdown))
local toggleScript = imgui.new.bool(ini.main.enabled)
local delays = {
    ["s"] = imgui.new.int(ini.delays.s),
    ["j"] = imgui.new.int(ini.delays.j),
    ["vr"] = imgui.new.int(ini.delays.vr),
    ["fb"] = imgui.new.int(ini.delays.fb),
    ["f"] = imgui.new.int(ini.delays.f),
    ["fam"] = imgui.new.int(ini.delays.fam),
    ["rb"] = imgui.new.int(ini.delays.rb),
    ["al"] = imgui.new.int(ini.delays.al),
    ["jb"] = imgui.new.int(ini.delays.jb),
    ["ad"] = imgui.new.int(ini.delays.ad)
}

local toggle = {
    ["s"] = imgui.new.bool(ini.toggle.s),
    ["j"] = imgui.new.bool(ini.toggle.j),
    ["vr"] = imgui.new.bool(ini.toggle.vr),
    ["fb"] = imgui.new.bool(ini.toggle.fb),
    ["f"] = imgui.new.bool(ini.toggle.f),
    ["fam"] = imgui.new.bool(ini.toggle.fam),
    ["rb"] = imgui.new.bool(ini.toggle.rb),
    ["al"] = imgui.new.bool(ini.toggle.al),
    ["jb"] = imgui.new.bool(ini.toggle.jb),
    ["ad"] = imgui.new.bool(ini.toggle.ad)
}

local ad = {
    ["type"] = imgui.new.int(ini.ad.type),
    ["centr"] = imgui.new.int(ini.ad.centr),
}


local input = {
    ["s"] = imgui.new.char[256](tostring(ini.input.s)),
    ["j"] = imgui.new.char[256](tostring(ini.input.j)),
    ["vr"] = imgui.new.char[256](tostring(ini.input.vr)),
    ["fb"] = imgui.new.char[256](tostring(ini.input.fb)),
    ["f"] = imgui.new.char[256](tostring(ini.input.f)),
    ["fam"] = imgui.new.char[256](tostring(ini.input.fam)),
    ["rb"] = imgui.new.char[256](tostring(ini.input.rb)),
    ["al"] = imgui.new.char[256](tostring(ini.input.al)),
    ["jb"] = imgui.new.char[256](tostring(ini.input.jb)),
    ["ad"] = imgui.new.char[256](tostring(ini.input.ad))
}

local item_listTypeCombo = {u8('Обычное'), u8('VIP'), u8('Реклама бизнеса')}
local ImItemsTypeCombo = imgui.new['const char*'][#item_listTypeCombo](item_listTypeCombo)

local item_listCentrCombo = {u8('Автоматически'), u8('SF'), u8('LV'), u8('LS')}
local ImItemsCentrCombo = imgui.new['const char*'][#item_listCentrCombo](item_listCentrCombo)

local vrSended = false
local advSended = {
    ["state"] = false,
    ["msg"] = ""
}

local ui_meta = {
    __index = function(self, v)
        if v == "switch" then
            local switch = function()
                if self.process and self.process:status() ~= "dead" then
                    return false -- // Предыдущая анимация ещё не завершилась!
                end
                self.timer = os.clock()
                self.state = not self.state

                self.process = lua_thread.create(function()
                    local bringFloatTo = function(from, to, start_time, duration)
                        local timer = os.clock() - start_time
                        if timer >= 0.00 and timer <= duration then
                            local count = timer / (duration / 100)
                            return count * ((to - from) / 100)
                        end
                        return (timer > duration) and to or from
                    end

                    while true do wait(0)
                        local a = bringFloatTo(0.00, 1.00, self.timer, self.duration)
                        self.alpha = self.state and a or 1.00 - a
                        if a == 1.00 then break end
                    end
                end)
                return true -- // Состояние окна изменено!
            end
            return switch
        end
 
        if v == "alpha" then
            return self.state and 1.00 or 0.00
        end
    end
}

local menu = { state = false, duration = 0.5 }
setmetatable(menu, ui_meta)


imgui.OnInitialize(function()
    imgui.GetIO().IniFilename = nil
    theme()
end)

imgui.OnFrame(
    function() return menu.alpha > 0.00 end,
    function(player)
        local resX, resY = getScreenResolution()
        local sizeX, sizeY = 500, 400
        imgui.SetNextWindowPos(imgui.ImVec2(resX / 2, resY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(sizeX, sizeY), imgui.Cond.FirstUseEver)
        player.HideCursor = not menu.state
        imgui.PushStyleVarFloat(imgui.StyleVar.Alpha, menu.alpha)
        if imgui.Begin('AutoAdByDiscq192 | ' .. thisScript().version, _, imgui.WindowFlags.NoResize) then
          
            imgui.PushItemWidth(175)
            if imgui.InputText("###inputS", input["s"], 99) then ini.input.s = ffi.string(input["s"]) ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.SameLine()
            if imgui.ToggleButton("/s###OnOrDisableS", toggle["s"]) then ini.lastSend["s"] = 0 ini.toggle.s = toggle["s"][0] SaveCfg() end
            imgui.SameLine()
            imgui.SetCursorPos(imgui.ImVec2(imgui.GetCursorPos().x + 16, imgui.GetCursorPos().y))
            imgui.PushItemWidth(234)
            if imgui.SliderInt("###Slider1", delays["s"], 1, 660, u8'%d cек') then ini.delays.s = delays["s"][0] SaveCfg() end

            imgui.PushItemWidth(175)
            if imgui.InputText("###inputJ", input["j"], 177) then ini.input.j = ffi.string(input["j"]) ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.SameLine()
            if imgui.ToggleButton("/j###OnOrDisableJ", toggle["j"]) then ini.lastSend["j"] = 0 ini.toggle.j = toggle["j"][0] SaveCfg() end
            imgui.SameLine()
            imgui.SetCursorPos(imgui.ImVec2(imgui.GetCursorPos().x + 16, imgui.GetCursorPos().y))
            imgui.PushItemWidth(234)
            if imgui.SliderInt("###Slider2", delays["j"], 1, 660, u8'%d cек') then ini.delays.j = delays["j"][0] SaveCfg() end
          
            imgui.PushItemWidth(175)
            if imgui.InputText("###inputVr", input["vr"], 256) then
                local str = ffi.string(input["vr"])
                if str:len() <= 100 then
                    ini.input.vr = ffi.string(input["vr"])
                    print(ini.input.vr)
                    print(str)
                    ini.main.enabled = false
                    toggleScript[0] = false
                    SaveCfg()
                else
                    ffi.copy(input["vr"], str:sub(1, 100))
                end
            end
            imgui.SameLine()
            if imgui.ToggleButton("/vr###OnOrDisableVR", toggle["vr"]) then ini.lastSend["vr"] = 0 ini.toggle.vr = toggle["vr"][0] SaveCfg() end
            imgui.SameLine()
            imgui.SetCursorPos(imgui.ImVec2(imgui.GetCursorPos().x + 9, imgui.GetCursorPos().y))
            imgui.PushItemWidth(234)
            if imgui.SliderInt("###Slider3", delays["vr"], 1, 660, u8'%d cек') then ini.delays.vr = delays["vr"][0] SaveCfg() end
          
            imgui.PushItemWidth(175)
            if imgui.InputText("###inputFb", input["fb"], 90) then ini.input.fb = ffi.string(input["fb"]) ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.SameLine()
            if imgui.ToggleButton("/fb###OnOrDisableFB", toggle["fb"]) then ini.lastSend["fb"] = 0 ini.toggle.fb = toggle["fb"][0] SaveCfg() end
            imgui.SameLine()
            imgui.SetCursorPos(imgui.ImVec2(imgui.GetCursorPos().x + 9, imgui.GetCursorPos().y))
            imgui.PushItemWidth(234)
            if imgui.SliderInt("###Slider4", delays["fb"], 1, 660, u8'%d cек') then ini.delays.fb = delays["fb"][0] SaveCfg() end
          
            imgui.PushItemWidth(175)
            if imgui.InputText("###inputF", input["f"], 90) then ini.input.f = ffi.string(input["f"]) ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.SameLine()
            if imgui.ToggleButton("/f###OnOrDisableF", toggle["f"]) then ini.lastSend["f"] = 0 ini.toggle.f = toggle["f"][0] SaveCfg() end
            imgui.SameLine()
            imgui.SetCursorPos(imgui.ImVec2(imgui.GetCursorPos().x + 16, imgui.GetCursorPos().y))
            imgui.PushItemWidth(234)
            if imgui.SliderInt("###Slider5", delays["f"], 1, 660, u8'%d cек') then ini.delays.f = delays["f"][0] SaveCfg() end
          
            imgui.PushItemWidth(175)
            if imgui.InputText("###inputFam", input["fam"], 89) then ini.input.fam = ffi.string(input["fam"]) ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.SameLine()
            if imgui.ToggleButton("/fam###OnOrDisableFAM", toggle["fam"]) then ini.lastSend["fam"] = 0 ini.toggle.fam = toggle["fam"][0] SaveCfg() end
            imgui.SameLine()
            imgui.PushItemWidth(234)
            if imgui.SliderInt("###Slider6", delays["fam"], 1, 660, u8'%d cек') then ini.delays.fam = delays["fam"][0] SaveCfg() end
          
            imgui.PushItemWidth(175)
            if imgui.InputText("###inputRb", input["rb"], 90) then ini.input.rb = ffi.string(input["rb"]) ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.SameLine()
            if imgui.ToggleButton("/rb###OnOrDisableRB", toggle["rb"]) then ini.lastSend["rb"] = 0 ini.toggle.rb = toggle["rb"][0] SaveCfg() end
            imgui.SameLine()
            imgui.SetCursorPos(imgui.ImVec2(imgui.GetCursorPos().x + 9, imgui.GetCursorPos().y))
            imgui.PushItemWidth(234)
            if imgui.SliderInt("###Slider7", delays["rb"], 1, 660, u8'%d cек') then ini.delays.rb = delays["rb"][0] SaveCfg() end
          
            imgui.PushItemWidth(175)
            if imgui.InputText("###inputAl", input["al"], 94) then ini.input.al = ffi.string(input["al"]) ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.SameLine()
            if imgui.ToggleButton("/al###OnOrDisableAL", toggle["al"]) then ini.lastSend["al"] = 0 ini.toggle.al = toggle["al"][0] SaveCfg() end
            imgui.SameLine()
            imgui.SetCursorPos(imgui.ImVec2(imgui.GetCursorPos().x + 11, imgui.GetCursorPos().y))
            imgui.PushItemWidth(234)
            if imgui.SliderInt("###Slider8", delays["al"], 1, 660, u8'%d cек') then ini.delays.al = delays["al"][0] SaveCfg() end
          
            imgui.PushItemWidth(175)
            if imgui.InputText("###inputJb", input["jb"], 175) then ini.input.jb = ffi.string(input["jb"]) ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.SameLine()
            if imgui.ToggleButton("/jb###OnOrDisableJB", toggle["jb"]) then ini.lastSend["jb"] = 0 ini.toggle.jb = toggle["jb"][0] SaveCfg() end
            imgui.SameLine()
            imgui.SetCursorPos(imgui.ImVec2(imgui.GetCursorPos().x + 9, imgui.GetCursorPos().y))
            imgui.PushItemWidth(234)
            if imgui.SliderInt("###Slider9", delays["jb"], 1, 660, u8'%d cек') then ini.delays.jb = delays["jb"][0] SaveCfg() end
          
            imgui.Separator()

            imgui.PushItemWidth(175)
            if imgui.InputText("###inputAd", input["ad"], 80) then ini.input.ad = ffi.string(input["ad"]) ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.SameLine()
            if imgui.ToggleButton("/ad###OnOrDisableAD", toggle["ad"]) then ini.lastSend["ad"] = 0 ini.toggle.ad = toggle["ad"][0] SaveCfg() end
            imgui.SameLine()
            imgui.PushItemWidth(241)
            if imgui.SliderInt("###Slider10", delays["ad"], 30, 660, u8'%d cек') then ini.delays.ad = delays["ad"][0] SaveCfg() end

            imgui.SetCursorPos(imgui.ImVec2(250, 295))
            imgui.PushItemWidth(120)
            if imgui.Combo("##com3", ad["type"], ImItemsTypeCombo, #item_listTypeCombo) then ini.ad.type = ad["type"][0] ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.SameLine()
            imgui.PushItemWidth(117)
            if imgui.Combo("##com4", ad["centr"], ImItemsCentrCombo, #item_listCentrCombo) then ini.ad.centr = ad["centr"][0] ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.Tooltip(u8('"Автоматически" - Скрипт будет кидать в радиоцентр где была последняя редакция'))

            imgui.Separator()

            if imgui.Checkbox(u8('Отправка рекламой в випчат'), vrAdvertisementSend) then ini.main.vrAdvertisementSend = vrAdvertisementSend[0] ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.Tooltip(u8('При активности скрипт будет оплачивать рекламу в випчат'))

            if imgui.Checkbox(u8('Отключение состояния скрипта через'), inactiveShutdown) then ini.main.inactiveShutdown = inactiveShutdown[0] ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.Tooltip(u8('Данная функция полезна для серверов, где автореклама разрешена только у ПК.'))
            imgui.SameLine()
            -- imgui.PushItemWidth(50)
            if imgui.InputInt("###sleepInactiveShutdown", sleepInactiveShutdown, 1, 100, imgui.InputTextFlags.AutoSelectAll) then ini.main.sleepInactiveShutdown = sleepInactiveShutdown[0] ini.main.enabled = false toggleScript[0] = false SaveCfg() end
            imgui.Tooltip(u8('В минутах.'))
            imgui.SameLine()
            imgui.Text(u8('не активности'))
            imgui.Tooltip(u8('Данная функция полезна для серверов, где автореклама разрешена только у ПК.'))

            if imgui.ToggleButton(u8("Состояние скрипта###scriptToggle"), toggleScript) then ini.main.enabled = toggleScript[0] SaveCfg() end
            imgui.SameLine()
            imgui.Link("https://vk.com/id620137656", u8("Автор скрипта"))
          
            imgui.SameLine()

            local text = u8('Команды скрипта')
            local tSize = imgui.CalcTextSize(text)
            local p = imgui.GetCursorScreenPos()
            local DL = imgui.GetWindowDrawList()
            local col = { 0xFFFF7700, 0xFFFF9900 }
            if imgui.InvisibleButton("##commands", tSize) then
                sms('/autoad - Меню скрипта')
                sms('/adv [message] - Быстрая отправка объявления с указанными настройками в скрипте')
            end
            local color = imgui.IsItemHovered() and col[1] or col[2]
            DL:AddText(p, color, text)
            DL:AddLine(imgui.ImVec2(p.x, p.y + tSize.y), imgui.ImVec2(p.x + tSize.x, p.y + tSize.y), color)

            imgui.End()
        end
        imgui.PopStyleVar()
    end
)

function imgui.Tooltip(text)
    if imgui.IsItemHovered() then
        imgui.BeginTooltip()
        imgui.Text(text)
        imgui.EndTooltip()
    end
end

function imgui.ToggleButton(str_id, bool)
    local rBool = false

    if LastActiveTime == nil then
        LastActiveTime = {}
    end
    if LastActive == nil then
        LastActive = {}
    end

    local function ImSaturate(f)
        return f < 0.0 and 0.0 or (f > 1.0 and 1.0 or f)
    end

    local p = imgui.GetCursorScreenPos()
    local dl = imgui.GetWindowDrawList()

    local height = imgui.GetTextLineHeightWithSpacing()
    local width = height * 1.70
    local radius = height * 0.50
    local ANIM_SPEED = type == 2 and 0.10 or 0.15
    local butPos = imgui.GetCursorPos()

    if imgui.InvisibleButton(str_id, imgui.ImVec2(width, height)) then
        bool[0] = not bool[0]
        rBool = true
        LastActiveTime[tostring(str_id)] = os.clock()
        LastActive[tostring(str_id)] = true
    end

    imgui.SetCursorPos(imgui.ImVec2(butPos.x + width + 8, butPos.y + 2.5))
    imgui.Text( str_id:gsub('##.+', '') )

    local t = bool[0] and 1.0 or 0.0

    if LastActive[tostring(str_id)] then
        local time = os.clock() - LastActiveTime[tostring(str_id)]
        if time <= ANIM_SPEED then
            local t_anim = ImSaturate(time / ANIM_SPEED)
            t = bool[0] and t_anim or 1.0 - t_anim
        else
            LastActive[tostring(str_id)] = false
        end
    end

    local col_circle = bool[0] and imgui.ColorConvertFloat4ToU32(imgui.ImVec4(imgui.GetStyle().Colors[imgui.Col.ButtonActive])) or imgui.ColorConvertFloat4ToU32(imgui.ImVec4(imgui.GetStyle().Colors[imgui.Col.TextDisabled]))
    dl:AddRectFilled(p, imgui.ImVec2(p.x + width, p.y + height), imgui.ColorConvertFloat4ToU32(imgui.GetStyle().Colors[imgui.Col.FrameBg]), height * 0.5)
    dl:AddCircleFilled(imgui.ImVec2(p.x + radius + t * (width - radius * 2.0), p.y + radius), radius - 1.5, col_circle)
    return rBool
end

function imgui.Link(link, text)
    text = text or link
    local tSize = imgui.CalcTextSize(text)
    local p = imgui.GetCursorScreenPos()
    local DL = imgui.GetWindowDrawList()
    local col = { 0xFFFF7700, 0xFFFF9900 }
    if imgui.InvisibleButton("##" .. link, tSize) then os.execute("explorer " .. link) end
    local color = imgui.IsItemHovered() and col[1] or col[2]
    DL:AddText(p, color, text)
    DL:AddLine(imgui.ImVec2(p.x, p.y + tSize.y), imgui.ImVec2(p.x + tSize.x, p.y + tSize.y), color)
end

function sms(text)
    local text = text:gsub('{mc}', '{3487ff}')
    sampAddChatMessage('[AutoAdByDiscq192] {FFFFFF}' .. tostring(text), 0x3487ff)
end

function main()
    while true do if isSampAvailable() and sampIsLocalPlayerSpawned() then break end wait(0) end
    sms("Успешно загружено! Активация: {mc}/autoad")
    sampRegisterChatCommand('autoad', function()
        menu.switch()
    end)

    sampRegisterChatCommand('adv', function (arg)
        if #arg < 1 then
            sms('Использование команды: {mc}/adv [message]')
        elseif toggle["ad"][0] and toggleScript[0] then
            sms('Данную команду можно использовать при отключенной авторекламе во избежание багов.')
        elseif #arg < 20 or #arg > 80 then
            sms('В тексте объявления должно быть от 20 до 80 символов.')
        else
            advSended.state = true
            advSended.msg = arg
            sampSendChat('/ad')
        end
    end)

    wait(3000)

    while true do
        if toggleScript[0] then
            print(os.time() - lastSendKeyMessage)
            if not stateLastSendKeyMessage and inactiveShutdown[0] and os.time() - lastSendKeyMessage > tonumber(sleepInactiveShutdown[0]) * 60 then
                stateLastSendKeyMessage = true
                sms('Состояние скрипта {mc}приостоновлено{FFFFFF}! Обнаружена не активность в течение {mc}' .. sleepInactiveShutdown[0] * 60 .. '{FFFFFF} секунд!')
            elseif not stateLastSendKeyMessage then
                for index, value in pairs(toggle) do
                    if value[0] and ini.lastSend[index] < os.time() then
                        ini.lastSend[index] = os.time() + delays[index][0]
                        SaveCfg()
                        if index == 'vr' then
                            vrSended = true
                        end
                        sampSendChat('/'..index..' '..u8:decode(ffi.string(input[index])))
                        wait(100)
                    end
                end
            end
        end
        wait(0)
    end
end


function sampev.onServerMessage(clr, text)
    if toggle["ad"][0] and toggleScript[0] and not advSended.state then
        local text = text:gsub("{......}","")
        if text:find("Объявление") and text:find(sampGetPlayerNickname(select(2, sampGetPlayerIdByCharHandle(PLAYER_PED)))) and clr == 1941201407 then
            lua_thread.create(function()
                local currentTime = os.time()
                local difference = os.difftime(currentTime, startTime)
                wait(1000)
                if difference >= delays["ad"][0] + 1 then
                    sampSendChat('/ad')
                else
                    local timeLeft = delays["ad"][0] + 1 - difference
                    sms("/ad - Еще не прошло "..delays["ad"][0].." секунд, отправлю через {mc}"..timeLeft.." секунд")
                    ini.lastSend["ad"] = os.time() + timeLeft
                end
            end)
        end
        if (text:find("Используйте: /ad %[текст объявления%]") or text:find("Ваше сообщение зарегистрировано в системе и будет опубликовано после редакции!")) then
            return false
        end
    end
end

function sampev.onShowDialog(id, style, title, button1, button2, text)
    if (toggle["ad"][0] and toggleScript[0]) or advSended.state then
        if title:find("Подача объявления") and text:find("Напишите текст объявление") and not advSended.state then
            sampSendDialogResponse(id, 1, 65535, u8:decode(ffi.string(input['ad'])))
            return false
        elseif title:find("Подача объявления") and text:find("Напишите текст объявление") and advSended.state then
            sampSendDialogResponse(id, 1, 65535, advSended.msg)
            return false
        end
        if title:find("Выберите радиостанцию") and text:find("Радиостанция") then
            local lines = {}
            local line_count = 0
            for line in text:gmatch("[^\r\n]+") do
                if not line:find("{[a-fA-F0-9]+}") then
                    line_count = line_count + 1
                    lines[line_count] = line
                end
            end
            local line1, line2, line3 = lines[1], lines[2], lines[3]
            local hour1, hour2, hour3, min1, min2, min3, sec1, sec2, sec3
            local totalsec1, totalsec2, totalsec3 = 9999, 9998, 9997
            if line1:find("час") then
                hour1, min1, sec1 = line1:match("(%d+) час (%d+) мин (%d+) сек")
                totalsec1 = hour1 * 360 + min1 * 60 + sec1
            elseif line1:find("мин") and not line1:find("час") then
                min1, sec1 = line1:match("(%d+) мин (%d+) сек")
                totalsec1 = min1 * 60 + sec1
            elseif line1:find("сек") and not line1:find("мин") then
                sec1 = line1:match("(%d+) сек")
                totalsec1 = sec1
            end
            if line2:find("час") then
                hour2, min2, sec2 = line2:match("(%d+) час (%d+) мин (%d+) сек")
                totalsec2 = hour2 * 360 + min2 * 60 + sec2
            elseif line2:find("мин") and not line2:find("час") then
                min2, sec2 = line2:match("(%d+) мин (%d+) сек")
                totalsec2 = min2 * 60 + sec2
            elseif line2:find("сек") and not line2:find("мин") then
                sec2 = line2:match("(%d+) сек")
                totalsec2 = sec2
            end
            if line3:find("час") then
                hour3, min3, sec3 = line3:match("(%d+) час (%d+) мин (%d+) сек")
                totalsec3 = hour3 * 360 + min3 * 60 + sec3
            elseif line3:find("мин") and not line3:find("час") then
                min3, sec3 = line3:match("(%d+) мин (%d+) сек")
                totalsec3 = min3 * 60 + sec3
            elseif line3:find("сек") and not line3:find("мин") then
                sec3 = line3:match("(%d+) сек")
                totalsec3 = sec3
            end

            if tonumber(totalsec1) < tonumber(totalsec2) and tonumber(totalsec1) < tonumber(totalsec3) and ad["centr"][0] == 0 then
                sampSendDialogResponse(id,1,0,"")
                sms('/ad - Последняя редакция была в Радиоцентре Лос-Сантос')
            elseif tonumber(totalsec2) < tonumber(totalsec1) and tonumber(totalsec2) < tonumber(totalsec3) and ad["centr"][0] == 0 then
                sampSendDialogResponse(id,1,1,"")
                sms('/ad - Последняя редакция была в Радиоцентре Лас-Вентурас')
            elseif tonumber(totalsec3) < tonumber(totalsec1) and tonumber(totalsec3) < tonumber(totalsec2) and ad["centr"][0] == 0 then
                sampSendDialogResponse(id,1,2,"")
                sms('/ad - Последняя редакция была в Радиоцентре Сан-Фиерро')
            else
                if ad["centr"][0] == 1 then
                    sampSendDialogResponse(id,1,2,"")
                elseif ad["centr"][0] == 2 then
                    sampSendDialogResponse(id,1,1,"")
                elseif ad["centr"][0] == 3 then
                    sampSendDialogResponse(id,1,0,"")
                end
            end
            return false
        end
        if title:find("Подача объявления") and text:find("Выберите тип объявления") then
            if ad["type"][0] == 0 then
                sampSendDialogResponse(id,1,0,"")
            elseif ad["type"][0] == 1 then
                sampSendDialogResponse(id,1,1,"")
            else
                sampSendDialogResponse(id,1,3,"")
            end
            return false
        end
        if title:find("Подача объявления %| Подтверждение") then
            sampSendDialogResponse(id,1,65535,"")
            startTime = os.time()
            return false
        end
    end
    if id == 25623 and vrSended then
        vrSended = false
        sampSendDialogResponse(id, ini.main.vrAdvertisementSend and 1 or 0, 65535, "")
        return false
    end
    if id == 15379 and ini.toggle.ad and toggleScript[0] and not advSended.state then
        ini.lastSend['ad'] = os.time() + delays['ad'][0]
        sms('/ad - Объявление не отредактировали, повторная попытка через {mc}'.. delays['ad'][0] .. ' секунд')
        sampSendDialogResponse(id, 0, 65535, "")
        return false
    end
end

function onWindowMessage(msg, wparam, lparam)
    if msg == 0x100 or msg == 0x101 or msg == 523 or msg == 513 or msg == 516 then
        if (wparam == keys.VK_ESCAPE and menu.state) and not isPauseMenuActive() then
            consumeWindowMessage(true, false);
            if msg == 0x101 then menu.switch() end
        end
        lastSendKeyMessage = os.time()

        if stateLastSendKeyMessage then
            sms('Работа скрипта {mc}возобновлена{FFFFFF}!')
            stateLastSendKeyMessage = false
        end
    end
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 = imgui.ImVec2(8, 8)
    style.WindowRounding = 6
    style.ChildRounding = 5
    style.FramePadding = imgui.ImVec2(5, 3)
    style.FrameRounding = 3.0
    style.ItemSpacing = imgui.ImVec2(5, 4)
    style.ItemInnerSpacing = imgui.ImVec2(4, 4)
    style.IndentSpacing = 21
    style.ScrollbarSize = 10.0
    style.ScrollbarRounding = 13
    style.GrabMinSize = 8
    style.GrabRounding = 1
    style.WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
    style.ButtonTextAlign = imgui.ImVec2(0.5, 0.5)

    colors[clr.Text]                   = ImVec4(0.95, 0.96, 0.98, 1.00);
    colors[clr.TextDisabled]           = ImVec4(0.29, 0.29, 0.29, 1.00);
    colors[clr.WindowBg]               = ImVec4(0.14, 0.14, 0.14, 1.00);
    colors[clr.ChildBg]          = ImVec4(0.17, 0.17, 0.17, 1.00);
    colors[clr.PopupBg]                = ImVec4(0.08, 0.08, 0.08, 0.94);
    colors[clr.Border]                 = ImVec4(0.14, 0.14, 0.14, 1.00);
    colors[clr.BorderShadow]           = ImVec4(1.00, 1.00, 1.00, 0.10);
    colors[clr.FrameBg]                = ImVec4(0.22, 0.22, 0.22, 1.00);
    colors[clr.FrameBgHovered]         = ImVec4(0.18, 0.18, 0.18, 1.00);
    colors[clr.FrameBgActive]          = ImVec4(0.10, 0.10, 0.10, 1.00);
    colors[clr.TitleBg]                = ImVec4(0.14, 0.14, 0.14, 0.81);
    colors[clr.TitleBgActive]          = ImVec4(0.12, 0.12, 0.12, 1.00);
    colors[clr.TitleBgCollapsed]       = ImVec4(0.00, 0.00, 0.00, 0.51);
    colors[clr.MenuBarBg]              = ImVec4(0.20, 0.20, 0.20, 1.00);
    colors[clr.ScrollbarBg]            = ImVec4(0.02, 0.02, 0.02, 0.39);
    colors[clr.ScrollbarGrab]          = ImVec4(0.36, 0.36, 0.36, 1.00);
    colors[clr.ScrollbarGrabHovered]   = ImVec4(0.18, 0.22, 0.25, 1.00);
    colors[clr.ScrollbarGrabActive]    = ImVec4(0.24, 0.24, 0.24, 1.00);
    colors[clr.CheckMark]              = ImVec4(1.00, 0.28, 0.28, 1.00);
    colors[clr.SliderGrab]             = ImVec4(1.00, 0.28, 0.28, 1.00);
    colors[clr.SliderGrabActive]       = ImVec4(1.00, 0.28, 0.28, 1.00);
    colors[clr.Button]                 = ImVec4(1.00, 0.28, 0.28, 1.00);
    colors[clr.ButtonHovered]          = ImVec4(1.00, 0.39, 0.39, 1.00);
    colors[clr.ButtonActive]           = ImVec4(1.00, 0.21, 0.21, 1.00);
    colors[clr.Header]                 = ImVec4(1.00, 0.28, 0.28, 1.00);
    colors[clr.HeaderHovered]          = ImVec4(1.00, 0.39, 0.39, 1.00);
    colors[clr.HeaderActive]           = ImVec4(1.00, 0.21, 0.21, 1.00);
    colors[clr.ResizeGrip]             = ImVec4(1.00, 0.28, 0.28, 1.00);
    colors[clr.ResizeGripHovered]      = ImVec4(1.00, 0.39, 0.39, 1.00);
    colors[clr.ResizeGripActive]       = ImVec4(1.00, 0.19, 0.19, 1.00);
    colors[clr.PlotLines]              = ImVec4(0.61, 0.61, 0.61, 1.00);
    colors[clr.PlotLinesHovered]       = ImVec4(1.00, 0.43, 0.35, 1.00);
    colors[clr.PlotHistogram]          = ImVec4(1.00, 0.21, 0.21, 1.00);
    colors[clr.PlotHistogramHovered]   = ImVec4(1.00, 0.18, 0.18, 1.00);
    colors[clr.TextSelectedBg]         = ImVec4(1.00, 0.32, 0.32, 1.00);
    colors[clr.ModalWindowDimBg]   = ImVec4(0.26, 0.26, 0.26, 0.60);
end
 
  • Влюблен
Реакции: kereewka