Узнать ид строчки диалога по тексту.

Firus20016

Участник
Автор темы
148
15
Версия MoonLoader
.025-beta
Как в диалоге найти номер строчки, в которой название "{B0E73A}Вперед >>>"?
47122
 

Firus20016

Участник
Автор темы
148
15
поделить все на строки. проверить последний элемент на название, записать номер элемента и отнять один
Это я уже понял, но не понял как реализовать. Нашел такой способ, но не понял, что тут под "123" подразумевается.

Lua:
function sampev.onShowDialog(dialogId, style, title, button1, button2, text)

    local index = 0

    for line in text:gmatch("[^\n]*\n?") do -- line будет включать также "\n" вконце строки
        if title:match("123") then
            if line:match("Ищем это") then
                sampSendDialogResponse(dialogid, 1, index , -1)
                break
            end
            index = index+1
        end

    end
end
 

AnWu

Guardian of Order
Всефорумный модератор
4,686
5,166
Это я уже понял, но не понял как реализовать. Нашел такой способ, но не понял, что тут под "123" подразумевается.

Lua:
function sampev.onShowDialog(dialogId, style, title, button1, button2, text)

    local index = 0

    for line in text:gmatch("[^\n]*\n?") do -- line будет включать также "\n" вконце строки
        if title:match("123") then
            if line:match("Ищем это") then
                sampSendDialogResponse(dialogid, 1, index , -1)
                break
            end
            index = index+1
        end

    end
end
Замени match на find, везде. 123 это заголовок диалога
 

Firus20016

Участник
Автор темы
148
15
Замени match на find, везде. 123 это заголовок диалога
Выдаёт смэрт.
[ML] (error) CheckListFam: ... GameWorld - GTA San Andreas\moonloader\checklistfam.lua:46: attempt to call a string value
[ML] (error) CheckListFam: Script died due to error. (210B9144)
 

AnWu

Guardian of Order
Всефорумный модератор
4,686
5,166

Firus20016

Участник
Автор темы
148
15
потому-что кидай код не картинкой а текстом. Перепишу
Кинул полностью функцию

Lua:
function sampev.onShowDialog(id, style, title, button1, button2, text)
    if check == 1 then
        if id == 2920 then
            lua_thread.create(function()
              sampSendDialogResponse(id, 1, 2, -1)
          end)
      end
        if id == 0 then
            FileWrite = io.open(FileNameWrite, "w")
            FileWrite:write(text)
          sampAddChatMessage("OK", -100000)
            sampCloseCurrentDialogWithButton(0)
            lua_thread.create(function()
              sampSendChat('/fammenu')
          end)
            check = 2
        end
    end
    if check == 2 then
        if id == 2920 then
            lua_thread.create(function()
              sampSendDialogResponse(id, 1, 3, -1)
            end)
        end
        if id == 2931 then
            lua_thread.create(function()
            for line in text:gmatch("[^\n]*\n?") do -- line будет включать также "\n" вконце строки
        if title:find("{BFBBBA}Участники семьи (оффлайн)") then
            if line:find("{B0E73A}Вперед >>>") then
                sampSendDialogResponse(id, 1, index , -1)
                                sampAddChatMessage("sasa", -100)
                break
            end
            index = index+1
         end
       end
         end)
     end
  end
end
 

AnWu

Guardian of Order
Всефорумный модератор
4,686
5,166
Кинул полностью функцию

Lua:
function sampev.onShowDialog(id, style, title, button1, button2, text)
    if check == 1 then
        if id == 2920 then
            lua_thread.create(function()
              sampSendDialogResponse(id, 1, 2, -1)
          end)
      end
        if id == 0 then
            FileWrite = io.open(FileNameWrite, "w")
            FileWrite:write(text)
          sampAddChatMessage("OK", -100000)
            sampCloseCurrentDialogWithButton(0)
            lua_thread.create(function()
              sampSendChat('/fammenu')
          end)
            check = 2
        end
    end
    if check == 2 then
        if id == 2920 then
            lua_thread.create(function()
              sampSendDialogResponse(id, 1, 3, -1)
            end)
        end
        if id == 2931 then
            lua_thread.create(function()
            for line in text:gmatch("[^\n]*\n?") do -- line будет включать также "\n" вконце строки
        if title:find("{BFBBBA}Участники семьи (оффлайн)") then
            if line:find("{B0E73A}Вперед >>>") then
                sampSendDialogResponse(id, 1, index , -1)
                                sampAddChatMessage("sasa", -100)
                break
            end
            index = index+1
         end
       end
         end)
     end
  end
end
Lua:
function split(str, delim, plain)
  local tokens, pos, plain = {}, 1, not (plain == false) --[[ delimiter is plain text by default ]]
  repeat
      local npos, epos = string.find(str, delim, pos, plain)
      table.insert(tokens, string.sub(str, pos, npos and npos - 1))
      pos = epos and epos + 1
  until not pos
  return tokens
end

function sampev.onShowDialog(id, style, title, button1, button2, text)
    if check == 1 then
        if id == 2920 then
            sampSendDialogResponse(id, 1, 2, -1)
      end
        if id == 0 then
            FileWrite = io.open(FileNameWrite, "w")
            FileWrite:write(text)
          sampAddChatMessage("OK", -100000)
            sampCloseCurrentDialogWithButton(0)
            lua_thread.create(function()
              sampSendChat('/fammenu')
          end)
          check = 2
        end
    end
    if check == 2 then
        if id == 2920 then
            sampSendDialogResponse(id, 1, 3, -1)
        end
        if id == 2931 then
          local tLines = split(text, "\n")
          if tLines[#tLines]:find("{B0E73A}Вперед >>>", 1, true) then
            sampSendDialogResponse(id, 1, #tLines-1 , "")
          end
       end
     end
  end
end
 

Firus20016

Участник
Автор темы
148
15
Lua:
function split(str, delim, plain)
  local tokens, pos, plain = {}, 1, not (plain == false) --[[ delimiter is plain text by default ]]
  repeat
      local npos, epos = string.find(str, delim, pos, plain)
      table.insert(tokens, string.sub(str, pos, npos and npos - 1))
      pos = epos and epos + 1
  until not pos
  return tokens
end

function sampev.onShowDialog(id, style, title, button1, button2, text)
    if check == 1 then
        if id == 2920 then
            sampSendDialogResponse(id, 1, 2, -1)
      end
        if id == 0 then
            FileWrite = io.open(FileNameWrite, "w")
            FileWrite:write(text)
          sampAddChatMessage("OK", -100000)
            sampCloseCurrentDialogWithButton(0)
            lua_thread.create(function()
              sampSendChat('/fammenu')
          end)
          check = 2
        end
    end
    if check == 2 then
        if id == 2920 then
            sampSendDialogResponse(id, 1, 3, -1)
        end
        if id == 2931 then
          local tLines = split(text, "\n")
          if tLines[#tLines]:find("{B0E73A}Вперед >>>", 1, true) then
            sampSendDialogResponse(id, 1, #tLines-1 , "")
          end
       end
     end
  end
end
К сожалению, кнопка далее не нажалась, либо она не нашлась. (end лишний убрал)
 

AnWu

Guardian of Order
Всефорумный модератор
4,686
5,166
К сожалению, кнопка далее не нажалась, либо она не нашлась. (end лишний убрал)
Lua:
function split(str, delim, plain)
  local tokens, pos, plain = {}, 1, not (plain == false) --[[ delimiter is plain text by default ]]
  repeat
      local npos, epos = string.find(str, delim, pos, plain)
      table.insert(tokens, string.sub(str, pos, npos and npos - 1))
      pos = epos and epos + 1
  until not pos
  return tokens
end

function sampev.onShowDialog(id, style, title, button1, button2, text)
  if check == 1 then
    if id == 2920 then
      sampSendDialogResponse(id, 1, 2, -1)
    end
    if id == 0 then
      FileWrite = io.open(FileNameWrite, "w")
      FileWrite:write(text)
      sampAddChatMessage("OK", -100000)
      sampCloseCurrentDialogWithButton(0)
      sampSendChat('/fammenu')
      check = 2
    end
  end
  if check == 2 then
    if id == 2920 then
      sampSendDialogResponse(id, 1, 3, -1)
    end
    if id == 2931 then
      local tLines = split(text, "\n")
      if tLines[#tLines]:find("{B0E73A}Вперед >>>", 1, true) then
        sampSendDialogResponse(id, 1, #tLines-1 , "")
      end
    end
  end
end
 

Firus20016

Участник
Автор темы
148
15
Lua:
function split(str, delim, plain)
  local tokens, pos, plain = {}, 1, not (plain == false) --[[ delimiter is plain text by default ]]
  repeat
      local npos, epos = string.find(str, delim, pos, plain)
      table.insert(tokens, string.sub(str, pos, npos and npos - 1))
      pos = epos and epos + 1
  until not pos
  return tokens
end

function sampev.onShowDialog(id, style, title, button1, button2, text)
  if check == 1 then
    if id == 2920 then
      sampSendDialogResponse(id, 1, 2, -1)
    end
    if id == 0 then
      FileWrite = io.open(FileNameWrite, "w")
      FileWrite:write(text)
      sampAddChatMessage("OK", -100000)
      sampCloseCurrentDialogWithButton(0)
      sampSendChat('/fammenu')
      check = 2
    end
  end
  if check == 2 then
    if id == 2920 then
      sampSendDialogResponse(id, 1, 3, -1)
    end
    if id == 2931 then
      local tLines = split(text, "\n")
      if tLines[#tLines]:find("{B0E73A}Вперед >>>", 1, true) then
        sampSendDialogResponse(id, 1, #tLines-1 , "")
      end
    end
  end
end
Теперь окно диалога появляется и становиться неактивным (кнопки и строчки нажимаются, но не несут последствий) id диалога = 2931