Два аргумента в одной команде

BlackCherry

Известный
Автор темы
193
32
Версия MoonLoader
.026-beta
Нужно что бы при вводе команды /connect ip port подключалось к определённому серверу.
Lua:
function main()
  if not isSampLoaded() or not isSampfuncsLoaded() then return end
  while not isSampAvailable() do wait(100) end
  sampRegisterChatCommand("connect", connect)
  wait(-1)
end

function connect(ip, port)
  if #ip and #port == 0 then
        sampAddChatMessage("укажите аргумент к команде /connect ip port", -1)
  else
        sampAddChatMessage("Подключаемся к "..ip..":"..port.."", -1)
        wait(1000)
        sampConnectToServer(ip, port)
  end
end
 
Решение
Нужно что бы при вводе команды /connect ip port подключалось к определённому серверу.
Lua:
function main()
  if not isSampLoaded() or not isSampfuncsLoaded() then return end
  while not isSampAvailable() do wait(100) end
  sampRegisterChatCommand("connect", connect)
  wait(-1)
end

function connect(ip, port)
  if #ip and #port == 0 then
        sampAddChatMessage("укажите аргумент к команде /connect ip port", -1)
  else
        sampAddChatMessage("Подключаемся к "..ip..":"..port.."", -1)
        wait(1000)
        sampConnectToServer(ip, port)
  end
end
Lua:
function main()
  if not isSampLoaded() or not isSampfuncsLoaded() then return end
  while not isSampAvailable() do wait(100) end
  sampRegisterChatCommand("connect"...

CaJlaT

Овощ
Модератор
2,806
2,608
Нужно что бы при вводе команды /connect ip port подключалось к определённому серверу.
Lua:
function main()
  if not isSampLoaded() or not isSampfuncsLoaded() then return end
  while not isSampAvailable() do wait(100) end
  sampRegisterChatCommand("connect", connect)
  wait(-1)
end

function connect(ip, port)
  if #ip and #port == 0 then
        sampAddChatMessage("укажите аргумент к команде /connect ip port", -1)
  else
        sampAddChatMessage("Подключаемся к "..ip..":"..port.."", -1)
        wait(1000)
        sampConnectToServer(ip, port)
  end
end
Lua:
function main()
  if not isSampLoaded() or not isSampfuncsLoaded() then return end
  while not isSampAvailable() do wait(100) end
  sampRegisterChatCommand("connect", connect)
  wait(-1)
end

function connect(server)
    if #server == 0 then
        sampAddChatMessage("укажите аргумент к команде /connect ip port", -1)
    else
        lua_thread.create(function()
            local ip, port = server:match('(.+) (%d+)')
            if #port == 0 or port == nil then port = 7777 end
            sampAddChatMessage("Подключаемся к "..ip..":"..port.."", -1)
            wait(1000)
            sampConnectToServer(ip, port)
        end)
    end
end
 
Последнее редактирование:
  • Нравится
Реакции: BlackCherry

BlackCherry

Известный
Автор темы
193
32
Lua:
function main()
  if not isSampLoaded() or not isSampfuncsLoaded() then return end
  while not isSampAvailable() do wait(100) end
  sampRegisterChatCommand("connect", connect)
  wait(-1)
end

function connect(server)
    if #server == 0 then
        sampAddChatMessage("укажите аргумент к команде /connect ip port", -1)
    else
        lua_thread.create(function()
            local ip, port = server:match('(.+) (%d+)')
            if #port == 0 or port == nil then port == 7777
            sampAddChatMessage("Подключаемся к "..ip..":"..port.."", -1)
            wait(1000)
            sampConnectToServer(ip, port)
        end)
    end
end
[13:27:24.885600] (error) serverconnect.lua: ...s\ARIZONA GAMES\bin\Arizona\moonloader\serverconnect.lua:14: '=' expected near '=='
[13:27:24.885600] (error) serverconnect.lua: Script died due to an error. (2EFB4BD4)
 

CaJlaT

Овощ
Модератор
2,806
2,608
[13:27:24.885600] (error) serverconnect.lua: ...s\ARIZONA GAMES\bin\Arizona\moonloader\serverconnect.lua:14: '=' expected near '=='
[13:27:24.885600] (error) serverconnect.lua: Script died due to an error. (2EFB4BD4)
замени строчку на if #port == 0 or port == nil then port = 7777
 

BlackCherry

Известный
Автор темы
193
32
замени строчку на if #port == 0 or port == nil then port = 7777
[13:30:41.884599] (error) serverconnect.lua: ...s\ARIZONA GAMES\bin\Arizona\moonloader\serverconnect.lua:18: unexpected symbol near ')'
[13:30:41.884599] (error) serverconnect.lua: Script died due to an error. (1ABAD904)
 

BlackCherry

Известный
Автор темы
193
32
на этой же стночке допиши end 🤣🤣🤣🤣
if #port == 0 or port == nil then port = 7777 end
Я посмотрел код, тут если нету порта должен дописываться 7777, правильно?

Если да то -
[13:39:05.268457] (error) serverconnect.lua: ...s\ARIZONA GAMES\bin\Arizona\moonloader\serverconnect.lua:14: attempt to get length of local 'port' (a nil value)
stack traceback:
...s\ARIZONA GAMES\bin\Arizona\moonloader\serverconnect.lua: in function <...s\ARIZONA GAMES\bin\Arizona\moonloader\serverconnect.lua:12>
stack traceback:
[C]: in function 'create'
...s\ARIZONA GAMES\bin\Arizona\moonloader\serverconnect.lua:12: in function <...s\ARIZONA GAMES\bin\Arizona\moonloader\serverconnect.lua:8>
[13:39:05.269457] (error) serverconnect.lua: Script died due to an error. (3138CEB4)