LUA | Привязка к IP

Markelov9999

Участник
Автор темы
73
2
Версия MoonLoader
Другое
Всех приветствую.

Сделал привязку по IP адресу к серверу.
Захожу на сервер к которому привязал скрипт. По итогу выводит текст который выгружает скрипт.

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

local function checkip()
local ip, port = sampGetCurrentServerAddress()
for key, value in pairs(ips) do
if value == ip..':'..port then
if value == '46.174.50.45:7788' then
local result
print('test')
end
end
servername = key
return true
end
end
sampAddChatMessage('Данный скрипт привязан к серверам проекта: {FF0000} Союз RolePlay' .. main_color_text .. ', произошла выгрузка.', main_color)
thisScript():unload();

ChatLog:

Код:
[17:41:25] Данный скрипт привязан к серверам проекта: {FF0000} Союз RolePlay{4682B4}, произошла выгрузка.

[17:41:25] [Admin Tools]: Admin tools успешно зарегистрирован

SampFuncs:

Код:
[ML] (system) Loading script 'C:\Users\troin\Desktop\GTA WINTER POLICE EDITION\moonloader\new.lua'...
[ML] (system) Admin Tools: Loaded successfully.
 
Решение
Lua:
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    
    if not checkip() then
        sampAddChatMessage('Данный скрипт привязан к серверам проекта: {FF0000} Союз RolePlay, произошла выгрузка.', -1)
        thisScript():unload()
    else sampAddChatMessage('Скрипт загружен успешно.',-1)
    end

    while true do
    wait(-1)

    end
end


function checkip()
    local ip, port = sampGetCurrentServerAddress()
    for key, value in pairs(ips) do
        if value == ip..':'..port then
            if value == '46.174.50.45:7788' then
                servername = key
                return true
            end
        end
    end
    return false...

Manuel Leon

Известный
266
166
Lua:
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    
    if not checkip() then
        sampAddChatMessage('Данный скрипт привязан к серверам проекта: {FF0000} Союз RolePlay, произошла выгрузка.', -1)
        thisScript():unload()
    else sampAddChatMessage('Скрипт загружен успешно.',-1)
    end

    while true do
    wait(-1)

    end
end


function checkip()
    local ip, port = sampGetCurrentServerAddress()
    for key, value in pairs(ips) do
        if value == ip..':'..port then
            if value == '46.174.50.45:7788' then
                servername = key
                return true
            end
        end
    end
    return false
end
Выгрузка скрипта и вывод сообщения вне функции - 1.
return true вне проверки - 2
 

Markelov9999

Участник
Автор темы
73
2
SampFuncs:
[ML] (error) Admin Tools: ...oin\Desktop\GTA WINTER POLICE EDITION\moonloader\new.lua:22: bad argument #1 to 'pairs' (table expected, got nil)
stack traceback:
    [C]: in function 'pairs'
    ...oin\Desktop\GTA WINTER POLICE EDITION\moonloader\new.lua:22: in function 'checkip'
    ...oin\Desktop\GTA WINTER POLICE EDITION\moonloader\new.lua:37: in function <...oin\Desktop\GTA WINTER POLICE EDITION\moonloader\new.lua:33>
[ML] (error) Admin Tools: Script died due to an error. (01C734FC)

Lua script:
script_name('Admin Tools')
script_author('Лев Троцкий')
script_version(1.0)

require "lib.moonloader"
local keys = require 'vkeys'
local imgui = require 'imgui'

local tag = ' [Admin Tools]:'
local label = 1
local main_color = 0x4682B4
local main_color_text = '{4682B4}'
local white_color = '{FFFFFF}'



function checkip()
    local ip, port = sampGetCurrentServerAddress()
    for key, value in pairs(ips) do
        if value == ip..':'..port then
            if value == '46.174.50.45:7788' then
                servername = key
                return true
            end
        end
    end
    return false
end

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

if not checkip() then
        sampAddChatMessage('Скрипт был успешно: {FF0000} Выгружен.' .. main_color_text .. ' Данный скрипт привязан к серверам проекта: {FF0000} Союз RolePlay', main_color)
        thisScript():unload()
    else sampAddChatMessage('Скрипт был успешно: {00FF00}загружен.' .. main_color_text .. ' Приятного администрирования на проекте: {00FF00}Союз RolePlay.',main_color)
    end
while true do
    wait(-1)

    end
end

Теперь крашит
 

Manuel Leon

Известный
266
166
SampFuncs:
[ML] (error) Admin Tools: ...oin\Desktop\GTA WINTER POLICE EDITION\moonloader\new.lua:22: bad argument #1 to 'pairs' (table expected, got nil)
stack traceback:
    [C]: in function 'pairs'
    ...oin\Desktop\GTA WINTER POLICE EDITION\moonloader\new.lua:22: in function 'checkip'
    ...oin\Desktop\GTA WINTER POLICE EDITION\moonloader\new.lua:37: in function <...oin\Desktop\GTA WINTER POLICE EDITION\moonloader\new.lua:33>
[ML] (error) Admin Tools: Script died due to an error. (01C734FC)

Lua script:
script_name('Admin Tools')
script_author('Лев Троцкий')
script_version(1.0)

require "lib.moonloader"
local keys = require 'vkeys'
local imgui = require 'imgui'

local tag = ' [Admin Tools]:'
local label = 1
local main_color = 0x4682B4
local main_color_text = '{4682B4}'
local white_color = '{FFFFFF}'



function checkip()
    local ip, port = sampGetCurrentServerAddress()
    for key, value in pairs(ips) do
        if value == ip..':'..port then
            if value == '46.174.50.45:7788' then
                servername = key
                return true
            end
        end
    end
    return false
end

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

if not checkip() then
        sampAddChatMessage('Скрипт был успешно: {FF0000} Выгружен.' .. main_color_text .. ' Данный скрипт привязан к серверам проекта: {FF0000} Союз RolePlay', main_color)
        thisScript():unload()
    else sampAddChatMessage('Скрипт был успешно: {00FF00}загружен.' .. main_color_text .. ' Приятного администрирования на проекте: {00FF00}Союз RolePlay.',main_color)
    end
while true do
    wait(-1)

    end
end

Теперь крашит
Таблицу то создай с IP
Таблицу то создай с IP
Lua:
local ips =
{
    ['Server 1'] = '46.174.50.45:7788',
    ['Server 2'] = 'ip:port'
}
К переменным вставь
 

Shepi

Активный
178
37
Lua:
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
   
    if not checkip() then
        sampAddChatMessage('Данный скрипт привязан к серверам проекта: {FF0000} Союз RolePlay, произошла выгрузка.', -1)
        thisScript():unload()
    else sampAddChatMessage('Скрипт загружен успешно.',-1)
    end

    while true do
    wait(-1)

    end
end


function checkip()
    local ip, port = sampGetCurrentServerAddress()
    for key, value in pairs(ips) do
        if value == ip..':'..port then
            if value == '46.174.50.45:7788' then
                servername = key
                return true
            end
        end
    end
    return false
end
Выгрузка скрипта и вывод сообщения вне функции - 1.
return true вне проверки - 2
Что если изначально скрипт работает, вне зависимости от айпи сервера, а если перезагрузить все скрипты, то уже не работает на других серверах?
 

Markelov9999

Участник
Автор темы
73
2
Что если изначально скрипт работает, вне зависимости от айпи сервера, а если перезагрузить все скрипты, то уже не работает на других серверах?
Создай новую тему и лог SampFuncs прикладывай всегда