搜索 Lua 表格时出现多个消息和问题

我正在尝试为我所在的在线社区制作一个 Lua 脚本,当我试图搜索一个表格数组时出现了问题。它无法检测到我想要的结果。

它应该的工作方式是当有人输入“/gps [streetname]”时,它将搜索顶部的表格,检测匹配的街道名称和坐标,然后设置相关位置的航路点。

目前当表格中只有一个条目时,它能正常工作。但是当我添加了更多数据后,对于任何不匹配的街道会提供错误消息,对于匹配的街道则设置了航路点。我尝试过 Google,但似乎找不到任何可以帮助我的东西。

感谢任何帮助。

waypoint = {
  {404.08, -920.23, 'sinnerstreet', 'Sinner Street'},
  {360.85, -956.46, 'atleestreet', 'Atlee Street'},
  {500.48, -956.80, 'littlebighornavenue', 'Little Bighorn Avenue'},
}

RegisterCommand('gps', function(source, args, rawCommand)
  for k,v in pairs(waypoint) do
    x, y, streetname, displayname = table.unpack(v)
    results = ""

    if args[1] == nil then
      if IsWaypointActive() then
        SetWaypointOff()
        TriggerEvent('chatMessage', '^1^*GPS Navigation: ^r^7您的 GPS 系统已被重置。')
      return end
    elseif args[2] == nil and args[3] == nil then
      results = args[1]
    elseif args[2] ~= nil and args[3] == nil then
      results = args[1] .. args[2]
    else
      results = args[1] .. args[2] .. args[3]
    end

    results = string.lower(results) -- 这将 args 转换为小写
  end

  -- 这将定位街道名称并为玩家设置航路点
  if string.find(streetname, results) then
    SetNewWaypoint(x, y)
    TriggerEvent('chatMessage', '^1^*GPS Navigation: ^r^7已将航路点设置到 ^1' .. displayname .. '^r^7 上。')
  else
    TriggerEvent('chatMessage', '^1^*GPS Navigation: ^r^7您的街道名称出现错误,请重试。')
  end
end)

TriggerEvent('chat:addSuggestion', '/gps', '这将为您设定指定街道的航路点。^*用法:/gps [streetname]')
点赞