inicfg.save

Lertex

Участник
Автор темы
30
0
Версия MoonLoader
.027.0-preview
Пытался записать значение из игры в ini файл. Пишет мол сохранено, хотя значение остаётся тем же. Помогите пж
Код::
require "lib.moonloader"
local nick = "Nick_Name"
local font = renderCreateFont('Arial', 10, 5)
local inicfg = require 'inicfg'
local directIni = " moonloader/help.ini"
-- local stateIni = inicfg.save(mainIni, directIni)
local mainIni = inicfg.load(nil, directIni)

function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    while not isSampAvailable() do wait(0) end
    nick = sampGetPlayerNickname(select(2, sampGetPlayerIdByCharHandle(playerPed)))
    sampRegisterChatCommand("set_price", setPrice)
    sampRegisterChatCommand("lich", function()
        active = not active
        sampAddChatMessage('{C3C3C3}Помощь '..(active and '{6EF83C}включена, {FFAF00}by Lertex' or '{FF0000}выключена, {FFAF00}by Lertex'), -1)
        return active
    end)
    while true do wait(0)
        if active then
            renderFontDrawText(font, '{C3C3C3}Num0 - Приветствие\nNum1 - Покажи доки\nNum2 - Чек док\nNum3 - Спс за доки, бай\nNum4 - Наручники + конвой\nNum5 - Снять наручники + конвой\nNum6 - Погоня\nNum7 - В машину\nNum8 - Выдать розыск\nNum9 - В кпз\nAlt & Num0 - Штраф\nAlt & Num1 - Чек тонер(try)', 25, 345, 0xFFFFFFFF, 0x90000000)
            renderFontDrawText(font, '{C3C3C3}Alt & Num2 - Определение по фотороботу\nAlt & Num3 - обыск\nAlt & Num4 - Ордер на обыск\nAlt & Num5 - Снять аксы\nAlt & Num6 - Чек прицеп', 25, 535, 0xFFFFFFFF, 0x90000000)
        end
    end
end

require('samp.events').onServerMessage = function(color, text, message, messageType)
    lua_thread.create(function()
        if active then
            local pSMS, pName, pNumber = text:match("SMS%: (.+) %| Отправитель%: (.+) %[т%.(.+)%]")
            local cName, cNumber = text:match("")
            local cSMS = text:match("")
            print(pSMS, pName, pNumber)
            if pNumber == nil or pSMS == nil or pName == nil then
                wait(0)
            else
                sampAddChatMessage('1', -1)
            end
            if text:find(nick.." убрав канцелярские принадлежности в чемодан с документами, закрывает его") then
                wait(300)
                sampAddChatMessage('{6EF83C}AHK завершил свою работу', -1)
            end
            if text:match("%a+_%a+ Предлагает починить Ваш транспорт за (%d+) руб") then
                local price = tonumber(text:match("%a+_%a+ Предлагает починить Ваш транспорт за (%d+) руб"))
                wait(100)
                if price < check then
                    sampSendChat("/yes")
                    wait(400)
                    setVirtualKeyDown(13, true)
                    wait(100)
                    setVirtualKeyDown(13, false)
                    wait(100)
                    sampAddChatMessage('{6EF83C}Успешно!', -1)
                else
                    sampAddChatMessage('{FF0000}Выбор за вами!', -1)
                end
            end
        end
    end)
end

function setPrice(arg)
    if active == active then
        mainIni = inicfg.load(nil, directIni)
        sampAddChatMessage("{C3C3C3}Цена ремонта на данный момент - "..mainIni.PARAMS.check, -1)
        mainIni.PARAMS.check = arg
        if inicfg.save(mainIni, directIni) then
            sampAddChatMessage("{6EF83C}Цена была изменена на "..mainIni.PARAMS.check.." рублей", -1)
        else
            sampAddChatMessage("{FF0000}Ошибка!", -1)
        end
    end
end
Вот что в самом ini файле
Код:
[PARAMS]
check = 1000
 
Решение
Нет, наверное. Сделай ещё так, не знаю.
Сначала удали свой ini-файл.
В самом коде создай конфиг. Замени свой local mainIni = inicfg.load(nil, directIni) в начале кода на:
Lua:
local mainIni = inicfg.load({
    PARAMS = {
        check = "1000"
    }
}, "help.ini")
При сохранении используй inicfg.save(mainIni, "help.ini"). "help.ini" вместо directIni.

Dmitriy Makarov

25.05.2021
Проверенный
2,478
1,113
Что?
Ладно, сделай так и попробуй.
Lua:
function setPrice(arg)
    if active then
        sampAddChatMessage("{C3C3C3}Цена ремонта на данный момент - "..mainIni.PARAMS.check, -1)
        mainIni.PARAMS.check = arg
        inicfg.save(mainIni, directIni)
        sampAddChatMessage("{6EF83C}Цена была изменена на "..mainIni.PARAMS.check.." рублей", -1)
    end
end
 

Lertex

Участник
Автор темы
30
0
Что?
Ладно, сделай так и попробуй.
Lua:
function setPrice(arg)
    if active then
        sampAddChatMessage("{C3C3C3}Цена ремонта на данный момент - "..mainIni.PARAMS.check, -1)
        mainIni.PARAMS.check = arg
        inicfg.save(mainIni, directIni)
        sampAddChatMessage("{6EF83C}Цена была изменена на "..mainIni.PARAMS.check.." рублей", -1)
    end
end
В код добавил принт показывает что меняет, хотя открываю файл, но значение то же. Так и должно быть?
 
Последнее редактирование:

Dmitriy Makarov

25.05.2021
Проверенный
2,478
1,113
Нет, наверное. Сделай ещё так, не знаю.
Сначала удали свой ini-файл.
В самом коде создай конфиг. Замени свой local mainIni = inicfg.load(nil, directIni) в начале кода на:
Lua:
local mainIni = inicfg.load({
    PARAMS = {
        check = "1000"
    }
}, "help.ini")
При сохранении используй inicfg.save(mainIni, "help.ini"). "help.ini" вместо directIni.
 
  • Нравится
Реакции: Lertex