хелп

falconix

Новичок
Автор темы
20
2
В этом скрипте охл заливается только один раз и не возвращается, чтобы заливать повторно, когда нужно обработать Н кол-во видеокарт. Как это фиксануть?
code:
require("moonloader")
local sampev = require("samp.events")
local encoding = require('encoding')

encoding.default = ('CP1251')
local u8 = encoding.UTF8

local coolantPercents = 50
local work = {on = false, cardsToProcess = {}, currentCardIndex = -1, stage = 0, videocardMode = ""}

local function checkCoolant(line)
    local val = tonumber(line:match("(%d+%.%d%d)%%?$"))
    return val and val <= coolantPercents
end

local function startCoolant()
    if work.on then
        sampAddChatMessage('{99ff99}Cooling{ffffff}: Автоматический обход уже выполняется.', -1)
        return
    end
    work.on = true
    work.cardsToProcess = {}
    work.currentCardIndex = -1
    work.stage = 0
    sampAddChatMessage('{99ff99}Cooling{ffffff}: Запуск обхода видеокарт (порог: '..coolantPercents..')...', -1)
end

local function getIndices(id, pattern, checkFunc)
    local text = sampGetDialogText(id)
    if not text then return {} end
    local indices = {}
    local idx = -1
    for line in string.gmatch(text, "[^\r\n]+") do
        if line:find(pattern) then
            if idx >= 0 and checkFunc(line) then
                table.insert(indices, idx)
            end
        end
        idx = idx + 1
    end
    return indices
end

function main()
    repeat wait(0) until isSampAvailable()
    while not isSampLoaded() do wait(0) end
    sampAddChatMessage('{99ff99}Cooling{ffffff}: {99ff99}Загружен{ffffff}. Команда для обхода:{99ff99} /cooling', -1)
    sampRegisterChatCommand('cooling', startCoolant)
    while true do wait(0) end
end

function sampev.onShowDialog(id, style, title, button1, button2, text)
    if not work.on then return end

    local function deactivate(msg, closeDialog)
        work.on = false
        work.cardsToProcess = {}
        work.currentCardIndex = -1
        work.stage = 0
        sampAddChatMessage('{99ff99}Cooling{ffffff}: '..msg, -1)
        if closeDialog then
            lua_thread.create(function() wait(0) sampCloseCurrentDialogWithButton(0) end)
        end
        return true
    end

    if title:find('{BFBBBA}Выберите видеокарту') then
        if work.stage == 0 then
            work.cardsToProcess = getIndices(id, "Полка", checkCoolant)
            if #work.cardsToProcess == 0 then
                return deactivate("Обход всех видеокарт завершён. Охлаждение не требуется.", false)
            else
                sampAddChatMessage('{99ff99}Cooling{ffffff}: Найдено '..#work.cardsToProcess..' видеокарт, требующих внимания.', -1)
            end
        end

        if #work.cardsToProcess > 0 then
            work.currentCardIndex = work.cardsToProcess[1]
            sampSendDialogResponse(id, 1, work.currentCardIndex)
            work.stage = 1
            return true
        else
            return deactivate("Обход всех видеокарт завершён.", false)
        end
    end

    if title:gsub("%-",""):find("{BFBBBA}Стойка №%d+ | Полка №%d+") and work.stage == 1 then
        local function findLineIndex(dialog_text, pattern)
            local idx = 0
            for line in string.gmatch(dialog_text, "[^\r\n]+") do
                if line:find(pattern) then
                    return idx
                end
                idx = idx + 1
            end
            return nil
        end

        local fillIndex = findLineIndex(text, 'Залить охлаждающую жидкость')
        if fillIndex ~= nil then
            work.videocardMode = ""
            if text:find("BTC") then
                work.videocardMode = "btc"
            elseif text:find("ASC") then
                work.videocardMode = "asc"
            end

            sampSendDialogResponse(id, 1, fillIndex)
            work.stage = 2
            return true
        else
            table.remove(work.cardsToProcess, 1)
            work.currentCardIndex = -1
            work.stage = 0
            sampSendDialogResponse(id, 0)
            return true
        end
    end

    if title:find('{BFBBBA}Выберите тип жидкости') and work.stage == 2 then
        local fluidType = "None"
        if work.videocardMode == 'btc' then
            fluidType = "для видеокарты"
        elseif work.videocardMode == 'asc' then
            fluidType = "Охлаждающая жидкость для Arizona Video Card"
        end

        local found = false
        local idx = -1
        for line in string.gmatch(text, "[^\r\n]+") do
            if line:find(fluidType) then
                local count = tonumber(line:match("%[ (%d+) %]"))
                if count and count > 0 then
                    sampSendDialogResponse(id, 1, idx)
                    found = true
                    break
                end
            end
            idx = idx + 1
        end

        table.remove(work.cardsToProcess, 1)
        work.currentCardIndex = -1
        work.stage = 0

        if not found then
            return deactivate("Скрипт деактивирован. Нет охлаждающей жидкости типа "..fluidType..".", true)
        end
        return true
    end
end
 

alexroq

Участник
112
12
Lua:
require("moonloader")
local sampev = require("samp.events")
local encoding = require('encoding')
encoding.default = ('CP1251')
local u8 = encoding.UTF8
local coolantPercents = 50
local work = {on = false, cardsToProcess = {}, currentCardIndex = -1, stage = 0, videocardMode = ""}
local function checkCoolant(line)
    local val = tonumber(line:match("(%d+%.%d%d)%%?$"))
    return val and val <= coolantPercents
end
local function startCoolant()
    if work.on then
        sampAddChatMessage('{99ff99}Cooling{ffffff}: Автоматический обход уже выполняется.', -1)
        return
    end
    work.on = true
    work.cardsToProcess = {}
    work.currentCardIndex = -1
    work.stage = 0
    sampAddChatMessage('{99ff99}Cooling{ffffff}: Запуск обхода видеокарт (порог: '..coolantPercents..')...', -1)
end
local function getIndices(id, pattern, checkFunc)
    local text = sampGetDialogText(id)
    if not text then return {} end
    local indices = {}
    local idx = -1
    for line in string.gmatch(text, "[^\r\n]+") do
        if line:find(pattern) then
            if idx >= 0 and checkFunc(line) then
                table.insert(indices, idx)
            end
        end
        idx = idx + 1
    end
    return indices
end
function main()
    repeat wait(0) until isSampAvailable()
    while not isSampLoaded() do wait(0) end
    sampAddChatMessage('{99ff99}Cooling{ffffff}: {99ff99}Загружен{ffffff}. Команда для обхода:{99ff99} /cooling', -1)
    sampRegisterChatCommand('cooling', startCoolant)
    while true do wait(0) end
end
function sampev.onShowDialog(id, style, title, button1, button2, text)
    if not work.on then return end
    local function deactivate(msg, closeDialog)
        work.on = false
        work.cardsToProcess = {}
        work.currentCardIndex = -1
        work.stage = 0
        sampAddChatMessage('{99ff99}Cooling{ffffff}: '..msg, -1)
        if closeDialog then
            lua_thread.create(function() wait(0) sampCloseCurrentDialogWithButton(0) end)
        end
        return true
    end
    if title:find('{BFBBBA}Выберите видеокарту') then
        if work.stage == 0 or work.stage == 3 then
            work.cardsToProcess = getIndices(id, "Полка", checkCoolant)
            if #work.cardsToProcess == 0 then
                return deactivate("Обход всех видеокарт завершён. Охлаждение не требуется.", false)
            else
                sampAddChatMessage('{99ff99}Cooling{ffffff}: Найдено '..#work.cardsToProcess..' видеокарт, требующих внимания.', -1)
            end
            work.stage = 0
        end
        if #work.cardsToProcess > 0 then
            work.currentCardIndex = work.cardsToProcess[1]
            sampSendDialogResponse(id, 1, work.currentCardIndex)
            work.stage = 1
            return true
        else
            return deactivate("Обход всех видеокарт завершён.", false)
        end
    end
    if title:gsub("%-",""):find("{BFBBBA}Стойка №%d+ | Полка №%d+") and work.stage == 1 then
        local function findLineIndex(dialog_text, pattern)
            local idx = 0
            for line in string.gmatch(dialog_text, "[^\r\n]+") do
                if line:find(pattern) then
                    return idx
                end
                idx = idx + 1
            end
            return nil
        end
        local fillIndex = findLineIndex(text, 'Залить охлаждающую жидкость')
        if fillIndex ~= nil then
            work.videocardMode = ""
            if text:find("BTC") then
                work.videocardMode = "btc"
            elseif text:find("ASC") then
                work.videocardMode = "asc"
            end
            sampSendDialogResponse(id, 1, fillIndex)
            work.stage = 2
            return true
        else
            table.remove(work.cardsToProcess, 1)
            work.currentCardIndex = -1
            work.stage = 0
            sampSendDialogResponse(id, 0)
            return true
        end
    end
    if title:find('{BFBBBA}Выберите тип жидкости') and work.stage == 2 then
        local fluidType = "None"
        if work.videocardMode == 'btc' then
            fluidType = "для видеокарты"
        elseif work.videocardMode == 'asc' then
            fluidType = "Охлаждающая жидкость для Arizona Video Card"
        end
        local found = false
        local idx = -1
        for line in string.gmatch(text, "[^\r\n]+") do
            if line:find(fluidType) then
                local count = tonumber(line:match("%[ (%d+) %]"))
                if count and count > 0 then
                    sampSendDialogResponse(id, 1, idx)
                    found = true
                    break
                end
            end
            idx = idx + 1
        end
        table.remove(work.cardsToProcess, 1)
        work.currentCardIndex = -1
        if not found then
            return deactivate("Скрипт деактивирован. Нет охлаждающей жидкости типа "..fluidType..".", true)
        end
        if #work.cardsToProcess > 0 then
            sampAddChatMessage('{99ff99}Cooling{ffffff}: Охлаждение залито. Осталось видеокарт: '..#work.cardsToProcess, -1)
            work.stage = 3
        else
            sampAddChatMessage('{99ff99}Cooling{ffffff}: Обход всех видеокарт завершён успешно.', -1)
            work.on = false
            work.stage = 0
        end
        return true
    end
end
хз, попробуй
 

falconix

Новичок
Автор темы
20
2
Lua:
require("moonloader")
local sampev = require("samp.events")
local encoding = require('encoding')
encoding.default = ('CP1251')
local u8 = encoding.UTF8
local coolantPercents = 50
local work = {on = false, cardsToProcess = {}, currentCardIndex = -1, stage = 0, videocardMode = ""}
local function checkCoolant(line)
    local val = tonumber(line:match("(%d+%.%d%d)%%?$"))
    return val and val <= coolantPercents
end
local function startCoolant()
    if work.on then
        sampAddChatMessage('{99ff99}Cooling{ffffff}: Автоматический обход уже выполняется.', -1)
        return
    end
    work.on = true
    work.cardsToProcess = {}
    work.currentCardIndex = -1
    work.stage = 0
    sampAddChatMessage('{99ff99}Cooling{ffffff}: Запуск обхода видеокарт (порог: '..coolantPercents..')...', -1)
end
local function getIndices(id, pattern, checkFunc)
    local text = sampGetDialogText(id)
    if not text then return {} end
    local indices = {}
    local idx = -1
    for line in string.gmatch(text, "[^\r\n]+") do
        if line:find(pattern) then
            if idx >= 0 and checkFunc(line) then
                table.insert(indices, idx)
            end
        end
        idx = idx + 1
    end
    return indices
end
function main()
    repeat wait(0) until isSampAvailable()
    while not isSampLoaded() do wait(0) end
    sampAddChatMessage('{99ff99}Cooling{ffffff}: {99ff99}Загружен{ffffff}. Команда для обхода:{99ff99} /cooling', -1)
    sampRegisterChatCommand('cooling', startCoolant)
    while true do wait(0) end
end
function sampev.onShowDialog(id, style, title, button1, button2, text)
    if not work.on then return end
    local function deactivate(msg, closeDialog)
        work.on = false
        work.cardsToProcess = {}
        work.currentCardIndex = -1
        work.stage = 0
        sampAddChatMessage('{99ff99}Cooling{ffffff}: '..msg, -1)
        if closeDialog then
            lua_thread.create(function() wait(0) sampCloseCurrentDialogWithButton(0) end)
        end
        return true
    end
    if title:find('{BFBBBA}Выберите видеокарту') then
        if work.stage == 0 or work.stage == 3 then
            work.cardsToProcess = getIndices(id, "Полка", checkCoolant)
            if #work.cardsToProcess == 0 then
                return deactivate("Обход всех видеокарт завершён. Охлаждение не требуется.", false)
            else
                sampAddChatMessage('{99ff99}Cooling{ffffff}: Найдено '..#work.cardsToProcess..' видеокарт, требующих внимания.', -1)
            end
            work.stage = 0
        end
        if #work.cardsToProcess > 0 then
            work.currentCardIndex = work.cardsToProcess[1]
            sampSendDialogResponse(id, 1, work.currentCardIndex)
            work.stage = 1
            return true
        else
            return deactivate("Обход всех видеокарт завершён.", false)
        end
    end
    if title:gsub("%-",""):find("{BFBBBA}Стойка №%d+ | Полка №%d+") and work.stage == 1 then
        local function findLineIndex(dialog_text, pattern)
            local idx = 0
            for line in string.gmatch(dialog_text, "[^\r\n]+") do
                if line:find(pattern) then
                    return idx
                end
                idx = idx + 1
            end
            return nil
        end
        local fillIndex = findLineIndex(text, 'Залить охлаждающую жидкость')
        if fillIndex ~= nil then
            work.videocardMode = ""
            if text:find("BTC") then
                work.videocardMode = "btc"
            elseif text:find("ASC") then
                work.videocardMode = "asc"
            end
            sampSendDialogResponse(id, 1, fillIndex)
            work.stage = 2
            return true
        else
            table.remove(work.cardsToProcess, 1)
            work.currentCardIndex = -1
            work.stage = 0
            sampSendDialogResponse(id, 0)
            return true
        end
    end
    if title:find('{BFBBBA}Выберите тип жидкости') and work.stage == 2 then
        local fluidType = "None"
        if work.videocardMode == 'btc' then
            fluidType = "для видеокарты"
        elseif work.videocardMode == 'asc' then
            fluidType = "Охлаждающая жидкость для Arizona Video Card"
        end
        local found = false
        local idx = -1
        for line in string.gmatch(text, "[^\r\n]+") do
            if line:find(fluidType) then
                local count = tonumber(line:match("%[ (%d+) %]"))
                if count and count > 0 then
                    sampSendDialogResponse(id, 1, idx)
                    found = true
                    break
                end
            end
            idx = idx + 1
        end
        table.remove(work.cardsToProcess, 1)
        work.currentCardIndex = -1
        if not found then
            return deactivate("Скрипт деактивирован. Нет охлаждающей жидкости типа "..fluidType..".", true)
        end
        if #work.cardsToProcess > 0 then
            sampAddChatMessage('{99ff99}Cooling{ffffff}: Охлаждение залито. Осталось видеокарт: '..#work.cardsToProcess, -1)
            work.stage = 3
        else
            sampAddChatMessage('{99ff99}Cooling{ffffff}: Обход всех видеокарт завершён успешно.', -1)
            work.on = false
            work.stage = 0
        end
        return true
    end
end
хз, попробуй
не воркает