imgui помогите

Oki_Bern

Участник
Автор темы
196
6
Lua:
local ffi = require('ffi');
local imgui = require('mimgui');
local encoding = require('encoding');
encoding.default = 'CP1251';
local u8 = encoding.UTF8;

local window = imgui.new.bool(false);
local active = imgui.new.bool(false);
local text = imgui.new.char[64]('Hello world!');

imgui.OnInitialize(function()
    imgui.GetIO().IniFilename = nil;
end)

imgui.OnFrame(
    function() return window[0] end,
    function(this)
        local size, res = imgui.ImVec2(450, 250), imgui.ImVec2(getScreenResolution());
        imgui.SetNextWindowPos(imgui.ImVec2(res.x / 2, res.y / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5));
        imgui.SetNextWindowSize(size, imgui.Cond.FirstUseEver);
        if imgui.Begin('test window', window, imgui.WindowFlags.NoCollapse) then
            if (imgui.Checkbox(u8'Статус работы', active)) then
                sampAddChatMessage('Чекбокс ' .. (active[0] and 'включен' or 'выключен'), -1);
            end
            imgui.InputText(u8'Текст', text, ffi.sizeof(text));
            if (imgui.Button(u8'Добавить сообщение в чат')) then
                sampAddChatMessage(u8:decode(ffi.string(text)), -1);
            end
            imgui.End();
        end
    end
)

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('mimgui_toggle', function()
        window[0] = not window[0];
    end)
    while true do
        wait(500)
        if (active[0]) then
            sampAddChatMessage(u8:decode(ffi.string(text)), -1);
        end
    end
end
можно ли как то сделать, чтоб когда в игре меняешь слова на другое оно сохраняется и после перезагрузки скрипта не изменялось на начальное
 
Последнее редактирование:
Решение
можешь подсказать что тут не так, мб я дебил и вообще по другому надо было делать.
был код:
Lua:
local ffi = require('ffi');
local imgui = require('mimgui');
local encoding = require('encoding');
encoding.default = 'CP1251';
local u8 = encoding.UTF8;

local window = imgui.new.bool(false);
local active = imgui.new.bool(false);
local text = imgui.new.char[64]('Hello world!');

imgui.OnInitialize(function()
    imgui.GetIO().IniFilename = nil;
end)

imgui.OnFrame(
    function() return window[0] end,
    function(this)
        local size, res = imgui.ImVec2(450, 250), imgui.ImVec2(getScreenResolution());
        imgui.SetNextWindowPos(imgui.ImVec2(res.x / 2, res.y / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))...

Hinаta

Известный
780
358
1699886876210.png

это mimgui
можно ли как то сделать, чтоб когда в игре меняешь слова на другое оно сохраняется и после перезагрузки скрипта не изменялось на начальное
да, можно, используя inicfg
 

Hinаta

Известный
780
358
а как это сделать
 

Dmitriy Makarov

25.05.2021
Проверенный
2,490
1,120
Lua:
-- К библиотекам.
local inicfg = require "inicfg"

-- К переменным. Желательно ДО них, ибо некоторые переменные будут брать отсюда информацию.
local mainIni = inicfg.load({
    config = {
        text = "Hello World"
    }
}, "settings.ini")
inicfg.save(mainIni, "settings.ini") -- Чтобы конфиг сразу создался.

-- Под "local mainIni".
local text = imgui.new.char[64](u8(mainIni.config.text)) -- Тут берёшь информацию из конфига и вставляешь в InputText.

-- OnFrame
if imgui.InputText(u8'Текст', text, ffi.sizeof(text)) then
    mainIni.config.text = u8:decode(ffi.string(text)) -- Перезапись текста из конфига.
    inicfg.save(mainIni, "settings.ini") -- Сохранение.
end
 
  • Нравится
Реакции: Oki_Bern, minxty и Hinаta

Oki_Bern

Участник
Автор темы
196
6
Lua:
-- К библиотекам.
local inicfg = require "inicfg"

-- К переменным. Желательно ДО них, ибо некоторые переменные будут брать отсюда информацию.
local mainIni = inicfg.load({
    config = {
        text = "Hello World"
    }
}, "settings.ini")
inicfg.save(mainIni, "settings.ini") -- Чтобы конфиг сразу создался.

-- Под "local mainIni".
local text = imgui.new.char[64](u8(mainIni.config.text)) -- Тут берёшь информацию из конфига и вставляешь в InputText.

-- OnFrame
if imgui.InputText(u8'Текст', text, ffi.sizeof(text)) then
    mainIni.config.text = u8:decode(ffi.string(text)) -- Перезапись текста из конфига.
    inicfg.save(mainIni, "settings.ini") -- Сохранение.
end
можешь подсказать что тут не так, мб я дебил и вообще по другому надо было делать.
был код:
Lua:
local ffi = require('ffi');
local imgui = require('mimgui');
local encoding = require('encoding');
encoding.default = 'CP1251';
local u8 = encoding.UTF8;

local window = imgui.new.bool(false);
local active = imgui.new.bool(false);
local text = imgui.new.char[64]('Hello world!');

imgui.OnInitialize(function()
    imgui.GetIO().IniFilename = nil;
end)

imgui.OnFrame(
    function() return window[0] end,
    function(this)
        local size, res = imgui.ImVec2(450, 250), imgui.ImVec2(getScreenResolution());
        imgui.SetNextWindowPos(imgui.ImVec2(res.x / 2, res.y / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5));
        imgui.SetNextWindowSize(size, imgui.Cond.FirstUseEver);
        if imgui.Begin('test window', window, imgui.WindowFlags.NoCollapse) then
            if (imgui.Checkbox(u8'Статус работы', active)) then
                sampAddChatMessage('Чекбокс ' .. (active[0] and 'включен' or 'выключен'), -1);
            end
            imgui.InputText(u8'Текст', text, ffi.sizeof(text));
            if (imgui.Button(u8'Добавить сообщение в чат')) then
                sampAddChatMessage(u8:decode(ffi.string(text)), -1);
            end
            imgui.End();
        end
    end
)

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('mimgui_toggle', function()
        window[0] = not window[0];
    end)
    while true do
        wait(500)
        if (active[0]) then
            sampAddChatMessage(u8:decode(ffi.string(text)), -1);
        end
    end
end
сделал
Lua:
local inicfg = require "inicfg"
local mainIni = inicfg.load({
    config = {
        text = "Hello World"
    }
}, "settings.ini")
inicfg.save(mainIni, "settings.ini") -- Чтобы конфиг сразу создался.

-- Под "local mainIni".
local text = imgui.new.char[64](u8(mainIni.config.text)) -- Тут берёшь информацию из конфига и вставляешь в InputText.

-- OnFrame
if imgui.InputText(u8'Текст', text, ffi.sizeof(text)) then
    mainIni.config.text = u8:decode(ffi.string(text)) -- Перезапись текста из конфига.
    inicfg.save(mainIni, "settings.ini") -- Сохранение.
end
local ffi = require('ffi');
local imgui = require('mimgui');
local encoding = require('encoding');
encoding.default = 'CP1251';
local u8 = encoding.UTF8;
local text = imgui.new.char[64]('Hello world!');

local window = imgui.new.bool(false);
local active = imgui.new.bool(false);

imgui.OnInitialize(function()
    imgui.GetIO().IniFilename = nil;
end)

imgui.OnFrame(
    function() return window[0] end,
    function(this)
        local size, res = imgui.ImVec2(450, 250), imgui.ImVec2(getScreenResolution());
        imgui.SetNextWindowPos(imgui.ImVec2(res.x / 2, res.y / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5));
        imgui.SetNextWindowSize(size, imgui.Cond.FirstUseEver);
        if imgui.Begin('test window', window, imgui.WindowFlags.NoCollapse) then
            if (imgui.Checkbox(u8'Статус работы', active)) then
                sampAddChatMessage('Чекбокс ' .. (active[0] and 'включен' or 'выключен'), -1);
            end
            imgui.InputText(u8'Текст', text, ffi.sizeof(text));
            if (imgui.Button(u8'Добавить сообщение в чат')) then
                sampAddChatMessage(u8:decode(ffi.string(text)), -1);
            end
            imgui.End();
        end
    end
)

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('mimgui_toggle', function()
        window[0] = not window[0];
    end)
    while true do
        wait(500)
        if (active[0]) then
            sampAddChatMessage(u8:decode(ffi.string(mainIni)), -1);
        end
    end
end
и не робит, файл в конфиге есть
 

minxty

Известный
1,057
894
можешь подсказать что тут не так, мб я дебил и вообще по другому надо было делать.
был код:
Lua:
local ffi = require('ffi');
local imgui = require('mimgui');
local encoding = require('encoding');
encoding.default = 'CP1251';
local u8 = encoding.UTF8;

local window = imgui.new.bool(false);
local active = imgui.new.bool(false);
local text = imgui.new.char[64]('Hello world!');

imgui.OnInitialize(function()
    imgui.GetIO().IniFilename = nil;
end)

imgui.OnFrame(
    function() return window[0] end,
    function(this)
        local size, res = imgui.ImVec2(450, 250), imgui.ImVec2(getScreenResolution());
        imgui.SetNextWindowPos(imgui.ImVec2(res.x / 2, res.y / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5));
        imgui.SetNextWindowSize(size, imgui.Cond.FirstUseEver);
        if imgui.Begin('test window', window, imgui.WindowFlags.NoCollapse) then
            if (imgui.Checkbox(u8'Статус работы', active)) then
                sampAddChatMessage('Чекбокс ' .. (active[0] and 'включен' or 'выключен'), -1);
            end
            imgui.InputText(u8'Текст', text, ffi.sizeof(text));
            if (imgui.Button(u8'Добавить сообщение в чат')) then
                sampAddChatMessage(u8:decode(ffi.string(text)), -1);
            end
            imgui.End();
        end
    end
)

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('mimgui_toggle', function()
        window[0] = not window[0];
    end)
    while true do
        wait(500)
        if (active[0]) then
            sampAddChatMessage(u8:decode(ffi.string(text)), -1);
        end
    end
end
сделал
Lua:
local inicfg = require "inicfg"
local mainIni = inicfg.load({
    config = {
        text = "Hello World"
    }
}, "settings.ini")
inicfg.save(mainIni, "settings.ini") -- Чтобы конфиг сразу создался.

-- Под "local mainIni".
local text = imgui.new.char[64](u8(mainIni.config.text)) -- Тут берёшь информацию из конфига и вставляешь в InputText.

-- OnFrame
if imgui.InputText(u8'Текст', text, ffi.sizeof(text)) then
    mainIni.config.text = u8:decode(ffi.string(text)) -- Перезапись текста из конфига.
    inicfg.save(mainIni, "settings.ini") -- Сохранение.
end
local ffi = require('ffi');
local imgui = require('mimgui');
local encoding = require('encoding');
encoding.default = 'CP1251';
local u8 = encoding.UTF8;
local text = imgui.new.char[64]('Hello world!');

local window = imgui.new.bool(false);
local active = imgui.new.bool(false);

imgui.OnInitialize(function()
    imgui.GetIO().IniFilename = nil;
end)

imgui.OnFrame(
    function() return window[0] end,
    function(this)
        local size, res = imgui.ImVec2(450, 250), imgui.ImVec2(getScreenResolution());
        imgui.SetNextWindowPos(imgui.ImVec2(res.x / 2, res.y / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5));
        imgui.SetNextWindowSize(size, imgui.Cond.FirstUseEver);
        if imgui.Begin('test window', window, imgui.WindowFlags.NoCollapse) then
            if (imgui.Checkbox(u8'Статус работы', active)) then
                sampAddChatMessage('Чекбокс ' .. (active[0] and 'включен' or 'выключен'), -1);
            end
            imgui.InputText(u8'Текст', text, ffi.sizeof(text));
            if (imgui.Button(u8'Добавить сообщение в чат')) then
                sampAddChatMessage(u8:decode(ffi.string(text)), -1);
            end
            imgui.End();
        end
    end
)

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('mimgui_toggle', function()
        window[0] = not window[0];
    end)
    while true do
        wait(500)
        if (active[0]) then
            sampAddChatMessage(u8:decode(ffi.string(mainIni)), -1);
        end
    end
end
и не робит, файл в конфиге есть
как минимум, нету сохранения кфгшки, или же inicfg.save(mainIni, "settings.ini")
 

Dmitriy Makarov

25.05.2021
Проверенный
2,490
1,120
можешь подсказать что тут не так, мб я дебил и вообще по другому надо было делать.
был код:
Lua:
local ffi = require('ffi');
local imgui = require('mimgui');
local encoding = require('encoding');
encoding.default = 'CP1251';
local u8 = encoding.UTF8;

local window = imgui.new.bool(false);
local active = imgui.new.bool(false);
local text = imgui.new.char[64]('Hello world!');

imgui.OnInitialize(function()
    imgui.GetIO().IniFilename = nil;
end)

imgui.OnFrame(
    function() return window[0] end,
    function(this)
        local size, res = imgui.ImVec2(450, 250), imgui.ImVec2(getScreenResolution());
        imgui.SetNextWindowPos(imgui.ImVec2(res.x / 2, res.y / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5));
        imgui.SetNextWindowSize(size, imgui.Cond.FirstUseEver);
        if imgui.Begin('test window', window, imgui.WindowFlags.NoCollapse) then
            if (imgui.Checkbox(u8'Статус работы', active)) then
                sampAddChatMessage('Чекбокс ' .. (active[0] and 'включен' or 'выключен'), -1);
            end
            imgui.InputText(u8'Текст', text, ffi.sizeof(text));
            if (imgui.Button(u8'Добавить сообщение в чат')) then
                sampAddChatMessage(u8:decode(ffi.string(text)), -1);
            end
            imgui.End();
        end
    end
)

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('mimgui_toggle', function()
        window[0] = not window[0];
    end)
    while true do
        wait(500)
        if (active[0]) then
            sampAddChatMessage(u8:decode(ffi.string(text)), -1);
        end
    end
end
сделал
Lua:
local inicfg = require "inicfg"
local mainIni = inicfg.load({
    config = {
        text = "Hello World"
    }
}, "settings.ini")
inicfg.save(mainIni, "settings.ini") -- Чтобы конфиг сразу создался.

-- Под "local mainIni".
local text = imgui.new.char[64](u8(mainIni.config.text)) -- Тут берёшь информацию из конфига и вставляешь в InputText.

-- OnFrame
if imgui.InputText(u8'Текст', text, ffi.sizeof(text)) then
    mainIni.config.text = u8:decode(ffi.string(text)) -- Перезапись текста из конфига.
    inicfg.save(mainIni, "settings.ini") -- Сохранение.
end
local ffi = require('ffi');
local imgui = require('mimgui');
local encoding = require('encoding');
encoding.default = 'CP1251';
local u8 = encoding.UTF8;
local text = imgui.new.char[64]('Hello world!');

local window = imgui.new.bool(false);
local active = imgui.new.bool(false);

imgui.OnInitialize(function()
    imgui.GetIO().IniFilename = nil;
end)

imgui.OnFrame(
    function() return window[0] end,
    function(this)
        local size, res = imgui.ImVec2(450, 250), imgui.ImVec2(getScreenResolution());
        imgui.SetNextWindowPos(imgui.ImVec2(res.x / 2, res.y / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5));
        imgui.SetNextWindowSize(size, imgui.Cond.FirstUseEver);
        if imgui.Begin('test window', window, imgui.WindowFlags.NoCollapse) then
            if (imgui.Checkbox(u8'Статус работы', active)) then
                sampAddChatMessage('Чекбокс ' .. (active[0] and 'включен' or 'выключен'), -1);
            end
            imgui.InputText(u8'Текст', text, ffi.sizeof(text));
            if (imgui.Button(u8'Добавить сообщение в чат')) then
                sampAddChatMessage(u8:decode(ffi.string(text)), -1);
            end
            imgui.End();
        end
    end
)

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('mimgui_toggle', function()
        window[0] = not window[0];
    end)
    while true do
        wait(500)
        if (active[0]) then
            sampAddChatMessage(u8:decode(ffi.string(mainIni)), -1);
        end
    end
end
и не робит, файл в конфиге есть
Так я же в комментариях объяснил, что куда надо вставлять.
Lua:
local ffi = require('ffi');
local imgui = require('mimgui');
local encoding = require('encoding');
local inicfg = require "inicfg"
encoding.default = 'CP1251';
local u8 = encoding.UTF8;

local mainIni = inicfg.load({
    config = {
        text = "Hello World"
    }
}, "settings.ini")
inicfg.save(mainIni, "settings.ini")

local window = imgui.new.bool(false);
local active = imgui.new.bool(false);
local text = imgui.new.char[64](u8(mainIni.config.text));

imgui.OnInitialize(function()
    imgui.GetIO().IniFilename = nil;
end)

imgui.OnFrame(
    function() return window[0] end,
    function(this)
        local size, res = imgui.ImVec2(450, 250), imgui.ImVec2(getScreenResolution());
        imgui.SetNextWindowPos(imgui.ImVec2(res.x / 2, res.y / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5));
        imgui.SetNextWindowSize(size, imgui.Cond.FirstUseEver);
        if imgui.Begin('test window', window, imgui.WindowFlags.NoCollapse) then
            if (imgui.Checkbox(u8'Статус работы', active)) then
                sampAddChatMessage('Чекбокс ' .. (active[0] and 'включен' or 'выключен'), -1);
            end
            if imgui.InputText(u8'Текст', text, ffi.sizeof(text)) then
                mainIni.config.text = u8:decode(ffi.string(text))
                inicfg.save(mainIni, "settings.ini")
            end
            if (imgui.Button(u8'Добавить сообщение в чат')) then
                sampAddChatMessage(u8:decode(ffi.string(text)), -1);
            end
            imgui.End();
        end
    end
)

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('mimgui_toggle', function()
        window[0] = not window[0];
    end)
    while true do
        wait(500)
        if (active[0]) then
            sampAddChatMessage(u8:decode(ffi.string(text)), -1);
        end
    end
end
 
  • Нравится
Реакции: Oki_Bern

MLycoris

Режим чтения
Проверенный
1,873
1,976
тут в примере 2.1 есть сохранение инпута
 
  • Нравится
Реакции: Oki_Bern