do -- reconnect
local _reconnectThread
-- d - задержка
reconnect = function(d)
-- first, disconnect
sampSetGamestate(GAMESTATE_DISCONNECTED)
sampDisconnectWithReason(0)
-- delete all textdraws
for i = 0, 2304 do
if sampTextdrawIsExists(i) then
sampTextdrawDelete(i)
end
end
-- close dialog if open
if sampIsDialogActive() then
sampCloseCurrentDialogWithButton(0)
end
-- clear chat
if settings.multiconnect.reconnect.clear_chat then
local ChatInfoPtr = sampGetChatInfoPtr()
local ChatEntryPtr = ChatInfoPtr + 306
memory.fill(ChatEntryPtr, 0x0, 25200)
memory.write(ChatInfoPtr + 25562, 0x1, 4)
end
-- make thread for delay available
if _reconnectThread and _reconnectThread:status() ~= "dead" then _reconnectThread:terminate() end
_reconnectThread = lua_thread.create(function()
-- wait delay
local target_time = timeGetTime() + (d * 1000)
while timeGetTime() < target_time do
printStringNow("~g~Reconnect in ~b~" .. tostring(math.ceil((target_time - timeGetTime()) / 1000)), 10)
wait(10)
end
printStringNow("~g~Reconnecting...", 3500)
wait(0)
-- reconnect
sampSetGamestate(GAMESTATE_WAIT_CONNECT)
--sampConnectToServer(sip, sport)
end)
end
end