Вопросы по 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
 
Последнее редактирование:

sep

Известный
673
76
как в imgui.TextColored(imgui.ImVec4(0.0, 1.0, 0.0, 1.0 ), u8(nik))
сделать чтобы цвета были по цвету клиста ника своего

знаю что надо как то через
local color = sampGetPlayerColor(pID)
bit.band(color,0xffffff)
а вот как все это собрать в рабочую незнаю подскажите
 

b0ga9

Новичок
14
0
Еще вопрос
Как получить ник игрока введя его id?
Используя похожий код
Код:
_, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
nick = sampGetPlayerNickname(id)
Нужно для функции
Lua:
function cmd(arg)
    array = {"LSPD", "SFPD", "LVPD"}
    text = ""
    for i, arra in pairs(array) do
        text = text.." "..array[i]
    end
    down1, down2 = string.match(arg, "(.+) (.+)")--(%d+)
    if down1 == nil or down1 == "" then
        sampAddChatMessage(tag.." Введите /ssf номер фракции: ["..text.."], ID", r_color)
    else
        sampSendChat("/b "  .. array[tonumber(down1)] .. ", забрал ".. id1 .. " для работы с бюро, не теряйте. ", -1)
    end
end
 

Andrinall

Известный
689
534
как в imgui.TextColored(imgui.ImVec4(0.0, 1.0, 0.0, 1.0 ), u8(nik))
сделать чтобы цвета были по цвету клиста ника своего

знаю что надо как то через
local color = sampGetPlayerColor(pID)
bit.band(color,0xffffff)
а вот как все это собрать в рабочую незнаю подскажите
Если ты получаешь цвет прямо в отрисовке фрейма - скорее всего тебе поможет этот код
Lua:
imgui.TextColored( imgui.ColorConvertU32ToFloat4( bit.band( sampGetPlayerColor(pID), 0xffffff ) ), u8(nik) )

Еще вопрос
Как получить ник игрока введя его id?
Используя похожий код
Код:
_, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
nick = sampGetPlayerNickname(id)
Нужно для функции
Lua:
function cmd(arg)
    array = {"LSPD", "SFPD", "LVPD"}
    text = ""
    for i, arra in pairs(array) do
        text = text.." "..array[i]
    end
    down1, down2 = string.match(arg, "(.+) (.+)")--(%d+)
    if down1 == nil or down1 == "" then
        sampAddChatMessage(tag.." Введите /ssf номер фракции: ["..text.."], ID", r_color)
    else
        sampSendChat("/b "  .. array[tonumber(down1)] .. ", забрал ".. id1 .. " для работы с бюро, не теряйте. ", -1)
    end
end
Lua:
function cmd(arg)
    if arg ~= '' and tonumber(arg) then
        arg = tonumber(arg)
        if sampIsPlayerConnected(arg) then
            return sampGetPlayerNickname(arg)
        end
    end
end
Вроде не ошибся.
 
  • Нравится
Реакции: sep

Immortal-

Участник
67
1
Сделал сохранение в json, все отлично работает. Но вопрос. Как считать нужный мне массив из таблицы?
Потому-что команду все равно не регистрирует после перезахода в игру.

Lua:
local imgui = require 'imgui'
local sampev = require('samp.events')
local inicfg = require 'inicfg'
local encoding = require 'encoding'

local main_window_state = imgui.ImBool(false)
local winState = 1

local json_file = getWorkingDirectory()..'\\config\\mt_cmd.json'
local list = {
}

local cmd = imgui.ImBuffer(256)
local type_n = imgui.ImBuffer(256)
local prich = imgui.ImBuffer(256)
local time_n = imgui.ImInt(0)

encoding.default = 'CP1251'
u8 = encoding.UTF8

local mainIni = inicfg.load(
{
    config =
    {
        yourself = false,
        other = false,
        deletemsg = false,
        autogetip = false,
        fix_autopass = true
    }
},
    'antifloodclickwarp'
)

local yourself = imgui.ImBool(mainIni.config.yourself)
local other = imgui.ImBool(mainIni.config.other)
local deletemsg = imgui.ImBool(mainIni.config.deletemsg)
local autogetip = imgui.ImBool(mainIni.config.autogetip)
local fix_autopass = imgui.ImBool(mainIni.config.fix_autopass)

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

    style.WindowRounding = 2.0
    style.WindowTitleAlign = imgui.ImVec2(0.5, 0.84)
    style.ChildWindowRounding = 2.0
    style.FrameRounding = 2.0
    style.ItemSpacing = imgui.ImVec2(5.0, 4.0)
    style.ScrollbarSize = 13.0
    style.ScrollbarRounding = 0
    style.GrabMinSize = 8.0
    style.GrabRounding = 1.0

    colors[clr.FrameBg]                = ImVec4(0.16, 0.48, 0.42, 0.54)
    colors[clr.FrameBgHovered]         = ImVec4(0.26, 0.98, 0.85, 0.40)
    colors[clr.FrameBgActive]          = ImVec4(0.26, 0.98, 0.85, 0.67)
    colors[clr.TitleBg]                = ImVec4(0.04, 0.04, 0.04, 1.00)
    colors[clr.TitleBgActive]          = ImVec4(0.16, 0.48, 0.42, 1.00)
    colors[clr.TitleBgCollapsed]       = ImVec4(0.00, 0.00, 0.00, 0.51)
    colors[clr.CheckMark]              = ImVec4(0.26, 0.98, 0.85, 1.00)
    colors[clr.SliderGrab]             = ImVec4(0.24, 0.88, 0.77, 1.00)
    colors[clr.SliderGrabActive]       = ImVec4(0.26, 0.98, 0.85, 1.00)
    colors[clr.Button]                 = ImVec4(0.26, 0.98, 0.85, 0.40)
    colors[clr.ButtonHovered]          = ImVec4(0.26, 0.98, 0.85, 1.00)
    colors[clr.ButtonActive]           = ImVec4(0.06, 0.98, 0.82, 1.00)
    colors[clr.Header]                 = ImVec4(0.26, 0.98, 0.85, 0.31)
    colors[clr.HeaderHovered]          = ImVec4(0.26, 0.98, 0.85, 0.80)
    colors[clr.HeaderActive]           = ImVec4(0.26, 0.98, 0.85, 1.00)
    colors[clr.Separator]              = colors[clr.Border]
    colors[clr.SeparatorHovered]       = ImVec4(0.10, 0.75, 0.63, 0.78)
    colors[clr.SeparatorActive]        = ImVec4(0.10, 0.75, 0.63, 1.00)
    colors[clr.ResizeGrip]             = ImVec4(0.26, 0.98, 0.85, 0.25)
    colors[clr.ResizeGripHovered]      = ImVec4(0.26, 0.98, 0.85, 0.67)
    colors[clr.ResizeGripActive]       = ImVec4(0.26, 0.98, 0.85, 0.95)
    colors[clr.PlotLines]              = ImVec4(0.61, 0.61, 0.61, 1.00)
    colors[clr.PlotLinesHovered]       = ImVec4(1.00, 0.81, 0.35, 1.00)
    colors[clr.TextSelectedBg]         = ImVec4(0.26, 0.98, 0.85, 0.35)
    colors[clr.Text]                   = ImVec4(1.00, 1.00, 1.00, 1.00)
    colors[clr.TextDisabled]           = ImVec4(0.50, 0.50, 0.50, 1.00)
    colors[clr.WindowBg]               = ImVec4(0.06, 0.06, 0.06, 0.94)
    colors[clr.ChildWindowBg]          = ImVec4(1.00, 1.00, 1.00, 0.00)
    colors[clr.PopupBg]                = ImVec4(0.08, 0.08, 0.08, 0.94)
    colors[clr.ComboBg]                = colors[clr.PopupBg]
    colors[clr.Border]                 = ImVec4(0.43, 0.43, 0.50, 0.50)
    colors[clr.BorderShadow]           = ImVec4(0.00, 0.00, 0.00, 0.00)
    colors[clr.MenuBarBg]              = ImVec4(0.14, 0.14, 0.14, 1.00)
    colors[clr.ScrollbarBg]            = ImVec4(0.02, 0.02, 0.02, 0.53)
    colors[clr.ScrollbarGrab]          = ImVec4(0.31, 0.31, 0.31, 1.00)
    colors[clr.ScrollbarGrabHovered]   = ImVec4(0.41, 0.41, 0.41, 1.00)
    colors[clr.ScrollbarGrabActive]    = ImVec4(0.51, 0.51, 0.51, 1.00)
    colors[clr.CloseButton]            = ImVec4(0.41, 0.41, 0.41, 0.50)
    colors[clr.CloseButtonHovered]     = ImVec4(0.98, 0.39, 0.36, 1.00)
    colors[clr.CloseButtonActive]      = ImVec4(0.98, 0.39, 0.36, 1.00)
    colors[clr.PlotHistogram]          = ImVec4(0.90, 0.70, 0.00, 1.00)
    colors[clr.PlotHistogramHovered]   = ImVec4(1.00, 0.60, 0.00, 1.00)
    colors[clr.ModalWindowDarkening]   = ImVec4(0.80, 0.80, 0.80, 0.35)
end
apply_custom_style()

function imgui.OnDrawFrame()
    if not main_window_state.v then
        imgui.Process = false
    end   

    if not window_pos then
        ScreenX, ScreenY = getScreenResolution()ScreenX, ScreenY = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(ScreenX / 2 , ScreenY / 2), imgui.Cond.FirsUseEver, imgui.ImVec2(0.5, 0.5))
    end   

    if main_window_state.v then
        imgui.SetNextWindowSize(imgui.ImVec2(290, 225), imgui.Cond.FirstUseEver)

        imgui.Begin(u8'[MiniTools] Настройки', main_window_state, imgui.WindowFlags.MenuBar)
        
        imgui.BeginMenuBar()
        
        if imgui.MenuItem(u8'Анти-Флуд') then
            winState = 1
        end
        
        if imgui.MenuItem(u8'Слежка') then
            winState = 2
        end
        
        if imgui.MenuItem(u8'Фиксы') then
            winState = 3
        end   

        if imgui.MenuItem(u8'Команды') then
            winState = 4
        end           
        
        imgui.EndMenuBar()
        
        if winState == 1 then
            AntiFloodWindow()
        end
        
        if winState == 2 then
            Recon()
        end   

        if winState == 3 then
            Fixed()
        end

        if winState == 4 then
            OpenCmd()
        end           

        imgui.End()
    end
end

function AntiFloodWindow()
    imgui.Checkbox(u8'Не отображать флуд от себя.', yourself)
    imgui.Checkbox(u8'Не отображать флуд от других.', other)
    imgui.Checkbox(u8'Не отображать координаты.', deletemsg)

    if imgui.Button(u8'Сохранить', imgui.ImVec2(255, 20)) then
        mainIni.config.yourself = yourself.v
        mainIni.config.other = other.v
        mainIni.config.deletemsg = deletemsg.v
        inicfg.save(mainIni, 'antifloodclickwarp.ini')
    end
end

function Recon()
    imgui.Checkbox(u8'Автоматически получать IP в /re.', autogetip)

    if imgui.Button(u8'Сохранить', imgui.ImVec2(255, 20)) then
        mainIni.config.autogetip = autogetip.v
        inicfg.save(mainIni, 'antifloodclickwarp.ini')
    end
end

function Fixed()
    imgui.Checkbox(u8'Фикс автоматического входа в игру.', fix_autopass)
    
    if imgui.Button(u8'Сохранить', imgui.ImVec2(255, 20)) then
        mainIni.config.fix_autopass = fix_autopass.v
        inicfg.save(mainIni, 'antifloodclickwarp.ini')
    end     
end

function OpenCmd()
    if imgui.Button(u8'Зарегистрировать команду.') then
        imgui.OpenPopup(u8'Регистрация команды.')
    end
    
    if imgui.BeginPopup(u8'Регистрация команды.') then
        imgui.InputText(u8'Команда.', cmd)
        imgui.InputText(u8'Тип наказания.', type_n)
        imgui.InputText(u8'Причина.', prich)
        imgui.InputInt(u8'Время.', time_n)
        
            if imgui.Button(u8'Создать команду.') then
                table.insert(list, {cmd = cmd.v})
                table.insert(list, {type_n = type_n.v})
                table.insert(list, {prich = prich.v})
                table.insert(list, {time_n = time_n.v})
                jsonSave(json_file, list)           
                sampRegisterChatCommand(cmd.v, function(num)
                    sampSendChat(u8:decode(string.format("/%s "..num.." %s %s", type_n.v, time_n.v, prich.v)))
                end)
            end
            
        imgui.EndPopup()
    end
end

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then
        return
    end

    while not isSampAvailable() do
        wait(0)
    end
    
    if not doesFileExist(json_file) then jsonSave(json_file, {}) end
    list = jsonRead(json_file)
    
    sampRegisterChatCommand('minitools', cmd_tool)

    sampAddChatMessage('{00ffcc}[MiniToolsAdm] {ffffff}- For Payson!', -1)
    sampAddChatMessage('{00ffcc}[MiniToolsAdm] {ffffff}- Version: 1.0 beta', -1)
    sampAddChatMessage('{00ffcc}[MiniToolsAdm] {ffffff}- Author: Haunted_BabyTape', -1)
    
    sampRegisterChatCommand(cmd.v, function(num)
        sampSendChat(u8:decode(string.format("/%s "..num.." %s %s", type_n.v, time_n.v, prich.v)))
    end)   
    
end

function cmd_tool(arg)
    main_window_state.v = not main_window_state.v
    imgui.Process = main_window_state.v
end

function sampev.onSendCommand(command)
    if yourself.v then
        if (command:find('/a %[Tools%]')) then
            return false
        end
    end
    
    if autogetip.v then
        if (command:find('/re ')) then
            lua_thread.create(function()
                wait(500)
                sampSendChat(u8:decode('/getip '..getClosestPlayerId()))
            end)
        end
    end
end

function sampev.onServerMessage(color, text)
    if other.v then
        if text:find('%{......%}: %[Tools%] Телепортировал') then
            return false
        end
        if text:find('на координаты') then
            return false
        end       
    end
    
    if deletemsg.v then
        if text:find('Вы телепортировали') then
            return false
        end           
    end
end

function sampev.onShowDialog(dialogId, style, title, button1, button2, text)
    if fix_autopass.v then
        if dialogId == 7722 then
            lua_thread.create(function()
                wait(500)
                sampCloseCurrentDialogWithButton(0)
            end)
        end
        if dialogId == 15330 then
            return false
        end
    end
end

function getClosestPlayerId()
    local closestId = -1
    mydist = 30
    local x, y, z = getCharCoordinates(PLAYER_PED)
    for i = 0, 999 do
        local streamed, pedID = sampGetCharHandleBySampPlayerId(i)
        if streamed and getCharHealth(pedID) > 0 and not sampIsPlayerPaused(pedID) then
            local xi, yi, zi = getCharCoordinates(pedID)
            local dist = getDistanceBetweenCoords3d(x, y, z, xi, yi, zi)
            if dist <= mydist then
                mydist = dist
                closestId = i
            end
        end
    end
    return closestId
end

function jsonSave(jsonFilePath, t)
    file = io.open(jsonFilePath, "w")
    file:write(encodeJson(t))
    file:flush()
    file:close()
end

function jsonRead(jsonFilePath)
    local file = io.open(jsonFilePath, "r+")
    local jsonInString = file:read("*a")
    file:close()
    local jsonTable = decodeJson(jsonInString)
    return jsonTable
end
 

sep

Известный
673
76
Если ты получаешь цвет прямо в отрисовке фрейма - скорее всего тебе поможет этот код
Lua:
imgui.TextColored( imgui.ColorConvertU32ToFloat4( bit.band( sampGetPlayerColor(pID), 0xffffff ) ), u8(nik) )
непашет функция какаято нужна для этого ???
типо этой или что проверь у себя у тебя работает ?
function U32ToImVec4(color)
r = bit.rshift(color, 16)
g = bit.band(bit.rshift(color, 8), 0xFF)
b = bit.band(color, 0xFF)
return imgui.ImVec4(r / 255, g / 255, b / 255, 1.0)
end
 

b0ga9

Новичок
14
0
Если ты получаешь цвет прямо в отрисовке фрейма - скорее всего тебе поможет этот код
Lua:
imgui.TextColored( imgui.ColorConvertU32ToFloat4( bit.band( sampGetPlayerColor(pID), 0xffffff ) ), u8(nik) )


Lua:
function cmd(arg)
    if arg ~= '' and tonumber(arg) then
        arg = tonumber(arg)
        if sampIsPlayerConnected(arg) then
            return sampGetPlayerNickname(arg)
        end
    end
end
Вроде не ошибся.
не совсем понял что нужно вставлять вместо arg
 

|| NN - NoName ||

Известный
1,049
630

|| NN - NoName ||

Известный
1,049
630
 

Immortal-

Участник
67
1
Сделал сохранение в json, все отлично работает. Но вопрос. Как считать нужный мне массив из таблицы?
Потому-что команду все равно не регистрирует после перезахода в игру.

Lua:
local imgui = require 'imgui'
local sampev = require('samp.events')
local inicfg = require 'inicfg'
local encoding = require 'encoding'

local main_window_state = imgui.ImBool(false)
local winState = 1

local json_file = getWorkingDirectory()..'\\config\\mt_cmd.json'
local list = {
}

local cmd = imgui.ImBuffer(256)
local type_n = imgui.ImBuffer(256)
local prich = imgui.ImBuffer(256)
local time_n = imgui.ImInt(0)

encoding.default = 'CP1251'
u8 = encoding.UTF8

local mainIni = inicfg.load(
{
    config =
    {
        yourself = false,
        other = false,
        deletemsg = false,
        autogetip = false,
        fix_autopass = true
    }
},
    'antifloodclickwarp'
)

local yourself = imgui.ImBool(mainIni.config.yourself)
local other = imgui.ImBool(mainIni.config.other)
local deletemsg = imgui.ImBool(mainIni.config.deletemsg)
local autogetip = imgui.ImBool(mainIni.config.autogetip)
local fix_autopass = imgui.ImBool(mainIni.config.fix_autopass)

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

    style.WindowRounding = 2.0
    style.WindowTitleAlign = imgui.ImVec2(0.5, 0.84)
    style.ChildWindowRounding = 2.0
    style.FrameRounding = 2.0
    style.ItemSpacing = imgui.ImVec2(5.0, 4.0)
    style.ScrollbarSize = 13.0
    style.ScrollbarRounding = 0
    style.GrabMinSize = 8.0
    style.GrabRounding = 1.0

    colors[clr.FrameBg]                = ImVec4(0.16, 0.48, 0.42, 0.54)
    colors[clr.FrameBgHovered]         = ImVec4(0.26, 0.98, 0.85, 0.40)
    colors[clr.FrameBgActive]          = ImVec4(0.26, 0.98, 0.85, 0.67)
    colors[clr.TitleBg]                = ImVec4(0.04, 0.04, 0.04, 1.00)
    colors[clr.TitleBgActive]          = ImVec4(0.16, 0.48, 0.42, 1.00)
    colors[clr.TitleBgCollapsed]       = ImVec4(0.00, 0.00, 0.00, 0.51)
    colors[clr.CheckMark]              = ImVec4(0.26, 0.98, 0.85, 1.00)
    colors[clr.SliderGrab]             = ImVec4(0.24, 0.88, 0.77, 1.00)
    colors[clr.SliderGrabActive]       = ImVec4(0.26, 0.98, 0.85, 1.00)
    colors[clr.Button]                 = ImVec4(0.26, 0.98, 0.85, 0.40)
    colors[clr.ButtonHovered]          = ImVec4(0.26, 0.98, 0.85, 1.00)
    colors[clr.ButtonActive]           = ImVec4(0.06, 0.98, 0.82, 1.00)
    colors[clr.Header]                 = ImVec4(0.26, 0.98, 0.85, 0.31)
    colors[clr.HeaderHovered]          = ImVec4(0.26, 0.98, 0.85, 0.80)
    colors[clr.HeaderActive]           = ImVec4(0.26, 0.98, 0.85, 1.00)
    colors[clr.Separator]              = colors[clr.Border]
    colors[clr.SeparatorHovered]       = ImVec4(0.10, 0.75, 0.63, 0.78)
    colors[clr.SeparatorActive]        = ImVec4(0.10, 0.75, 0.63, 1.00)
    colors[clr.ResizeGrip]             = ImVec4(0.26, 0.98, 0.85, 0.25)
    colors[clr.ResizeGripHovered]      = ImVec4(0.26, 0.98, 0.85, 0.67)
    colors[clr.ResizeGripActive]       = ImVec4(0.26, 0.98, 0.85, 0.95)
    colors[clr.PlotLines]              = ImVec4(0.61, 0.61, 0.61, 1.00)
    colors[clr.PlotLinesHovered]       = ImVec4(1.00, 0.81, 0.35, 1.00)
    colors[clr.TextSelectedBg]         = ImVec4(0.26, 0.98, 0.85, 0.35)
    colors[clr.Text]                   = ImVec4(1.00, 1.00, 1.00, 1.00)
    colors[clr.TextDisabled]           = ImVec4(0.50, 0.50, 0.50, 1.00)
    colors[clr.WindowBg]               = ImVec4(0.06, 0.06, 0.06, 0.94)
    colors[clr.ChildWindowBg]          = ImVec4(1.00, 1.00, 1.00, 0.00)
    colors[clr.PopupBg]                = ImVec4(0.08, 0.08, 0.08, 0.94)
    colors[clr.ComboBg]                = colors[clr.PopupBg]
    colors[clr.Border]                 = ImVec4(0.43, 0.43, 0.50, 0.50)
    colors[clr.BorderShadow]           = ImVec4(0.00, 0.00, 0.00, 0.00)
    colors[clr.MenuBarBg]              = ImVec4(0.14, 0.14, 0.14, 1.00)
    colors[clr.ScrollbarBg]            = ImVec4(0.02, 0.02, 0.02, 0.53)
    colors[clr.ScrollbarGrab]          = ImVec4(0.31, 0.31, 0.31, 1.00)
    colors[clr.ScrollbarGrabHovered]   = ImVec4(0.41, 0.41, 0.41, 1.00)
    colors[clr.ScrollbarGrabActive]    = ImVec4(0.51, 0.51, 0.51, 1.00)
    colors[clr.CloseButton]            = ImVec4(0.41, 0.41, 0.41, 0.50)
    colors[clr.CloseButtonHovered]     = ImVec4(0.98, 0.39, 0.36, 1.00)
    colors[clr.CloseButtonActive]      = ImVec4(0.98, 0.39, 0.36, 1.00)
    colors[clr.PlotHistogram]          = ImVec4(0.90, 0.70, 0.00, 1.00)
    colors[clr.PlotHistogramHovered]   = ImVec4(1.00, 0.60, 0.00, 1.00)
    colors[clr.ModalWindowDarkening]   = ImVec4(0.80, 0.80, 0.80, 0.35)
end
apply_custom_style()

function imgui.OnDrawFrame()
    if not main_window_state.v then
        imgui.Process = false
    end  

    if not window_pos then
        ScreenX, ScreenY = getScreenResolution()ScreenX, ScreenY = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(ScreenX / 2 , ScreenY / 2), imgui.Cond.FirsUseEver, imgui.ImVec2(0.5, 0.5))
    end  

    if main_window_state.v then
        imgui.SetNextWindowSize(imgui.ImVec2(290, 225), imgui.Cond.FirstUseEver)

        imgui.Begin(u8'[MiniTools] Настройки', main_window_state, imgui.WindowFlags.MenuBar)
       
        imgui.BeginMenuBar()
       
        if imgui.MenuItem(u8'Анти-Флуд') then
            winState = 1
        end
       
        if imgui.MenuItem(u8'Слежка') then
            winState = 2
        end
       
        if imgui.MenuItem(u8'Фиксы') then
            winState = 3
        end  

        if imgui.MenuItem(u8'Команды') then
            winState = 4
        end          
       
        imgui.EndMenuBar()
       
        if winState == 1 then
            AntiFloodWindow()
        end
       
        if winState == 2 then
            Recon()
        end  

        if winState == 3 then
            Fixed()
        end

        if winState == 4 then
            OpenCmd()
        end          

        imgui.End()
    end
end

function AntiFloodWindow()
    imgui.Checkbox(u8'Не отображать флуд от себя.', yourself)
    imgui.Checkbox(u8'Не отображать флуд от других.', other)
    imgui.Checkbox(u8'Не отображать координаты.', deletemsg)

    if imgui.Button(u8'Сохранить', imgui.ImVec2(255, 20)) then
        mainIni.config.yourself = yourself.v
        mainIni.config.other = other.v
        mainIni.config.deletemsg = deletemsg.v
        inicfg.save(mainIni, 'antifloodclickwarp.ini')
    end
end

function Recon()
    imgui.Checkbox(u8'Автоматически получать IP в /re.', autogetip)

    if imgui.Button(u8'Сохранить', imgui.ImVec2(255, 20)) then
        mainIni.config.autogetip = autogetip.v
        inicfg.save(mainIni, 'antifloodclickwarp.ini')
    end
end

function Fixed()
    imgui.Checkbox(u8'Фикс автоматического входа в игру.', fix_autopass)
   
    if imgui.Button(u8'Сохранить', imgui.ImVec2(255, 20)) then
        mainIni.config.fix_autopass = fix_autopass.v
        inicfg.save(mainIni, 'antifloodclickwarp.ini')
    end    
end

function OpenCmd()
    if imgui.Button(u8'Зарегистрировать команду.') then
        imgui.OpenPopup(u8'Регистрация команды.')
    end
   
    if imgui.BeginPopup(u8'Регистрация команды.') then
        imgui.InputText(u8'Команда.', cmd)
        imgui.InputText(u8'Тип наказания.', type_n)
        imgui.InputText(u8'Причина.', prich)
        imgui.InputInt(u8'Время.', time_n)
       
            if imgui.Button(u8'Создать команду.') then
                table.insert(list, {cmd = cmd.v})
                table.insert(list, {type_n = type_n.v})
                table.insert(list, {prich = prich.v})
                table.insert(list, {time_n = time_n.v})
                jsonSave(json_file, list)          
                sampRegisterChatCommand(cmd.v, function(num)
                    sampSendChat(u8:decode(string.format("/%s "..num.." %s %s", type_n.v, time_n.v, prich.v)))
                end)
            end
           
        imgui.EndPopup()
    end
end

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then
        return
    end

    while not isSampAvailable() do
        wait(0)
    end
   
    if not doesFileExist(json_file) then jsonSave(json_file, {}) end
    list = jsonRead(json_file)
   
    sampRegisterChatCommand('minitools', cmd_tool)

    sampAddChatMessage('{00ffcc}[MiniToolsAdm] {ffffff}- For Payson!', -1)
    sampAddChatMessage('{00ffcc}[MiniToolsAdm] {ffffff}- Version: 1.0 beta', -1)
    sampAddChatMessage('{00ffcc}[MiniToolsAdm] {ffffff}- Author: Haunted_BabyTape', -1)
   
    sampRegisterChatCommand(cmd.v, function(num)
        sampSendChat(u8:decode(string.format("/%s "..num.." %s %s", type_n.v, time_n.v, prich.v)))
    end)  
   
end

function cmd_tool(arg)
    main_window_state.v = not main_window_state.v
    imgui.Process = main_window_state.v
end

function sampev.onSendCommand(command)
    if yourself.v then
        if (command:find('/a %[Tools%]')) then
            return false
        end
    end
   
    if autogetip.v then
        if (command:find('/re ')) then
            lua_thread.create(function()
                wait(500)
                sampSendChat(u8:decode('/getip '..getClosestPlayerId()))
            end)
        end
    end
end

function sampev.onServerMessage(color, text)
    if other.v then
        if text:find('%{......%}: %[Tools%] Телепортировал') then
            return false
        end
        if text:find('на координаты') then
            return false
        end      
    end
   
    if deletemsg.v then
        if text:find('Вы телепортировали') then
            return false
        end          
    end
end

function sampev.onShowDialog(dialogId, style, title, button1, button2, text)
    if fix_autopass.v then
        if dialogId == 7722 then
            lua_thread.create(function()
                wait(500)
                sampCloseCurrentDialogWithButton(0)
            end)
        end
        if dialogId == 15330 then
            return false
        end
    end
end

function getClosestPlayerId()
    local closestId = -1
    mydist = 30
    local x, y, z = getCharCoordinates(PLAYER_PED)
    for i = 0, 999 do
        local streamed, pedID = sampGetCharHandleBySampPlayerId(i)
        if streamed and getCharHealth(pedID) > 0 and not sampIsPlayerPaused(pedID) then
            local xi, yi, zi = getCharCoordinates(pedID)
            local dist = getDistanceBetweenCoords3d(x, y, z, xi, yi, zi)
            if dist <= mydist then
                mydist = dist
                closestId = i
            end
        end
    end
    return closestId
end

function jsonSave(jsonFilePath, t)
    file = io.open(jsonFilePath, "w")
    file:write(encodeJson(t))
    file:flush()
    file:close()
end

function jsonRead(jsonFilePath)
    local file = io.open(jsonFilePath, "r+")
    local jsonInString = file:read("*a")
    file:close()
    local jsonTable = decodeJson(jsonInString)
    return jsonTable
end
up