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

pavl1nio

Участник
95
13
кенты, помогите сделать так, чтобы при вводе команды высвечивало сообщение в чат, пожалуйста

Lua:
function main()
    sampRegisterChatCommand("pvl", function(arg)
    sampSendChatMessage("first bind by pavlin"..arg)
     end)
wait(-1)
end
 

thebestsupreme

Участник
170
12
sa-mp-000.png


Из за чего это ???

уже поставил decon 8
и все равно когда я нажимаю на кнопку у меня символы


CODE:
script_name('FloodMaster') -- название скрипта
script_author('thebestsupreme') -- автор скрипта

require "lib.moonloader" -- подключение библиотеки
local keys = require "vkeys"
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local tag = "{ff0000}[FloodMaster]:{ffffff}" -- локальная переменная
local label = 0
local main_color = 0x5A90CE
local main_color_text = "{5A90CE}"
local white_color = "{FFFFFF}"

local main_window_state = imgui.ImBool(false)
local secondary_window_state = imgui.ImBool(false)

local test_text_buffer = imgui.ImBuffer(256)
local inicfg = require 'inicfg'

local settings = inicfg.load({
    main =
    {
    flood1 = "",
    flood2 = ""
    }
    }, "hpm")

local status = inicfg.load(settings, 'FloodMaster.ini')
if not doesFileExist('moonloader/config/FloodMaster.ini') then inicfg.save(settings, 'FloodMaster.ini') end
    
    
flood1Input = imgui.ImBuffer(''.. settings.main.flood1, 32)
flood2Input = imgui.ImBuffer(''.. settings.main.flood2, 32)

function blue()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4
    style.Alpha = 1.00

    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.29, 0.48, 0.54)
    colors[clr.FrameBgHovered]         = ImVec4(0.26, 0.59, 0.98, 0.40)
    colors[clr.FrameBgActive]          = ImVec4(0.26, 0.59, 0.98, 0.67)
    colors[clr.TitleBg]                = ImVec4(0.04, 0.04, 0.04, 1.00)
    colors[clr.TitleBgActive]          = ImVec4(0.16, 0.29, 0.48, 1.00)
    colors[clr.TitleBgCollapsed]       = ImVec4(0.00, 0.00, 0.00, 0.51)
    colors[clr.CheckMark]              = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.SliderGrab]             = ImVec4(0.24, 0.52, 0.88, 1.00)
    colors[clr.SliderGrabActive]       = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.Button]                 = ImVec4(0.26, 0.59, 0.98, 0.40)
    colors[clr.ButtonHovered]          = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.ButtonActive]           = ImVec4(0.06, 0.53, 0.98, 1.00)
    colors[clr.Header]                 = ImVec4(0.26, 0.59, 0.98, 0.31)
    colors[clr.HeaderHovered]          = ImVec4(0.26, 0.59, 0.98, 0.80)
    colors[clr.HeaderActive]           = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.Separator]              = colors[clr.Border]
    colors[clr.SeparatorHovered]       = ImVec4(0.26, 0.59, 0.98, 0.78)
    colors[clr.SeparatorActive]        = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.ResizeGrip]             = ImVec4(0.26, 0.59, 0.98, 0.25)
    colors[clr.ResizeGripHovered]      = ImVec4(0.26, 0.59, 0.98, 0.67)
    colors[clr.ResizeGripActive]       = ImVec4(0.26, 0.59, 0.98, 0.95)
    colors[clr.TextSelectedBg]         = ImVec4(0.26, 0.59, 0.98, 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.PlotLines]              = ImVec4(0.61, 0.61, 0.61, 1.00)
    colors[clr.PlotLinesHovered]       = ImVec4(1.00, 0.43, 0.35, 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

blue()

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

    _, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
    nick = sampGetPlayerNickname(id)

    imgui.Process = false

    sampAddChatMessage(tag .. " {000000}blast.hk{ffffff} [thebestsupreme]")
    sampAddChatMessage(tag .. " Скрипт успешно {03ff28}загружен{ffffff}.")

    while true do
        wait(0)
        if isKeyJustPressed(VK_F3) then
            main_window_state.v = not main_window_state.v
            imgui.Process = main_window_state.v
        end
        if isKeyJustPressed(VK_N) then
            sampSendChat("" .. settings.main.flood1)
        end
    end
end

function imgui.OnDrawFrame()

    if not main_window_state.v and not secondary_window_state.v then
        imgui.Process = false
    end

    if main_window_state.v then
        local ex, ey = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(ex / 5, ey / 5), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowSize(imgui.ImVec2(600, 500), imgui.Cond.FirstUseEver)
        imgui.Begin(u8"FloodMaster", main_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
        imgui.Text(u8'Общие настройки')
            imgui.InputText(u8'Введите текст для флуда[N]', flood1Input)
            if imgui.Button(u8'Сохранить текст для флуда') then
            settings.main.flood1 = u8:decode(flood1Input.v)
            inicfg.save(settings, 'FloodMaster.ini')
            sampAddChatMessage(tag .. "Текст для флуда успешно загружен в конфиг.")
            end
        imgui.End()
    end

    if secondary_window_state.v then
        local ex, ey = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(ex / 5, ey / 5), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowSize(imgui.ImVec2(300, 200), imgui.Cond.FirstUseEver)
        imgui.Begin(u8"REPORT", secondary_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
        imgui.InputText(u8'Введите ID', test_text_buffer)
        imgui.End()
    end
end
 

Fott

Простреленный
3,443
2,303
Посмотреть вложение 75011

Из за чего это ???

уже поставил decon 8
и все равно когда я нажимаю на кнопку у меня символы


CODE:
script_name('FloodMaster') -- название скрипта
script_author('thebestsupreme') -- автор скрипта

require "lib.moonloader" -- подключение библиотеки
local keys = require "vkeys"
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local tag = "{ff0000}[FloodMaster]:{ffffff}" -- локальная переменная
local label = 0
local main_color = 0x5A90CE
local main_color_text = "{5A90CE}"
local white_color = "{FFFFFF}"

local main_window_state = imgui.ImBool(false)
local secondary_window_state = imgui.ImBool(false)

local test_text_buffer = imgui.ImBuffer(256)
local inicfg = require 'inicfg'

local settings = inicfg.load({
    main =
    {
    flood1 = "",
    flood2 = ""
    }
    }, "hpm")

local status = inicfg.load(settings, 'FloodMaster.ini')
if not doesFileExist('moonloader/config/FloodMaster.ini') then inicfg.save(settings, 'FloodMaster.ini') end
   
   
flood1Input = imgui.ImBuffer(''.. settings.main.flood1, 32)
flood2Input = imgui.ImBuffer(''.. settings.main.flood2, 32)

function blue()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4
    style.Alpha = 1.00

    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.29, 0.48, 0.54)
    colors[clr.FrameBgHovered]         = ImVec4(0.26, 0.59, 0.98, 0.40)
    colors[clr.FrameBgActive]          = ImVec4(0.26, 0.59, 0.98, 0.67)
    colors[clr.TitleBg]                = ImVec4(0.04, 0.04, 0.04, 1.00)
    colors[clr.TitleBgActive]          = ImVec4(0.16, 0.29, 0.48, 1.00)
    colors[clr.TitleBgCollapsed]       = ImVec4(0.00, 0.00, 0.00, 0.51)
    colors[clr.CheckMark]              = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.SliderGrab]             = ImVec4(0.24, 0.52, 0.88, 1.00)
    colors[clr.SliderGrabActive]       = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.Button]                 = ImVec4(0.26, 0.59, 0.98, 0.40)
    colors[clr.ButtonHovered]          = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.ButtonActive]           = ImVec4(0.06, 0.53, 0.98, 1.00)
    colors[clr.Header]                 = ImVec4(0.26, 0.59, 0.98, 0.31)
    colors[clr.HeaderHovered]          = ImVec4(0.26, 0.59, 0.98, 0.80)
    colors[clr.HeaderActive]           = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.Separator]              = colors[clr.Border]
    colors[clr.SeparatorHovered]       = ImVec4(0.26, 0.59, 0.98, 0.78)
    colors[clr.SeparatorActive]        = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.ResizeGrip]             = ImVec4(0.26, 0.59, 0.98, 0.25)
    colors[clr.ResizeGripHovered]      = ImVec4(0.26, 0.59, 0.98, 0.67)
    colors[clr.ResizeGripActive]       = ImVec4(0.26, 0.59, 0.98, 0.95)
    colors[clr.TextSelectedBg]         = ImVec4(0.26, 0.59, 0.98, 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.PlotLines]              = ImVec4(0.61, 0.61, 0.61, 1.00)
    colors[clr.PlotLinesHovered]       = ImVec4(1.00, 0.43, 0.35, 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

blue()

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

    _, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
    nick = sampGetPlayerNickname(id)

    imgui.Process = false

    sampAddChatMessage(tag .. " {000000}blast.hk{ffffff} [thebestsupreme]")
    sampAddChatMessage(tag .. " Скрипт успешно {03ff28}загружен{ffffff}.")

    while true do
        wait(0)
        if isKeyJustPressed(VK_F3) then
            main_window_state.v = not main_window_state.v
            imgui.Process = main_window_state.v
        end
        if isKeyJustPressed(VK_N) then
            sampSendChat("" .. settings.main.flood1)
        end
    end
end

function imgui.OnDrawFrame()

    if not main_window_state.v and not secondary_window_state.v then
        imgui.Process = false
    end

    if main_window_state.v then
        local ex, ey = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(ex / 5, ey / 5), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowSize(imgui.ImVec2(600, 500), imgui.Cond.FirstUseEver)
        imgui.Begin(u8"FloodMaster", main_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
        imgui.Text(u8'Общие настройки')
            imgui.InputText(u8'Введите текст для флуда[N]', flood1Input)
            if imgui.Button(u8'Сохранить текст для флуда') then
            settings.main.flood1 = u8:decode(flood1Input.v)
            inicfg.save(settings, 'FloodMaster.ini')
            sampAddChatMessage(tag .. "Текст для флуда успешно загружен в конфиг.")
            end
        imgui.End()
    end

    if secondary_window_state.v then
        local ex, ey = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(ex / 5, ey / 5), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowSize(imgui.ImVec2(300, 200), imgui.Cond.FirstUseEver)
        imgui.Begin(u8"REPORT", secondary_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
        imgui.InputText(u8'Введите ID', test_text_buffer)
        imgui.End()
    end
end
Lua:
sampSendChat(u8:decode(settings.main.flood1))
 

BARRY BRADLEY

Известный
711
176
Есть функция которая "парсит" (скачивает ее полностью)
Lua:
function tester()
    local fpath = os.getenv("TEMP") .. "\\Tester.txt"
    downloadUrlToFile("САЙТ", fpath, function(id, status, one, two)
        if status == dlstatus.STATUS_ENDDOWNLOADDATA then
            local file = io.open(fpath, "r")
            if file then
                local reads = file:read("*a")
                if reads and reads ~= nil and reads ~= "" then
                    if reads:find("%[.*%] .*%: .* был забанен администратором .*, причина%: %[.*%] .*") then
                        local date, p1, nickBan, adminBan, reas1, reas2 = reads:match("%[(.*)%] (.*)%: (.*) был забанен администратором (.*), причина%: %[(.*)%] (.*)")
                        for line in reads:gmatch("%[.*%] .*%: .* был забанен администратором .*, причина%: %[.*%] .*") do
                            table.insert(testerTable, line)
                        end
                    end
                end
                io.close(file)
            end
        end
    end)
    os.remove(fpath)
end

Скачивает успешно, но файл вессит аж 9МБ!! И игра просто зависает. Возможно ли как то убрать зависание?
 
Последнее редактирование:

thebestsupreme

Участник
170
12
Lua:
imgui.ImBuffer(u8(database["messages"]), 1000) -- 1000 это кол-во символов в Input
Это к другому вопрос ответ
А тут я говорю как из ?? сделать нормальный текст который находится в конфиге


CODE:
script_name('FloodMaster') -- название скрипта
script_author('thebestsupreme') -- автор скрипта

require "lib.moonloader" -- подключение библиотеки
local keys = require "vkeys"
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local tag = "{ff0000}[FloodMaster]:{ffffff}" -- локальная переменная
local label = 0
local main_color = 0x5A90CE
local main_color_text = "{5A90CE}"
local white_color = "{FFFFFF}"

local main_window_state = imgui.ImBool(false)
local secondary_window_state = imgui.ImBool(false)

local test_text_buffer = imgui.ImBuffer(256)
local inicfg = require 'inicfg'

local settings = inicfg.load({
    main =
    {
    flood1 = "",
    flood2 = ""
    }
    }, "hpm")

local status = inicfg.load(settings, 'FloodMaster.ini')
if not doesFileExist('moonloader/config/FloodMaster.ini') then inicfg.save(settings, 'FloodMaster.ini') end
    
    
flood1Input = imgui.ImBuffer(''.. settings.main.flood1, 99)
flood2Input = imgui.ImBuffer(''.. settings.main.flood2, 99)

function blue()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4
    style.Alpha = 1.00

    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.29, 0.48, 0.54)
    colors[clr.FrameBgHovered]         = ImVec4(0.26, 0.59, 0.98, 0.40)
    colors[clr.FrameBgActive]          = ImVec4(0.26, 0.59, 0.98, 0.67)
    colors[clr.TitleBg]                = ImVec4(0.04, 0.04, 0.04, 1.00)
    colors[clr.TitleBgActive]          = ImVec4(0.16, 0.29, 0.48, 1.00)
    colors[clr.TitleBgCollapsed]       = ImVec4(0.00, 0.00, 0.00, 0.51)
    colors[clr.CheckMark]              = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.SliderGrab]             = ImVec4(0.24, 0.52, 0.88, 1.00)
    colors[clr.SliderGrabActive]       = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.Button]                 = ImVec4(0.26, 0.59, 0.98, 0.40)
    colors[clr.ButtonHovered]          = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.ButtonActive]           = ImVec4(0.06, 0.53, 0.98, 1.00)
    colors[clr.Header]                 = ImVec4(0.26, 0.59, 0.98, 0.31)
    colors[clr.HeaderHovered]          = ImVec4(0.26, 0.59, 0.98, 0.80)
    colors[clr.HeaderActive]           = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.Separator]              = colors[clr.Border]
    colors[clr.SeparatorHovered]       = ImVec4(0.26, 0.59, 0.98, 0.78)
    colors[clr.SeparatorActive]        = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.ResizeGrip]             = ImVec4(0.26, 0.59, 0.98, 0.25)
    colors[clr.ResizeGripHovered]      = ImVec4(0.26, 0.59, 0.98, 0.67)
    colors[clr.ResizeGripActive]       = ImVec4(0.26, 0.59, 0.98, 0.95)
    colors[clr.TextSelectedBg]         = ImVec4(0.26, 0.59, 0.98, 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.PlotLines]              = ImVec4(0.61, 0.61, 0.61, 1.00)
    colors[clr.PlotLinesHovered]       = ImVec4(1.00, 0.43, 0.35, 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

blue()

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

    _, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
    nick = sampGetPlayerNickname(id)

    imgui.Process = false

    sampAddChatMessage(tag .. " {000000}blast.hk{ffffff} [thebestsupreme]")
    sampAddChatMessage(tag .. " Скрипт успешно {03ff28}загружен{ffffff}.")

    while true do
        wait(0)
        if isKeyJustPressed(VK_F3) then
            main_window_state.v = not main_window_state.v
            imgui.Process = main_window_state.v
        end
        if isKeyJustPressed(VK_N) then
            sampSendChat(u8:decode"" .. settings.main.flood1)
        end
        if isKeyJustPressed(VK_M) then
            sampSendChat(u8:decode(settings.main.flood2))
        end
    end
end

function imgui.OnDrawFrame()

    if not main_window_state.v and not secondary_window_state.v then
        imgui.Process = false
    end

    if main_window_state.v then
        local ex, ey = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(ex / 5, ey / 5), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowSize(imgui.ImVec2(600, 150), imgui.Cond.FirstUseEver)
        imgui.Begin(u8"FloodMaster", main_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
        imgui.Text(u8'Общие настройки')
            imgui.InputText(u8'Введите текст для флуда[N]', flood1Input)
                if imgui.Button(u8'Сохранить текст для флуда[N]') then
                    settings.main.flood1 = u8:decode(flood1Input.v)
                    inicfg.save(settings, 'FloodMaster.ini')
                    sampAddChatMessage(tag .. "Текст для флуда успешно загружен в конфиг.[N]")
                end
                imgui.InputText(u8'Введите текст для флуда[M]', flood2Input)
                    if imgui.Button(u8"Сохранить текст для флуда[M]") then
                    settings.main.flood2 = u8:decode(flood2Input.v)
                    inicfg.save(settings, 'FloodMaster.ini')
                    sampAddChatMessage(tag .. "Текст для флуда успешно загружен в конфиг.[M]")
                end
            imgui.End()
        end

    if secondary_window_state.v then
        local ex, ey = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(ex / 5, ey / 5), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowSize(imgui.ImVec2(300, 200), imgui.Cond.FirstUseEver)
        imgui.Begin(u8"REPORT", secondary_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
        imgui.InputText(u8'Введите ID', test_text_buffer)
        imgui.End()
    end
end
 

BARRY BRADLEY

Известный
711
176
Это к другому вопрос ответ
А тут я говорю как из ?? сделать нормальный текст который находится в конфиге


CODE:
script_name('FloodMaster') -- название скрипта
script_author('thebestsupreme') -- автор скрипта

require "lib.moonloader" -- подключение библиотеки
local keys = require "vkeys"
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local tag = "{ff0000}[FloodMaster]:{ffffff}" -- локальная переменная
local label = 0
local main_color = 0x5A90CE
local main_color_text = "{5A90CE}"
local white_color = "{FFFFFF}"

local main_window_state = imgui.ImBool(false)
local secondary_window_state = imgui.ImBool(false)

local test_text_buffer = imgui.ImBuffer(256)
local inicfg = require 'inicfg'

local settings = inicfg.load({
    main =
    {
    flood1 = "",
    flood2 = ""
    }
    }, "hpm")

local status = inicfg.load(settings, 'FloodMaster.ini')
if not doesFileExist('moonloader/config/FloodMaster.ini') then inicfg.save(settings, 'FloodMaster.ini') end
  
  
flood1Input = imgui.ImBuffer(''.. settings.main.flood1, 99)
flood2Input = imgui.ImBuffer(''.. settings.main.flood2, 99)

function blue()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4
    style.Alpha = 1.00

    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.29, 0.48, 0.54)
    colors[clr.FrameBgHovered]         = ImVec4(0.26, 0.59, 0.98, 0.40)
    colors[clr.FrameBgActive]          = ImVec4(0.26, 0.59, 0.98, 0.67)
    colors[clr.TitleBg]                = ImVec4(0.04, 0.04, 0.04, 1.00)
    colors[clr.TitleBgActive]          = ImVec4(0.16, 0.29, 0.48, 1.00)
    colors[clr.TitleBgCollapsed]       = ImVec4(0.00, 0.00, 0.00, 0.51)
    colors[clr.CheckMark]              = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.SliderGrab]             = ImVec4(0.24, 0.52, 0.88, 1.00)
    colors[clr.SliderGrabActive]       = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.Button]                 = ImVec4(0.26, 0.59, 0.98, 0.40)
    colors[clr.ButtonHovered]          = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.ButtonActive]           = ImVec4(0.06, 0.53, 0.98, 1.00)
    colors[clr.Header]                 = ImVec4(0.26, 0.59, 0.98, 0.31)
    colors[clr.HeaderHovered]          = ImVec4(0.26, 0.59, 0.98, 0.80)
    colors[clr.HeaderActive]           = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.Separator]              = colors[clr.Border]
    colors[clr.SeparatorHovered]       = ImVec4(0.26, 0.59, 0.98, 0.78)
    colors[clr.SeparatorActive]        = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.ResizeGrip]             = ImVec4(0.26, 0.59, 0.98, 0.25)
    colors[clr.ResizeGripHovered]      = ImVec4(0.26, 0.59, 0.98, 0.67)
    colors[clr.ResizeGripActive]       = ImVec4(0.26, 0.59, 0.98, 0.95)
    colors[clr.TextSelectedBg]         = ImVec4(0.26, 0.59, 0.98, 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.PlotLines]              = ImVec4(0.61, 0.61, 0.61, 1.00)
    colors[clr.PlotLinesHovered]       = ImVec4(1.00, 0.43, 0.35, 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

blue()

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

    _, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
    nick = sampGetPlayerNickname(id)

    imgui.Process = false

    sampAddChatMessage(tag .. " {000000}blast.hk{ffffff} [thebestsupreme]")
    sampAddChatMessage(tag .. " Скрипт успешно {03ff28}загружен{ffffff}.")

    while true do
        wait(0)
        if isKeyJustPressed(VK_F3) then
            main_window_state.v = not main_window_state.v
            imgui.Process = main_window_state.v
        end
        if isKeyJustPressed(VK_N) then
            sampSendChat(u8:decode"" .. settings.main.flood1)
        end
        if isKeyJustPressed(VK_M) then
            sampSendChat(u8:decode(settings.main.flood2))
        end
    end
end

function imgui.OnDrawFrame()

    if not main_window_state.v and not secondary_window_state.v then
        imgui.Process = false
    end

    if main_window_state.v then
        local ex, ey = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(ex / 5, ey / 5), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowSize(imgui.ImVec2(600, 150), imgui.Cond.FirstUseEver)
        imgui.Begin(u8"FloodMaster", main_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
        imgui.Text(u8'Общие настройки')
            imgui.InputText(u8'Введите текст для флуда[N]', flood1Input)
                if imgui.Button(u8'Сохранить текст для флуда[N]') then
                    settings.main.flood1 = u8:decode(flood1Input.v)
                    inicfg.save(settings, 'FloodMaster.ini')
                    sampAddChatMessage(tag .. "Текст для флуда успешно загружен в конфиг.[N]")
                end
                imgui.InputText(u8'Введите текст для флуда[M]', flood2Input)
                    if imgui.Button(u8"Сохранить текст для флуда[M]") then
                    settings.main.flood2 = u8:decode(flood2Input.v)
                    inicfg.save(settings, 'FloodMaster.ini')
                    sampAddChatMessage(tag .. "Текст для флуда успешно загружен в конфиг.[M]")
                end
            imgui.End()
        end

    if secondary_window_state.v then
        local ex, ey = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(ex / 5, ey / 5), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowSize(imgui.ImVec2(300, 200), imgui.Cond.FirstUseEver)
        imgui.Begin(u8"REPORT", secondary_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
        imgui.InputText(u8'Введите ID', test_text_buffer)
        imgui.End()
    end
end
Lua:
u8:decode(text) --При вносе в ini
Для норм вывода с конфига ответ был выше
 

Viem

Известный
49
5
Как сделать так, чтобы линия

renderDrawLine

не рисовалась, если я не вижу одну из координат?

т.е точка к которой идет линия находится вне моего обзора