Off when disconnected

James Hawk

Известный
Автор темы
919
217
Как-то уже сталкивался с такой проблемой, но она появилась снова. Отключение от сервера не происходит
Lua:
local hook = require 'lib.samp.events'

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
   
    sampRegisterChatCommand("off", function()
        flag = not flag
        if flag then
            sampAddChatMessage(string.format("[%s]: started",thisScript().name), 0x40FF40)
        else
            sampAddChatMessage(string.format("[%s]: stoped",thisScript().name), 0xFF4040)
        end
    end)
    while true do wait(0) end
end

function hook.onServerMessage(color,msg)
    if flag then
        if string.find(msg, "Server closed the connection.") or string.find(msg, "The server didn't respond.") then
            lua_thread.create(function()
                wait(1000)
                sampProcessChatInput('/q')
            end)
        end
    end
end
 

James Hawk

Известный
Автор темы
919
217
Само сообщение server closed the coonection. не серверное. А hook.onServerMessage хукает серверные сообщения
Я вот такую штуку тоже пробовал
Lua:
function hook.onConnectionRejected(reason)
    if flag then
        sampProcessChatInput('/q')
    end
end


Актуально