Dialog

Jendosik

Участник
Автор темы
211
12
Версия MoonLoader
.027.0-preview
в чём оишибка должно выводить текст в имгуи из диалога

Lua:
require "lib.moonloader"
local imgui = require 'imgui'
local encoding = require 'encoding'
local inicfg = require 'inicfg'
local samp = require 'samp.events'
local main_color = 0x02274D
local main_color2 = 0x50BD27
local main_color1 = 0xE60020
local main_color3 = 0x138D75
encoding.default = 'CP1251'
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', cmd_vi)


    while true do
        wait(0)
         end
        end       



function samp.onShowDialog(dialogId, style, title, button1, button2, text)
    if sampIsDialogActive() then
        diaId = sampGetCurrentDialogId()
    end
        local result, _, _, diaText = sampHasDialogRespond(diaId)
        end
    -- end
-- end
-- end

function cmd_vi()
    main_window_state.v = not main_window_state.v
    imgui.Process = main_window_state.v
end
function imgui.OnDrawFrame()
if not main_window_state.v then
imgui.Process = false
end
if main_window_state.v then
    imgui.Begin('test', main_window_state)
    if result then
    imgui.Text(diaText)
end
    imgui.End()
end
end
 
Решение
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...

Albertio

Attention! Thanks for your attention.
887
717
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
 
  • Нравится
Реакции: Jendosik

Albertio

Attention! Thanks for your attention.
887
717
  • Нравится
Реакции: meowprd

meowprd

Тот самый Котовский
Проверенный
1,278
720
Всё сделано), моя ошибка, это я ему тот код подсказал
Да я только начал писать - смотрю ответ, а тут уже ты.
Шустро работаешь!
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

кста, зачем ему переменные типа main_color и inicfg?
А еще не понимаю зачем проверка:
Lua:
imgui.Process = main_window_state.v
if not main_window_state.v then
    imgui.Process = false
end

Ведь если main_window_state.v = false, то и imgui.Process = false
 
Последнее редактирование:
  • Влюблен
Реакции: Albertio