Вопросы по Lua скриптингу

Общая тема для вопросов по разработке скриптов на языке программирования Lua, в частности под MoonLoader.
  • Задавая вопрос, убедитесь, что его нет в списке частых вопросов и что на него ещё не отвечали (воспользуйтесь поиском).
  • Поищите ответ в теме посвященной разработке Lua скриптов в MoonLoader
  • Отвечая, убедитесь, что ваш ответ корректен.
  • Старайтесь как можно точнее выразить мысль, а если проблема связана с кодом, то обязательно прикрепите его к сообщению, используя блок [code=lua]здесь мог бы быть ваш код[/code].
  • Если вопрос связан с MoonLoader-ом первым делом желательно поискать решение на wiki.

Частые вопросы

Как научиться писать скрипты? С чего начать?
Информация - Гайд - Всё о Lua скриптинге для MoonLoader(https://blast.hk/threads/22707/)
Как вывести текст на русском? Вместо русского текста у меня какие-то каракули.
Изменить кодировку файла скрипта на Windows-1251. В Atom: комбинация клавиш Ctrl+Shift+U, в Notepad++: меню Кодировки -> Кодировки -> Кириллица -> Windows-1251.
Как получить транспорт, в котором сидит игрок?
Lua:
local veh = storeCarCharIsInNoSave(PLAYER_PED)
Как получить свой id или id другого игрока?
Lua:
local _, id = sampGetPlayerIdByCharHandle(PLAYER_PED) -- получить свой ид
local _, id = sampGetPlayerIdByCharHandle(ped) -- получить ид другого игрока. ped - это хендл персонажа
Как проверить, что строка содержит какой-то текст?
Lua:
if string.find(str, 'текст', 1, true) then
-- строка str содержит "текст"
end
Как эмулировать нажатие игровой клавиши?
Lua:
local game_keys = require 'game.keys' -- где-нибудь в начале скрипта вне функции main

setGameKeyState(game_keys.player.FIREWEAPON, -1) -- будет сэмулировано нажатие клавиши атаки
Все иды клавиш находятся в файле moonloader/lib/game/keys.lua.
Подробнее о функции setGameKeyState здесь: lua - setgamekeystate | BlastHack — DEV_WIKI(https://www.blast.hk/wiki/lua:setgamekeystate)
Как получить id другого игрока, в которого целюсь я?
Lua:
local valid, ped = getCharPlayerIsTargeting(PLAYER_HANDLE) -- получить хендл персонажа, в которого целится игрок
if valid and doesCharExist(ped) then -- если цель есть и персонаж существует
  local result, id = sampGetPlayerIdByCharHandle(ped) -- получить samp-ид игрока по хендлу персонажа
  if result then -- проверить, прошло ли получение ида успешно
    -- здесь любые действия с полученным идом игрока
  end
end
Как зарегистрировать команду чата SAMP?
Lua:
-- До бесконечного цикла/задержки
sampRegisterChatCommand("mycommand", function (param)
     -- param будет содержать весь текст введенный после команды, чтобы разделить его на аргументы используйте string.match()
    sampAddChatMessage("MyCMD", -1)
end)
Крашит игру при вызове sampSendChat. Как это исправить?
Это происходит из-за бага в SAMPFUNCS, когда производится попытка отправки пакета определенными функциями изнутри события исходящих RPC и пакетов. Исправления для этого бага нет, но есть способ не провоцировать его. Вызов sampSendChat изнутри обработчика исходящих RPC/пакетов нужно обернуть в скриптовый поток с нулевой задержкой:
Lua:
function onSendRpc(id)
  -- крашит:
  -- sampSendChat('Send RPC: ' .. id)

  -- норм:
  lua_thread.create(function()
    wait(0)
    sampSendChat('Send RPC: ' .. id)
  end)
end
 
Последнее редактирование:

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,775
11,223
как сделать что бы при нажатии определенной клавиши появлялась надпись в определенном месте экрана, а при нажатии другой определенной клавиши надпись пропадала?
Lua:
require 'lib.moonloader'
local show = false

local font = renderCreateFont('Arial', 15, 5)

function main()
    while not isSampAvailable() do wait(0) end
    
    while true do
        wait(0)
        if wasKeyPressed(VK_1) then show = true end
        if wasKeyPressed(VK_2) then show = false end

        if show then
            renderFontDrawText(font, 'ТЕКСТ', положениеX, положениеY, 0xFFFFFFFF, 0x90000000)
        end
    end
end
 

MixailScripts

Участник
83
6
Приветствую, можно ли сделать так чтобы при нахождении 3д текста, не выводило бесконечно в чат сообщение, а только один раз при каждом новом 3д тексте?
Пример кода.

1:
function main()
    if not isSampLoaded() and not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(0) end
    while not sampIsLocalPlayerSpawned() do wait(100) end
    sampRegisterChatCommand('far', test)
    sampAddChatMessage('1113', -1)
    lockPlayerControl(false)
    j = 0
    n = 0
    local saveX = {}
    local saveY = {}
    local saveZ = {}
    x3 = 0.0
    y3 = 0.0
    z3 = 0.0
    while true do
        wait(0)
        if state then
            if isPlayerPlaying(playerHandle) then
                local posX, posY, posZ = getCharCoordinates(playerPed)
                local res, text, color, x, y, z, distance, ignoreWalls, player, vehicle = Search3Dtext(posX, posY, posZ, 50.0, "Для сбора")
                if res then
                    sampAddChatMessage('1', -1)
                    res = false
                end
            end
        end
    end
end


function Search3Dtext(x, y, z, radius, patern) -- https://www.blast.hk/threads/13380/post-119168
    local text = ""
    local color = 0
    local posX = 0.0
    local posY = 0.0
    local posZ = 0.0
    local distance = 0.0
    local ignoreWalls = false
    local player = -1
    local vehicle = -1
    local result = false
    for id = 0, 2048 do
        if sampIs3dTextDefined(id) then
            local text2, color2, posX2, posY2, posZ2, distance2, ignoreWalls2, player2, vehicle2 = sampGet3dTextInfoById(id)
            if getDistanceBetweenCoords3d(x, y, z, posX2, posY2, posZ2) < radius then
                if string.len(patern) ~= 0 then
                    if string.match(text2, patern, 0) ~= nil then result = true end
                else
                    result = true
                end
                if result then
                    text = text2
                    color = color2
                    posX = posX2
                    posY = posY2
                    posZ = posZ2
                    distance = distance2
                    ignoreWalls = ignoreWalls2
                    player = player2
                    vehicle = vehicle2
                    radius = getDistanceBetweenCoords3d(x, y, z, posX, posY, posZ)
                end
            end
        end
    end
    return result, text, color, posX, posY, posZ, distance, ignoreWalls, player, vehicle
end
 

Mr.Mastire222

Известный
529
259
Как на аризоне сделать чтобы при команде /jb открывался репорт и туда вводился текст, потом репорт отпрAвлялся
 
Последнее редактирование:
  • Ха-ха
Реакции: LLIKOJIbHUK

Стэнфорд

Потрачен
1,058
540
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Хелп сделать регулярку из
Nikitos_Shadow и Horhio_Lamos бросили кости

P.s. я сделал вроде верно, но не работает
(.*) и (.*) бросили кости
 

Стэнфорд

Потрачен
1,058
540
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
вместо * напиши +
if work and (text:find('(.+) и (.+) бросили кости')) then
n1,n2 = text:find('(.+) и (.+) бросили кости')
sampAddChatMessage(n1..' '..n2,-1)
end

вместо ников выводится 2 числа каких-то, как в случае с * так и с +
 

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,775
11,223
if work and (text:find('(.+) и (.+) бросили кости')) then
n1,n2 = text:find('(.+) и (.+) бросили кости')
sampAddChatMessage(n1..' '..n2,-1)
end

вместо ников выводится 2 числа каких-то, как в случае с * так и с +
1635077134243.png

Lua:
local text = 'Nikitos_Shadow и Horhio_Lamos бросили кости'

if text:find('(.+) и (.+) бросили кости') then
    local player1, player2 = text:match('(.+) и (.+) бросили кости')
    print('player1 = '..player1)
    print('player2 = '..player2)
end
 

Mr.Mastire222

Известный
529
259
Как сделать, чтобы если в строке чата есть слово "Администратор" то скрипт получал весь текст который есть в этой строке , и выводил его в диалоговое окно?
 

Corrygan228

Участник
132
9
Не могу понять в чём ошибка(ошибка в 66 строке)

[16:59:06.359377] (error) Gos-Helper.lua: ...ZONA GAMES\bin\Rodina(scripts)\moonloader\Gos-Helper.lua:322: attempt to index upvalue 'frac_mz' (a boolean value)
stack traceback:
...ZONA GAMES\bin\Rodina(scripts)\moonloader\Gos-Helper.lua:322: in function 'OnDrawFrame'
...IZONA GAMES\bin\Rodina(scripts)\moonloader\lib\imgui.lua:1378: in function <...IZONA GAMES\bin\Rodina(scripts)\moonloader\lib\imgui.lua:1367>
[16:59:06.368378] (error) Gos-Helper.lua: Script died due to an error. (799F1104)


Lua:
local fractions = imgui.ImBool(false)
local frac_mz = imgui.ImBool(false)
local frac_mvd = imgui.ImBool(false)
local frac_mo = imgui.ImBool(false)
local frac_as = imgui.ImBool(false)
local frac_cb = imgui.ImBool(false)

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    style()

    sampRegisterChatCommand('gos', function()
        fractions.v = not fractions.v
    end)

    while true do
        wait(0)
        if fractions.v then
            imgui.Process = true
        end
    end
end

local sw, sh = getScreenResolution()

function imgui.OnDrawFrame()
    if not fractions and not frac_mz.v and not frac_mvd.v and not frac_mo.v and not frac_cb.v and not frac_as.v then
        imgui.Process = false
    end

    if fractions.v then
        imgui.SetNextWindowSize(imgui.ImVec2(820, 200), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.Begin(u8'Gos Helper', fractions, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
        imgui.NewLine()
        imgui.Separator()
        imgui.NewLine()
        imgui.CenterText(u8'Выберите вашу организацию')
        imgui.NewLine()
        if imgui.Button(u8'Мин.Здравоохранения', imgui.ImVec2(150, 30)) then
            frac_mz = true
            fractions = false
        end
        imgui.SameLine()
        if imgui.Button(u8'Мин.Внутренних Дел', imgui.ImVec2(150, 30)) then
            frac_mvd = true
            fractions = false
        end
        imgui.SameLine()
        if imgui.Button(u8'Мин.Обороны', imgui.ImVec2(150, 30)) then
            frac_mo = true
            fractions = false
        end
        imgui.SameLine()
        if imgui.Button(u8'Автошкола', imgui.ImVec2(150, 30)) then
            frac_cb = true
            fractions = false
        end
        imgui.SameLine()
        if imgui.Button(u8'Банк', imgui.ImVec2(150, 30)) then
            frac_as = true
            fractions = false
        end
        imgui.End()
    end

    if frac_mz.v then
        imgui.SetNextWindowSize(imgui.ImVec2(1200, 700), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.Begin(u8'Ministry of Health', fractions, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
        imgui.End()
    end
end
 

un1qe

Участник
72
40
Не могу понять в чём ошибка(ошибка в 66 строке)

[16:59:06.359377] (error) Gos-Helper.lua: ...ZONA GAMES\bin\Rodina(scripts)\moonloader\Gos-Helper.lua:322: attempt to index upvalue 'frac_mz' (a boolean value)
stack traceback:
...ZONA GAMES\bin\Rodina(scripts)\moonloader\Gos-Helper.lua:322: in function 'OnDrawFrame'
...IZONA GAMES\bin\Rodina(scripts)\moonloader\lib\imgui.lua:1378: in function <...IZONA GAMES\bin\Rodina(scripts)\moonloader\lib\imgui.lua:1367>
[16:59:06.368378] (error) Gos-Helper.lua: Script died due to an error. (799F1104)


Lua:
local fractions = imgui.ImBool(false)
local frac_mz = imgui.ImBool(false)
local frac_mvd = imgui.ImBool(false)
local frac_mo = imgui.ImBool(false)
local frac_as = imgui.ImBool(false)
local frac_cb = imgui.ImBool(false)

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    style()

    sampRegisterChatCommand('gos', function()
        fractions.v = not fractions.v
    end)

    while true do
        wait(0)
        if fractions.v then
            imgui.Process = true
        end
    end
end

local sw, sh = getScreenResolution()

function imgui.OnDrawFrame()
    if not fractions and not frac_mz.v and not frac_mvd.v and not frac_mo.v and not frac_cb.v and not frac_as.v then
        imgui.Process = false
    end

    if fractions.v then
        imgui.SetNextWindowSize(imgui.ImVec2(820, 200), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.Begin(u8'Gos Helper', fractions, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
        imgui.NewLine()
        imgui.Separator()
        imgui.NewLine()
        imgui.CenterText(u8'Выберите вашу организацию')
        imgui.NewLine()
        if imgui.Button(u8'Мин.Здравоохранения', imgui.ImVec2(150, 30)) then
            frac_mz = true
            fractions = false
        end
        imgui.SameLine()
        if imgui.Button(u8'Мин.Внутренних Дел', imgui.ImVec2(150, 30)) then
            frac_mvd = true
            fractions = false
        end
        imgui.SameLine()
        if imgui.Button(u8'Мин.Обороны', imgui.ImVec2(150, 30)) then
            frac_mo = true
            fractions = false
        end
        imgui.SameLine()
        if imgui.Button(u8'Автошкола', imgui.ImVec2(150, 30)) then
            frac_cb = true
            fractions = false
        end
        imgui.SameLine()
        if imgui.Button(u8'Банк', imgui.ImVec2(150, 30)) then
            frac_as = true
            fractions = false
        end
        imgui.End()
    end

    if frac_mz.v then
        imgui.SetNextWindowSize(imgui.ImVec2(1200, 700), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.Begin(u8'Ministry of Health', fractions, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
        imgui.End()
    end
end
так тебе лог срыгнул что ошибка в 322 строке
 

Corrygan228

Участник
132
9
где ты видишь в логе что в 66 строке ошибка? там всего лишь стоит imgui.End(), скинь весь код
Не смотри на ini какой-то, это со старого файла
Lua:
script_properties("work-in-pause")

white_color = "{FFFFFF}"

local dlstatus = require('moonloader').download_status
local keys = require "vkeys"
local sampev = require "lib.samp.events"
local imgui = require "imgui"
local encoding = require "encoding"
encoding.default = "CP1251"
u8 = encoding.UTF8
local rkeys = require "rkeys"
imgui.ToggleButton = require("imgui_addons").ToggleButton
local inicfg = require "inicfg"

--------------------------------------------------------------------------------------------------------
--СКЛАД ПЕРЕМЕННЫХ, ЕДРИТЬ ЕГО ЗА НОГУ
local fractions = imgui.ImBool(false)

local frac_mz = imgui.ImBool(false)
local frac_mvd = imgui.ImBool(false)
local frac_mo = imgui.ImBool(false)
local frac_as = imgui.ImBool(false)
local frac_cb = imgui.ImBool(false)
-------------------------------------------------------------------------------------------
function imgui.TextColoredRGB(text)
    local style = imgui.GetStyle()
    local colors = style.Colors
    local ImVec4 = imgui.ImVec4

    local explode_argb = function(argb)
        local a = bit.band(bit.rshift(argb, 24), 0xFF)
        local r = bit.band(bit.rshift(argb, 16), 0xFF)
        local g = bit.band(bit.rshift(argb, 8), 0xFF)
        local b = bit.band(argb, 0xFF)
        return a, r, g, b
    end

    local getcolor = function(color)
        if color:sub(1, 6):upper() == 'SSSSSS' then
            local r, g, b = colors[1].x, colors[1].y, colors[1].z
            local a = tonumber(color:sub(7, 8), 16) or colors[1].w * 255
            return ImVec4(r, g, b, a / 255)
        end
        local color = type(color) == 'string' and tonumber(color, 16) or color
        if type(color) ~= 'number' then return end
        local r, g, b, a = explode_argb(color)
        return imgui.ImColor(r, g, b, a):GetVec4()
    end

    local render_text = function(text_)
        for w in text_:gmatch('[^\r\n]+') do
            local text, colors_, m = {}, {}, 1
            w = w:gsub('{(......)}', '{%1FF}')
            while w:find('{........}') do
                local n, k = w:find('{........}')
                local color = getcolor(w:sub(n + 1, k - 1))
                if color then
                    text[#text], text[#text + 1] = w:sub(m, n - 1), w:sub(k + 1, #w)
                    colors_[#colors_ + 1] = color
                    m = n
                end
                w = w:sub(1, n - 1) .. w:sub(k + 1, #w)
            end
            if text[0] then
                for i = 0, #text do
                    imgui.TextColored(colors_[i] or colors[1], u8(text[i]))
                    imgui.SameLine(nil, 0)
                end
                imgui.NewLine()
            else imgui.Text(u8(w)) end
        end
    end

    render_text(text)
end

function imgui.CenterText(text)
    local width = imgui.GetWindowWidth()
    local calc = imgui.CalcTextSize(text)
    imgui.SetCursorPosX( width / 2 - calc.x / 2 )
    imgui.Text(text)
end

function imgui.HelpText(text)
    imgui.TextDisabled("(?)")
    if imgui.IsItemHovered() then
        imgui.BeginTooltip()
        imgui.TextUnformatted(u8(text))
        imgui.EndTooltip()
    end
end

function imgui.InputTextWithHint(label, hint, buf, flags, callback, user_data)
    local l_pos = {imgui.GetCursorPos(), 0}
    local handle = imgui.InputText(label, buf, flags, callback, user_data)
    l_pos[2] = imgui.GetCursorPos()
    local t = (type(hint) == 'string' and buf.v:len() < 1) and hint or '\0'
    local t_size, l_size = imgui.CalcTextSize(t).x, imgui.CalcTextSize('A').x
    imgui.SetCursorPos(imgui.ImVec2(l_pos[1].x + 8, l_pos[1].y + 2))
    imgui.TextDisabled((imgui.CalcItemWidth() and t_size > imgui.CalcItemWidth()) and t:sub(1, math.floor(imgui.CalcItemWidth() / l_size)) or t)
    imgui.SetCursorPos(l_pos[2])
    return handle
end

function imgui.VerticalSeparator()
    local p = imgui.GetCursorScreenPos()
    imgui.GetWindowDrawList():AddLine(imgui.ImVec2(p.x, p.y), imgui.ImVec2(p.x, p.y + imgui.GetContentRegionMax().y), imgui.GetColorU32(imgui.GetStyle().Colors[imgui.Col.Separator]))
end

-----------------------------
-----------INI CFG-----------
-----------------------------

function iniReset()
    inicfg.save({
        mvd = {
            stmvdgov = '',
            ndmvdgov = '',
            rdmvdgov = '',
            mvdtag = '',
            mvdtime = '',
        },
        mo = {
            stmogov = '',
            ndmogov = '',
            rdmogov = '',
            motag = '',
            motime = '',
        },
        smi = {
            stsmigov = '',
            ndsmigov = '',
            rdsmigov = '',
            smitag = '',
            smitime = '',
        },
        mz = {
            stmzgov = '',
            ndmzgov = '',
            rdmzgov = '',
            mztag = '',
            mztime = '',
        },
        cb = {
            stcbgov = '',
            ndcbgov = '',
            rdcbgov = '',
            cbtag = '',
            cbtime = '',
        },
        gv = {
            stgvgov = '',
            ndgvgov = '',
            rdgvgov = '',
            gvtag = '',
            gvtime = '',
        },
        other = {
            colortheme = 1,
        }
    }, configuration_path)

    print("[Конфигурационный файл 'config.ini' не был найден, скрипт создал его автоматически]")
end

function iniLoad()
    configuration = inicfg.load(nil, configuration_path)

    if configuration == nil then
        iniReset()
    else
        text_buffermvd1.v = configuration.mvd.stmvdgov
        text_buffermvd2.v = configuration.mvd.ndmvdgov
        text_buffermvd3.v = configuration.mvd.rdmvdgov
        text_buffertagmvd.v = configuration.mvd.mvdtag
        mvd_time.v = configuration.mvd.mvdtime
        text_buffermo1.v = configuration.mo.stmogov
        text_buffermo2.v = configuration.mo.ndmogov
        text_buffermo3.v = configuration.mo.rdmogov
        text_buffertagmo.v = configuration.mo.motag
        mo_time.v = configuration.mo.motime
        text_buffersmi1.v = configuration.smi.stsmigov
        text_buffersmi2.v = configuration.smi.ndsmigov
        text_buffersmi3.v = configuration.smi.rdsmigov
        text_buffertagsmi.v = configuration.smi.smitag
        smi_time.v = configuration.smi.smitime
        text_buffermz1.v = configuration.mz.stmzgov
        text_buffermz2.v = configuration.mz.ndmzgov
        text_buffermz3.v = configuration.mz.rdmzgov
        text_buffertagmz.v = configuration.mz.mztag
        mz_time.v = configuration.mz.mztime
        text_buffercb1.v = configuration.cb.stcbgov
        text_buffercb2.v = configuration.cb.ndcbgov
        text_buffercb3.v = configuration.cb.rdcbgov
        text_buffertagcb.v = configuration.cb.cbtag
        cb_time.v = configuration.cb.cbtime
        text_buffergv1.v = configuration.gv.stgvgov
        text_buffergv2.v = configuration.gv.ndgvgov
        text_buffergv3.v = configuration.gv.rdgvgov
        text_buffertaggv.v = configuration.gv.gvtag
        gv_time.v = configuration.gv.gvtime
        intImGui.v = configuration.other.colortheme
    end
end

function iniSave()
    inicfg.save({
        mvd = {
            stmvdgov = text_buffermvd1.v,
            ndmvdgov = text_buffermvd2.v,
            rdmvdgov = text_buffermvd3.v,
            mvdtag = text_buffertagmvd.v,
            mvdtime = mvd_time.v,
        },
        mo = {
            stmogov = text_buffermo1.v,
            ndmogov = text_buffermo2.v,
            rdmogov = text_buffermo3.v,
            motag = text_buffertagmo.v,
            motime = mo_time.v,
        },
        smi = {
            stsmigov = text_buffersmi1.v,
            ndsmigov = text_buffersmi2.v,
            rdsmigov = text_buffersmi3.v,
            smitag = text_buffertagsmi.v,
            smitime = smi_time.v,
        },
        mz = {
            stmzgov = text_buffermz1.v,
            ndmzgov = text_buffermz2.v,
            rdmzgov = text_buffermz3.v,
            mztag = text_buffertagmz.v,
            mztime = mz_time.v,
        },
        cb = {
            stcbgov = text_buffercb1.v,
            ndcbgov = text_buffercb2.v,
            rdcbgov = text_buffercb3.v,
            cbtag = text_buffertagcb.v,
            cbtime = cb_time.v,
        },
        gv = {
            stgvgov = text_buffergv1.v,
            ndgvgov = text_buffergv2.v,
            rdgvgov = text_buffergv3.v,
            gvtag = text_buffertaggv.v,
            gvtime = gv_time.v,
        },
        other = {
            colortheme = intImGui.v,
        }
    }, configuration_path)
end

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampAddChatMessage('[Gos-Helper]:' .. white_color .. ' Запущена актуальная версия скрипта! (v1.0)', 0xFF0033)
    sampAddChatMessage('[Gos-Helper]:' .. white_color .. ' Автор скрипта - {FF0033}Ivan_Lopatov', 0xFF0033)

    style()

    sampRegisterChatCommand('gos', function()
        fractions.v = not fractions.v
    end)

    while true do
        wait(0)

        if fractions.v then
            imgui.Process = true
        end
    end
end

local sw, sh = getScreenResolution()

function imgui.OnDrawFrame()
    if not fractions and not frac_mz.v and not frac_mvd.v and not frac_mo.v and not frac_cb.v and not frac_as.v then
        imgui.Process = false
    end

    if fractions.v then
        imgui.SetNextWindowSize(imgui.ImVec2(820, 200), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.Begin(u8'Gos Helper | by Lopatov', fractions, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
        imgui.NewLine()
        imgui.Separator()
        imgui.NewLine()
        imgui.CenterText(u8'Выберите вашу организацию')
        imgui.NewLine()
        if imgui.Button(u8'Мин.Здравоохранения', imgui.ImVec2(150, 30)) then
            frac_mz = true
            fractions = false
        end
        imgui.SameLine()
        if imgui.Button(u8'Мин.Внутренних Дел', imgui.ImVec2(150, 30)) then
            frac_mvd = true
            fractions = false
        end
        imgui.SameLine()
        if imgui.Button(u8'Мин.Обороны', imgui.ImVec2(150, 30)) then
            frac_mo = true
            fractions = false
        end
        imgui.SameLine()
        if imgui.Button(u8'Автошкола', imgui.ImVec2(150, 30)) then
            frac_cb = true
            fractions = false
        end
        imgui.SameLine()
        if imgui.Button(u8'Банк', imgui.ImVec2(150, 30)) then
            frac_as = true
            fractions = false
        end
        imgui.End()
    end

    if frac_mz.v then
        imgui.SetNextWindowSize(imgui.ImVec2(1200, 700), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.Begin(u8'Ministry of Health | by Lopatov', fractions, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
        imgui.End()
    end
end

function style()
    imgui.SwitchContext()
    local style  = imgui.GetStyle()
    local colors = style.Colors
    local clr    = imgui.Col
    local ImVec4 = imgui.ImVec4
    local ImVec2 = imgui.ImVec2

    style.WindowPadding = ImVec2(15, 15)
    style.WindowRounding = 5.0
    style.FramePadding = ImVec2(10, 4)
    style.FrameRounding = 6
    style.ItemSpacing = ImVec2(10, 7)
    style.ItemInnerSpacing = ImVec2(17, 9)
    style.IndentSpacing = 25.0
    style.ScrollbarSize = 10.0
    style.WindowRounding = 10
    style.ScrollbarRounding = 15.0
    style.GrabMinSize = 5.0
    style.GrabRounding = 16.0
    style.WindowTitleAlign = ImVec2(0.50, 0.50)
    style.ButtonTextAlign = ImVec2(0.50, 0.50)

    colors[clr.Text]                 = ImVec4(1.00, 1.00, 1.00, 1.00)
    colors[clr.TextDisabled]         = ImVec4(0.39, 0.39, 0.39, 1.00)
    colors[clr.WindowBg]             = ImVec4(0.11, 0.11, 0.11, 0.94)
    colors[clr.ChildWindowBg]        = ImVec4(0.11, 0.11, 0.11, 0.94)
    colors[clr.PopupBg]              = ImVec4(0.11, 0.11, 0.11, 0.94)
    colors[clr.Border]               = ImVec4(0.57, 0.41, 0.00, 0.50)
    colors[clr.BorderShadow]         = ImVec4(0.00, 0.00, 0.00, 0.00)
    colors[clr.FrameBg]              = ImVec4(0.57, 0.41, 0.00, 0.50)
    colors[clr.FrameBgHovered]       = ImVec4(0.57, 0.41, 0.00, 0.50)
    colors[clr.FrameBgActive]        = ImVec4(0.57, 0.41, 0.00, 0.50)
    colors[clr.TitleBg]              = ImVec4(0.57, 0.41, 0.00, 0.50)
    colors[clr.TitleBgActive]        = ImVec4(0.57, 0.41, 0.00, 0.50)
    colors[clr.TitleBgCollapsed]     = ImVec4(0.57, 0.41, 0.00, 0.50)
    colors[clr.MenuBarBg]            = ImVec4(0.57, 0.41, 0.00, 0.50)
    colors[clr.ScrollbarBg]          = ImVec4(0.57, 0.41, 0.00, 0.50)
    colors[clr.ScrollbarGrab]        = ImVec4(0.11, 0.11, 0.11, 0.94)
    colors[clr.ScrollbarGrabHovered] = ImVec4(0.11, 0.11, 0.11, 0.94)
    colors[clr.ScrollbarGrabActive]  = ImVec4(0.11, 0.11, 0.11, 0.94)
    colors[clr.ComboBg]              = ImVec4(0.57, 0.41, 0.00, 0.50)
    colors[clr.CheckMark]            = ImVec4(0.11, 0.11, 0.11, 0.94)
    colors[clr.SliderGrab]           = ImVec4(0.11, 0.11, 0.11, 0.94)
    colors[clr.SliderGrabActive]     = ImVec4(0.11, 0.11, 0.11, 0.94)
    colors[clr.Button]               = ImVec4(0.57, 0.41, 0.00, 0.50)
    colors[clr.ButtonHovered]        = ImVec4(0.71, 0.55, 0.15, 0.50)
    colors[clr.ButtonActive]         = ImVec4(0.57, 0.41, 0.00, 0.50)
    colors[clr.Header]               = ImVec4(0.11, 0.11, 0.11, 0.94)
    colors[clr.HeaderHovered]        = ImVec4(0.11, 0.11, 0.11, 0.94)
    colors[clr.HeaderActive]         = ImVec4(0.11, 0.11, 0.11, 0.94)
    colors[clr.Separator]            = ImVec4(0.70, 0.50, 0.00, 0.50)
    colors[clr.SeparatorHovered]     = ImVec4(0.11, 0.11, 0.11, 0.94)
    colors[clr.SeparatorActive]      = ImVec4(0.11, 0.11, 0.11, 0.94)
    colors[clr.ResizeGrip]           = ImVec4(0.70, 0.51, 0.00, 0.50)
    colors[clr.ResizeGripHovered]    = ImVec4(0.71, 0.55, 0.15, 0.50)
    colors[clr.ResizeGripActive]     = ImVec4(0.70, 0.51, 0.00, 0.50)
    colors[clr.CloseButton]          = ImVec4(0.11, 0.11, 0.11, 0.94)
    colors[clr.CloseButtonHovered]   = ImVec4(0.11, 0.11, 0.11, 0.94)
    colors[clr.CloseButtonActive]    = ImVec4(0.11, 0.11, 0.11, 0.94)
    colors[clr.PlotLines]            = ImVec4(0.11, 0.11, 0.11, 0.94)
    colors[clr.PlotLinesHovered]     = ImVec4(0.11, 0.11, 0.11, 0.94)
    colors[clr.PlotHistogram]        = ImVec4(0.11, 0.11, 0.11, 0.94)
    colors[clr.PlotHistogramHovered] = ImVec4(0.11, 0.11, 0.11, 0.94)
    colors[clr.TextSelectedBg]       = ImVec4(0.11, 0.11, 0.11, 0.94)
    colors[clr.ModalWindowDarkening] = ImVec4(0.11, 0.11, 0.11, 0.94)
end