Прошу совета по скрипту ArizonaRp

PidrGriffin

Новичок
Автор темы
1
1
Версия MoonLoader
Другое
Автокапча переделанная самоучкой, хотел поставить закидывание удочки с кд, выдаёт такую ошибку:
Ошибка в потоке miniGame: moonloader\captcha.lua:16: attempt to call global 'setVirtualMouse' (a nil value)
есть варианты как исправить?

Lua:
local memory = require("memory")
local inicfg = require("inicfg")

local step = {200, 450}
local mouse_click_delay = {1000, 1500}

local tcap_enabled = false

local cfg = inicfg.load({
    main = {
        status = false
    }
}, 'tcap_config.ini')

function pressLeftMouseButtonWithDelay(delay)
    setVirtualMouse(1, 1)
    wait(delay)
    setVirtualMouse(1, 0)
end

function sendCustomPacket(text)
    local bs = raknetNewBitStream()
    raknetBitStreamWriteInt8(bs, 220)
    raknetBitStreamWriteInt8(bs, 18)
    raknetBitStreamWriteInt16(bs, #text)
    raknetBitStreamWriteString(bs, text)
    raknetBitStreamWriteInt32(bs, 0)
    raknetSendBitStream(bs)
    raknetDeleteBitStream(bs)
end

function cmd_toggle_tcap()
    tcap_enabled = not tcap_enabled
    cfg.main.status = tcap_enabled
    inicfg.save(cfg)

    if tcap_enabled then
        printStringNow("Captcha On.", 1500)
    else
        printStringNow("Captcha Off.", 1500)
    end
end

function onReceivePacket(id, bs)
    -- Добавляем отладочное сообщение, чтобы видеть, вызывается ли функция
    -- sampAddChatMessage("onReceivePacket called with ID: " .. id, -1)

    if id == 220 then
        raknetBitStreamIgnoreBits(bs, 8)
        if raknetBitStreamReadInt8(bs) == 17 then
            raknetBitStreamIgnoreBits(bs, 32)
            local length = raknetBitStreamReadInt16(bs)
            local encoded = raknetBitStreamReadInt8(bs)
            local str = (encoded ~= 0) and raknetBitStreamDecodeString(bs, length + encoded) or raknetBitStreamReadString(bs, length)

            if tcap_enabled then
                -- Оборачиваем логику в pcall для обработки ошибок в потоке
                local success, err = pcall(function()
                    if str:find([[window%.executeEvent%('event%.setActiveView', `%["FindGame"%]`%);]]) then
                        lua_thread.create(function ()
                            -- Обработка ошибок внутри потока
                            local thread_success, thread_err = pcall(function()
                                for i = 1, 5 do
                                    math.randomseed(os.clock() ^ i)
                                    wait(math.random(step[1], step[2]))
                                    sendCustomPacket('findGame.Success')
                                end
                                sendCustomPacket('findGame.finish')
                                printStringNow("FindGame пройдена.", 1000)

                                math.randomseed(os.clock())
                                wait(math.random(mouse_click_delay[1], mouse_click_delay[2]))
                                pressLeftMouseButtonWithDelay(50)
                            end)
                            if not thread_success then
                                sampAddChatMessage("Ошибка в потоке FindGame: " .. tostring(thread_err), -1)
                            end
                        end)
                        return false -- Пропускаем пакет
                    else
                        local countKeys = tonumber(str:match('"miniGameKeysCount":(%d+)'))
                        if countKeys then
                            lua_thread.create(function()
                                -- Обработка ошибок внутри потока
                                local thread_success, thread_err = pcall(function()
                                    for i = 1, countKeys do
                                        math.randomseed(os.clock() ^ i)
                                        wait(math.random(step[1], step[2]))
                                        sendCustomPacket('miniGame.DebugKeyID|74|74|true')
                                    end
                                    sendCustomPacket('miniGame.keyReaction.finish|' .. countKeys)
                                    printStringNow("miniGame пройдена.", 1000)

                                    math.randomseed(os.clock())
                                    wait(math.random(mouse_click_delay[1], mouse_click_delay[2]))
                                    pressLeftMouseButtonWithDelay(50)
                                end)
                                if not thread_success then
                                    sampAddChatMessage("Ошибка в потоке miniGame: " .. tostring(thread_err), -1)
                                end
                            end)
                            return false -- Пропускаем пакет
                        end
                    end
                end)
                if not success then
                    sampAddChatMessage("Критическая ошибка в onReceivePacket: " .. tostring(err), -1)
                    -- Можно попробовать сбросить tcap_enabled, если ошибка критическая
                    -- tcap_enabled = false
                    -- cfg.main.status = tcap_enabled
                    -- inicfg.save(cfg)
                    -- printStringNow("Captcha Off (Error).", 1500)
                end
            end
        end
    end
end

function main()
    while not isSampLoaded() do wait(0) end

    tcap_enabled = cfg.main.status

    sampRegisterChatCommand("tcap", cmd_toggle_tcap)
    sampAddChatMessage("CMD /tcap to turn on/off.", -1)

    if tcap_enabled then
        printStringNow("Captcha On.", 1500)
    end
end

main()
 
Последнее редактирование:
  • Нравится
Реакции: e11evated

Tema05

Известный
1,634
547
Автокапча переделанная самоучкой, хотел поставить закидывание удочки с кд, выдаёт такую ошибку:
Ошибка в потоке miniGame: moonloader\captcha.lua:16: attempt to call global 'setVirtualMouse' (a nil value)
есть варианты как исправить?

Lua:
local memory = require("memory")
local inicfg = require("inicfg")

local step = {200, 450}
local mouse_click_delay = {1000, 1500}

local tcap_enabled = false

local cfg = inicfg.load({
    main = {
        status = false
    }
}, 'tcap_config.ini')

function pressLeftMouseButtonWithDelay(delay)
    setVirtualMouse(1, 1)
    wait(delay)
    setVirtualMouse(1, 0)
end

function sendCustomPacket(text)
    local bs = raknetNewBitStream()
    raknetBitStreamWriteInt8(bs, 220)
    raknetBitStreamWriteInt8(bs, 18)
    raknetBitStreamWriteInt16(bs, #text)
    raknetBitStreamWriteString(bs, text)
    raknetBitStreamWriteInt32(bs, 0)
    raknetSendBitStream(bs)
    raknetDeleteBitStream(bs)
end

function cmd_toggle_tcap()
    tcap_enabled = not tcap_enabled
    cfg.main.status = tcap_enabled
    inicfg.save(cfg)

    if tcap_enabled then
        printStringNow("Captcha On.", 1500)
    else
        printStringNow("Captcha Off.", 1500)
    end
end

function onReceivePacket(id, bs)
    -- Добавляем отладочное сообщение, чтобы видеть, вызывается ли функция
    -- sampAddChatMessage("onReceivePacket called with ID: " .. id, -1)

    if id == 220 then
        raknetBitStreamIgnoreBits(bs, 8)
        if raknetBitStreamReadInt8(bs) == 17 then
            raknetBitStreamIgnoreBits(bs, 32)
            local length = raknetBitStreamReadInt16(bs)
            local encoded = raknetBitStreamReadInt8(bs)
            local str = (encoded ~= 0) and raknetBitStreamDecodeString(bs, length + encoded) or raknetBitStreamReadString(bs, length)

            if tcap_enabled then
                -- Оборачиваем логику в pcall для обработки ошибок в потоке
                local success, err = pcall(function()
                    if str:find([[window%.executeEvent%('event%.setActiveView', `%["FindGame"%]`%);]]) then
                        lua_thread.create(function ()
                            -- Обработка ошибок внутри потока
                            local thread_success, thread_err = pcall(function()
                                for i = 1, 5 do
                                    math.randomseed(os.clock() ^ i)
                                    wait(math.random(step[1], step[2]))
                                    sendCustomPacket('findGame.Success')
                                end
                                sendCustomPacket('findGame.finish')
                                printStringNow("FindGame пройдена.", 1000)

                                math.randomseed(os.clock())
                                wait(math.random(mouse_click_delay[1], mouse_click_delay[2]))
                                pressLeftMouseButtonWithDelay(50)
                            end)
                            if not thread_success then
                                sampAddChatMessage("Ошибка в потоке FindGame: " .. tostring(thread_err), -1)
                            end
                        end)
                        return false -- Пропускаем пакет
                    else
                        local countKeys = tonumber(str:match('"miniGameKeysCount":(%d+)'))
                        if countKeys then
                            lua_thread.create(function()
                                -- Обработка ошибок внутри потока
                                local thread_success, thread_err = pcall(function()
                                    for i = 1, countKeys do
                                        math.randomseed(os.clock() ^ i)
                                        wait(math.random(step[1], step[2]))
                                        sendCustomPacket('miniGame.DebugKeyID|74|74|true')
                                    end
                                    sendCustomPacket('miniGame.keyReaction.finish|' .. countKeys)
                                    printStringNow("miniGame пройдена.", 1000)

                                    math.randomseed(os.clock())
                                    wait(math.random(mouse_click_delay[1], mouse_click_delay[2]))
                                    pressLeftMouseButtonWithDelay(50)
                                end)
                                if not thread_success then
                                    sampAddChatMessage("Ошибка в потоке miniGame: " .. tostring(thread_err), -1)
                                end
                            end)
                            return false -- Пропускаем пакет
                        end
                    end
                end)
                if not success then
                    sampAddChatMessage("Критическая ошибка в onReceivePacket: " .. tostring(err), -1)
                    -- Можно попробовать сбросить tcap_enabled, если ошибка критическая
                    -- tcap_enabled = false
                    -- cfg.main.status = tcap_enabled
                    -- inicfg.save(cfg)
                    -- printStringNow("Captcha Off (Error).", 1500)
                end
            end
        end
    end
end

function main()
    while not isSampLoaded() do wait(0) end

    tcap_enabled = cfg.main.status

    sampRegisterChatCommand("tcap", cmd_toggle_tcap)
    sampAddChatMessage("CMD /tcap to turn on/off.", -1)

    if tcap_enabled then
        printStringNow("Captcha On.", 1500)
    end
end

main()
setVirtualMouse не существует