Проблема с сохранением в inicfg

lightmetal

Участник
Автор темы
32
3
Версия MoonLoader
.026-beta
Подскажите что не так делаю. Конфиг создаётся, но он не применяется. Вот захожу в игру, он создаётся
1711714818152.png

но он не как не реагирует на действия. Меняю значение чекбокса,в Testt.ini значение меняется, но не применяется.
Если выключен - false , включен - true . Но если перезайти, значение будет true , но чекбокс выключен. В чём моя ошибка?
1711714845344.png
1711715877520.png


Выделил код отвечающий за это.
Код:
require 'moonloader'
local imgui = require 'mimgui'
local inicfg = require 'inicfg'
local sampev = require('lib.samp.events')
local encoding = require 'encoding'
encoding.default = 'CP1251'
local u8 = encoding.UTF8
local new = imgui.new

local settings = inicfg.load({
        main = {
        active_script = false,
        }
    }, 'Test.ini');


local tab = 1
local WinState = imgui.new.bool()
local active_script = imgui.new.bool(settings.main.active_script)

imgui.OnFrame(function() return WinState[0] end, function(player)
    imgui.SetNextWindowPos(imgui.ImVec2(500, 500), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(700, 420), imgui.Cond.Always)
    imgui.Begin(u8'Пример', WinState, imgui.WindowFlags.NoResize)
   
    imgui.BeginChild('##left', imgui.ImVec2(160, 365), true)
    for numberTab, nameTab in pairs({'Основное','Настройки','Инфа', 'Тест', 'Тест2',  'Тест3'}) do
        if imgui.Button(u8(nameTab), imgui.ImVec2(148,55)) then
            tab = numberTab
        end
    end
    imgui.EndChild()
    imgui.SameLine()
     imgui.SetCursorPos(imgui.ImVec2(170, 30))
     if imgui.BeginChild('right'..tab, imgui.ImVec2(510, 365), true) then
        -- Содержимое вкладок
        if tab == 1 then
        if imgui.Checkbox(u8'Быстрый инвайт', active_script) then
            settings.main.active_script = active_script[0]
            inicfg.save(settings, 'Testt.ini')
        end
        imgui.Checkbox(u8'Быстрое увольнение', active_scriptuval)
        imgui.Checkbox(u8'Тест1', active_scriptU)
        imgui.Checkbox(u8'Тест2', active_scriptUU)
        imgui.Checkbox(u8'Тест3', active_scriptUUU)
        imgui.Checkbox(u8'Тест4', active_scriptUUUU)
        end
    end
end)


    function main()
        if not isSampLoaded() or not isSampfuncsLoaded() then return end
        while not isSampAvailable() do wait(100) end
        sampRegisterChatCommand('ghelperrr', function() WinState[0] = not WinState[0] end)
        while true do
            wait(0)
            if active_script[0] then
                if wasKeyPressed(0x31) and not sampIsChatInputActive() and not sampIsDialogActive() then
                    local result, ped = getCharPlayerIsTargeting(PLAYER_HANDLE)
                    if result then
                        _, id = sampGetPlayerIdByCharHandle(ped)
                        sampSendChat('/me передал бандану')
                        wait(1000)
                        sampSendChat('/givecbook '..id..' 100')
                        wait(100)
                        sampSendChat('/invite '..id)
                        setVirtualKeyDown(13, true)
                        wait(100)
                        setVirtualKeyDown(13, false)
   
                        if accept and t:find("(%S+)_(%S+) принял ваше предложение вступить к вам в организацию.") then
                            sampSendChat("/giverank "..id.." 6")
                            accept = false
                        end
                        accept = true
                    end
                end      
            end
        end
    end


И вообще так можно делать? что у меня функция и ини с одним значением(active_script)
 
Решение
Lua:
require('moonloader')
local sampev = require('lib.samp.events')
local inicfg = require('inicfg')
local imgui = require('mimgui')

local encoding = require('encoding')
encoding.default = 'CP1251'
local u8 = encoding.UTF8

local new = imgui.new
local sc_name, tab = 'Test.ini', 1
local WinState = new.bool()

local settings = inicfg.load({
    main = {
        active_script = false,
    }
}, sc_name);
local active_script = imgui.new.bool(settings.main.active_script)

imgui.OnFrame(function() return WinState[0] end, function(player)
    imgui.SetNextWindowPos(imgui.ImVec2(500, 500), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(700, 420), imgui.Cond.Always)
    imgui.Begin(u8'Пример', WinState...

MLycoris

Режим чтения
Проверенный
1,822
1,869
сохраняешь в конфиг с названием Testt.ini, а пытаешься подгрузить кфг с Test.ini (14 строка)
ещё скорее всего у тебя будет крашить игра, тк ты не добавил буфер остальным чекбоксам

И вообще так можно делать? что у меня функция и ини с одним значением(active_script)
да, как по мне это удобно
 
Последнее редактирование:
  • Нравится
Реакции: lightmetal и qdIbp

qdIbp

Автор темы
Проверенный
1,387
1,143
Lua:
require('moonloader')
local sampev = require('lib.samp.events')
local inicfg = require('inicfg')
local imgui = require('mimgui')

local encoding = require('encoding')
encoding.default = 'CP1251'
local u8 = encoding.UTF8

local new = imgui.new
local sc_name, tab = 'Test.ini', 1
local WinState = new.bool()

local settings = inicfg.load({
    main = {
        active_script = false,
    }
}, sc_name);
local active_script = imgui.new.bool(settings.main.active_script)

imgui.OnFrame(function() return WinState[0] end, function(player)
    imgui.SetNextWindowPos(imgui.ImVec2(500, 500), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(700, 420), imgui.Cond.Always)
    imgui.Begin(u8'Пример', WinState, imgui.WindowFlags.NoResize)
        imgui.BeginChild('##left', imgui.ImVec2(160, -1), true)
            for numberTab, nameTab in pairs({'Основное','Настройки','Инфа', 'Тест', 'Тест2',  'Тест3'}) do
                if imgui.Button(u8(nameTab), imgui.ImVec2(148,55)) then
                    tab = numberTab
                end
            end
        imgui.EndChild()
        imgui.SameLine()
        imgui.SetCursorPos(imgui.ImVec2(170, 30))
        imgui.BeginChild('right'..tab, imgui.ImVec2(510, -1), true) -- Содержимое вкладок
            if tab == 1 then
                if imgui.Checkbox(u8'Быстрый инвайт', active_script) then
                    settings.main.active_script = active_script[0]
                    inicfg.save(settings, sc_name)
                end
            end
        imgui.EndChild()
    imgui.End()
end)


function main()
    repeat wait(100) until isSampAvailable()
    sampRegisterChatCommand('ghelperrr', function()
        WinState[0] = not WinState[0]
    end)
    while true do
        wait(0)
        if active_script[0] and not sampIsChatInputActive() and not sampIsDialogActive() then
            if wasKeyPressed(0x31) then
                local result, ped = getCharPlayerIsTargeting(PLAYER_HANDLE)
                if result then
                    local result, id = sampGetPlayerIdByCharHandle(ped)
                    if result then
                        sampSendChat('/me передал бандану')
                        wait(1000)
                        sampSendChat('/givecbook '..id..' 100')
                        wait(100)
                        sampSendChat('/invite '..id)
                        setVirtualKeyDown(13, true)
                        wait(100)
                        setVirtualKeyDown(13, false)
                    end
                    if accept and string.match(t, "(%S+)_(%S+) принял ваше предложение вступить к вам в организацию.") then
                        sampSendChat( string.format('/giverank %d 6', id) )
                        accept = false
                    end
                    accept = true
                end
            end       
        end
    end
end
 
  • Нравится
Реакции: lightmetal