Сохранение в inicfg

LightPops

Новичок
Автор темы
19
1
Как сделать так, чтоб этот код сохранялся в inicfg?
КоDIck:
local sampev = require 'lib.samp.events'

local statsCMI = imgui.new.int(0)

function sampev.onServerMessage(color, text)
    if text:find('Вы получили $(%d+,%d+) за отредактированое вами объявление.') then
        statsCMI[0] = statsCMI[0] + 1
    end
end


imgui.Text('Объявлений всего: '..statsCMI[0])
 

Vespan

loneliness
Проверенный
2,104
1,635
 
  • Нравится
Реакции: qdIbp

recxvery

Участник
90
27
Как сделать так, чтоб этот код сохранялся в inicfg?
КоDIck:
local sampev = require 'lib.samp.events'

local statsCMI = imgui.new.int(0)

function sampev.onServerMessage(color, text)
    if text:find('Вы получили $(%d+,%d+) за отредактированое вами объявление.') then
        statsCMI[0] = statsCMI[0] + 1
    end
end


imgui.Text('Объявлений всего: '..statsCMI[0])
Lua:
local sampev        = require('lib.samp.events')
local imgui         = require('mimgui')
local inicfg        = require('inicfg')

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

local iniFilename = 'MassMediaStats.ini'
local ini = inicfg.load({
    stats = {
        ads = 0
    }
}, iniFilename)
inicfg.save(ini, iniFilename)

local menu = imgui.new.bool()

function main()
    while not isSampAvailable() do wait(0) end

    sampAddChatMessage('[ MassMedia Stats ] {FFFFFF}Скрипт успешно загружен. Активация: /mstats', 0xFF8C00)

    sampRegisterChatCommand('mstats', function()
        menu[0] = not menu[0]
    end)

    wait(-1)
end

function sampev.onServerMessage(color, text)
    if text:find('Вы получили %$(.+) за отредактированое вами объявление.') then
        ini.stats.ads = ini.stats.ads + 1
        inicfg.save(ini, iniFilename)
    end
end

imgui.OnFrame(function() return menu[0] end, function(window)

    window.HideCursor = true

    local size, res = imgui.ImVec2(250, 30), imgui.ImVec2(getScreenResolution())
    imgui.SetNextWindowSize(size)
    imgui.SetNextWindowPos(imgui.ImVec2(res.x / 2, res.y / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))

    if (imgui.Begin('##MassMediaStats', menu, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoTitleBar)) then
        imgui.CenterText('Отредактировано всего объявлений: ' .. ini.stats.ads)
    end
    imgui.End()
    end
)

function imgui.CenterText(text)
    imgui.SetCursorPosX(imgui.GetWindowWidth()/2-imgui.CalcTextSize(u8(text)).x/2);
    imgui.Text(u8(text));
end
Если зачем-то захочешь закрывать его по ESC, то в конец кода вставь:
Lua:
function onWindowMessage(m, p)
    if p == 0x1B and menu[0] then
        consumeWindowMessage()
        menu[0] = false
    end
end