Вывод диалога в имгуи

Seaside_

Участник
Автор темы
64
2
Версия MoonLoader
.026-beta
Как сделать чтобы определенная информация из диалога выходила в окно имгуи? Допустим, я хочу проверить свою статистику и узнать опыт и хочу чтобы мой уровень и опыт вывелся в окно имгуи.
 

Izvinisb

Известный
Проверенный
964
598
Как сделать чтобы определенная информация из диалога выходила в окно имгуи? Допустим, я хочу проверить свою статистику и узнать опыт и хочу чтобы мой уровень и опыт вывелся в окно имгуи.
Хукать диалог, регуляркой получать нужные значения и выводить в имгуи imguiText(переменная)
 

Jendosik

Участник
211
12
Приведи пж пример как делать
Lua:
require "lib.moonloader"
local imgui = require 'imgui'
local encoding = require 'encoding'
local inicfg = require 'inicfg'
local samp = require 'lib.samp.events'
local main_color = 0x02274D
local main_color2 = 0x50BD27
local main_color1 = 0xE60020
local main_color3 = 0x138D75
encoding.default = 'CP1251'
local u8 = encoding.UTF8

local main_window_state = imgui.ImBool(false)

function main()
  if not isSampLoaded() and not isSampfuncsLoaded() then return end
  while not isSampAvailable() do wait(100) end
  sampRegisterChatCommand('vi', function() main_window_state.v = not main_window_state.v end)
  while true do
    wait(0)
    imgui.Process = main_window_state.v
    if not main_window_state.v then
      imgui.Process = false
    end
  end
end

function samp.onShowDialog(dialogId, style, title, button1, button2, text)
  diaText = text
end

function imgui.OnDrawFrame()
  if main_window_state.v then
    imgui.ShowCursor = true
    imgui.SetNextWindowPos(imgui.ImVec2(imgui.GetIO().DisplaySize.x / 2, imgui.GetIO().DisplaySize.y / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(300, 300), imgui.Cond.FirstUseEver)
    imgui.Begin('test', main_window_state)
    if diaText then
      imgui.Text(u8(diaText))
    end
    imgui.End()
  end
end
Выводит текст последнего закрытого диалога
 

Seaside_

Участник
Автор темы
64
2
Lua:
require "lib.moonloader"
local imgui = require 'imgui'
local encoding = require 'encoding'
local inicfg = require 'inicfg'
local samp = require 'lib.samp.events'
local main_color = 0x02274D
local main_color2 = 0x50BD27
local main_color1 = 0xE60020
local main_color3 = 0x138D75
encoding.default = 'CP1251'
local u8 = encoding.UTF8

local main_window_state = imgui.ImBool(false)

function main()
  if not isSampLoaded() and not isSampfuncsLoaded() then return end
  while not isSampAvailable() do wait(100) end
  sampRegisterChatCommand('vi', function() main_window_state.v = not main_window_state.v end)
  while true do
    wait(0)
    imgui.Process = main_window_state.v
    if not main_window_state.v then
      imgui.Process = false
    end
  end
end

function samp.onShowDialog(dialogId, style, title, button1, button2, text)
  diaText = text
end

function imgui.OnDrawFrame()
  if main_window_state.v then
    imgui.ShowCursor = true
    imgui.SetNextWindowPos(imgui.ImVec2(imgui.GetIO().DisplaySize.x / 2, imgui.GetIO().DisplaySize.y / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(300, 300), imgui.Cond.FirstUseEver)
    imgui.Begin('test', main_window_state)
    if diaText then
      imgui.Text(u8(diaText))
    end
    imgui.End()
  end
end
Выводит текст последнего закрытого диалога
Как сделать чтобы определённую строку и опредедённый текст выводил?
 

back.DEV

Известный
71
6
Хочу чтобы самп эвент читал определенный диалог, определенные строки и выводил их в имгуи окно.
для каждого текста есть своя регулярка, нету примера который подойдет ко всему
 

andrey_hacker

Известный
274
88
Для примера рассмотрим диалог статистики:
oW25kEF.png

Допустим, мы хотим получить из этого диалога уровень игрока. За основу возьму твой код.

Lua:
require "lib.moonloader"
local imgui = require 'imgui'
local encoding = require 'encoding'
local inicfg = require 'inicfg'
local samp = require 'lib.samp.events'
local main_color = 0x02274D
local main_color2 = 0x50BD27
local main_color1 = 0xE60020
local main_color3 = 0x138D75
encoding.default = 'CP1251'
local u8 = encoding.UTF8

local main_window_state = imgui.ImBool(false)

function main()
  if not isSampLoaded() and not isSampfuncsLoaded() then return end
  while not isSampAvailable() do wait(100) end
  sampRegisterChatCommand('vi', function() main_window_state.v = not main_window_state.v end)
  while true do
    wait(0)
    imgui.Process = main_window_state.v
    if not main_window_state.v then
      imgui.Process = false
    end
  end
end

function samp.onShowDialog(dialogId, style, title, button1, button2, text)
  diaText = text
  -- через регулярку найдет строку с уровнем
  if dialogId == *id диалога статистики* and text:find('Уровень:%s+[(%d+)%]$') then --если показан диалог статистики и там есть строка с уровнем, тогда:
  -- добудем значение уровня
      level = text:match('Уровень:%s+[(%d+)%]$')
  end

end

function imgui.OnDrawFrame()
  if main_window_state.v then
    imgui.ShowCursor = true
    imgui.SetNextWindowPos(imgui.ImVec2(imgui.GetIO().DisplaySize.x / 2, imgui.GetIO().DisplaySize.y / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(300, 300), imgui.Cond.FirstUseEver)
    imgui.Begin('test', main_window_state)
    if diaText then
        -- выведем значение уровня в текс Имгуи
      imgui.Text(u8('Ваш уровень: '.. level))
    end
    imgui.End()
  end
end
что за проверка на diaText, зачем она, она же проверит, есть ли вообще текст в любом диалоге ?