Крашит при реконекте Lua

Статус
В этой теме нельзя размещать новые ответы.

Bananious

Известный
Автор темы
238
17
Lua:
require 'lib.moonloader'

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampRegisterChatCommand("rec",reconnect)
    while true do
        wait(0)
        if rec == true then
            sampDisconnectWithReason(quit)
            wait(15500)
            sampSetGamestate(1)
            rec = false
        end
    end
end

function reconnect()
    if rec == false then
    rec = true
    end
end
 
Решение
Lua:
require 'lib.moonloader'

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampRegisterChatCommand("rec",reconnect)
    while true do
        wait(0)
        if rec == true then
            sampDisconnectWithReason(quit)
            wait(15500)
            sampSetGamestate(1)
            rec = false
        end
    end
end

function reconnect()
    if rec == false then
    rec = true
    end
end
sampDisconnectWithReason(quit)
Где обозначение переменной quit?

Можно сделать так:

Lua:
function main()
  sampRegisterChatCommand("rec",reconnect)
wait(-1)
end

function reconnect()
  local ip, port = sampGetCurrentServerAddress()...

|| NN - NoName ||

Известный
1,049
630
Lua:
require 'lib.moonloader'

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampRegisterChatCommand("rec",reconnect)
    while true do
        wait(0)
        if rec == true then
            sampDisconnectWithReason(quit)
            wait(15500)
            sampSetGamestate(1)
            rec = false
        end
    end
end

function reconnect()
    if rec == false then
    rec = true
    end
end
sampDisconnectWithReason(quit)
Где обозначение переменной quit?

Можно сделать так:

Lua:
function main()
  sampRegisterChatCommand("rec",reconnect)
wait(-1)
end

function reconnect()
  local ip, port = sampGetCurrentServerAddress()
  closeConnect()
  sampConnectToServer(ip, port)
end

function closeConnect()
    local bs = raknetNewBitStream()
    raknetEmulPacketReceiveBitStream(PACKET_DISCONNECTION_NOTIFICATION, bs)
    raknetDeleteBitStream(bs)
end

Дальше добавляешь задержку и т.д и т.п
 
Последнее редактирование:
  • Нравится
Реакции: TheUnity
Статус
В этой теме нельзя размещать новые ответы.