require "moonloader"
local inicfg = require 'inicfg'
local cfg = inicfg.load({ ip = {} }, "servers")
function main()
if not isSampLoaded() or not isSampfuncsLoaded() then return end
while not isSampAvailable() do wait(2000) end
if not doesFileExist(getWorkingDirectory().."\\config\\servers.ini") then
inicfg.save(cfg, 'servers.ini')
end
sampRegisterChatCommand('addcurrent', function() -- добавление текущего IP сервера в конфиг
local ip, _ = sampGetCurrentServerAddress()
table.insert(cfg.ip, ip) -- добавление ip в массив конфига
if inicfg.save(cfg, 'servers.ini') then
sampAddChatMessage('Текущий сервер ('.. ip ..') добавлен в конфиг', -1)
end
end)
sampRegisterChatCommand('addip', function(ip) -- Добавление сервера в конфиг по IP
if ip:match('(%d+)%.(%d+)%.(%d+)%.(%d+)') then
table.insert(cfg.ip, ip)
if inicfg.save(cfg, 'servers.ini') then
sampAddChatMessage('IP: '.. ip ..' добавлен в конфиг', -1)
end
else
sampAddChatMessage('Вводи IP а не свой пароль от домофона додик', -1)
end
end)
-- при входе в игру
ip, _ = sampGetCurrentServerAddress() -- получаем IP сервера при входе
if ip then -- если Ip нашелся..
for k, v in pairs(cfg.ip) do -- проверяем циклом, наличие найденого IP в нашем конфиге
if v == ip then -- если сервер был найден в нашем конфиге то..
sampAddChatMessage('Вы зашли на сервер, который был указан в конфиге', -1)
end
end
end
while true do
wait(0)
end
end