кфг луа

r3wZzzz

Участник
Автор темы
79
10
Как сделать, что бы при загрузке скрипта кфг создавался сам, что-бы там уже было написано то, что мне нужно, например rklad=false, и при нажатии на кнопку, в конфиге rklad менялся на true, если рендер включён, на false если выключен? Помогите пожалуйста




1:
local render = false

require "lib.moonloader"

local encoding = require "encoding"
encoding.default = "CP1251"
u8 = encoding.UTF8

font = renderCreateFont('Arial', 13, 5)

-- local main_window_state(v) = false

local sampev = require 'lib.samp.events'
local imgui = require "imgui"

local main_window_state = imgui.ImBool(false)
local text_buffer = imgui.ImBuffer(256)

local inicfg = require "inicfg"
local directIni = "moonloader\\newrender.ini"

local mainIni = inicfg.load(nil, directIni)

function imgui.OnDrawFrame()
  imgui.Begin(u8'123', main_window_state)
  imgui.Text(u8'123')
  if imgui.Button(u8"Клады") then
      
    rklad = not rklad
    mainIni.settings.rklad = true
    if inicfg.save(mainIni, directIni) then
    end

  end
  if imgui.Button(u8"Х1йня какая-то") then
      
    asdd = not asdd
    mainIni.settings.asdd = true
    if inicfg.save(mainIni, directIni) then
    end

  end
  imgui.End()
end

function main()

    while not isSampLoaded() do wait(0) end wait(1)

    sampAddChatMessage("Render Loaded", -1)
    sampRegisterChatCommand("nwr", renderwindow)
    sampRegisterChatCommand("getc", test_get)
    sampRegisterChatCommand("setc", test_set)
        
         imgui.Process = false

    while true do
        wait(0)

        if main_window_state.v == false then
            imgui.Process = false
        end
        if rklad then
            for _, v in pairs(getAllObjects()) do
                local asd
                if sampGetObjectSampIdByHandle(v) == 2680 then
                    asd = sampGetObjectSampIdByHandle(v)
                end
                if isObjectOnScreen(v) then
                    local result, oX, oY, oZ = getObjectCoordinates(v)
                    local x1, y1 = convert3DCoordsToScreen(oX,oY,oZ)
                    local objmodel = getObjectModel(v)
                    local x2,y2,z2 = getCharCoordinates(PLAYER_PED)
                    local x10, y10 = convert3DCoordsToScreen(x2,y2,z2)
                    distance = string.format("%.0f", getDistanceBetweenCoords3d(oX,oY,oZ, x2, y2, z2))
                    if objmodel == 2680 then renderDrawLine(x10, y10, x1, y1, 2, 0xFFFF00) renderFontDrawText(font,"{FFFFFF}Клад - {696969}"..distance, x1, y1, -1)
                end
            end
        end
    end
              -- 123
        if asdd then
            for _, v in pairs(getAllObjects()) do
                local qwe
                if sampGetObjectSampIdByHandle(v) == 11744 then
                    qwe = sampGetObjectSampIdByHandle(v)
                end
                if isObjectOnScreen(v) then
                    local result, oX, oY, oZ = getObjectCoordinates(v)
                    local x1, y1 = convert3DCoordsToScreen(oX,oY,oZ)
                    local objmodel = getObjectModel(v)
                    local x2,y2,z2 = getCharCoordinates(PLAYER_PED)
                    local x10, y10 = convert3DCoordsToScreen(x2,y2,z2)
                    distance = string.format("%.0f", getDistanceBetweenCoords3d(oX,oY,oZ, x2, y2, z2))
                    if objmodel == 11744 then renderDrawLine(x10, y10, x1, y1, 2, 0xFFFF00) renderFontDrawText(font,"{FFFFFF}Х1йня какая-то - {696969}"..distance, x1, y1, -1)
                end   
            end
        end
    end
end
end

function renderwindow()
    main_window_state.v = not main_window_state.v
    imgui.Process = main_window_state.v
end

function test_get(arg)
    mainIni = inicfg.load(nil, directIni)
    sampAddChatMessage(mainIni.settings.name, -1)
end

function test_set(arg)
   mainIni.settings.zalupa = arg
   if inicfg.save(mainIni, directIni) then
    sampAddChatMessage("+", -1)
   end
end
 
Решение
Lua:
local state = new.bool()

function save()
    ini.main.state = state
    inicfg.save(ini, directIni)
    sampAddChatMessage('save', -1)
end

--imgui
if imgui.Button('##123', imgui.ImVec2(100,50)) then state = not state save() end

--main, бесконечный цикл
state = ini.main.state

r3wZzzz

Участник
Автор темы
79
10
как пример
Lua:
--вверху
local inicfg = require("inicfg")
local directIni = ('config.ini')
local ini = inicfg.load(inicfg.load({
    main = {
        state = false
    },
}, directIni))
inicfg.save(ini, directIni)

-в теле мимгуи

if imgui.Button(##button) then ini.main.state = not ini.main.state end
При нажатии на кнопку имгуи в конфиге ничего не меняеться


 

r3wZzzz

Участник
Автор темы
79
10
Добавь: inicfg.save(ini, directIni)
Lua:
if imgui.Butoon(..) then .. inicfg.save(ini, directIni) end
пробовал, оно все равно не сохраняеться, мне нужно что бы false менялось на true, если галочка стоит, или наоборот
 

r3wZzzz

Участник
Автор темы
79
10
Lua:
local state = new.bool()

function save()
    ini.main.state = state
    inicfg.save(ini, directIni)
    sampAddChatMessage('save', -1)
end

--imgui
if imgui.Button('##123', imgui.ImVec2(100,50)) then state = not state save() end

--main, бесконечный цикл
state = ini.main.state
Спасибо, работает всё