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

Alkoigel

Участник
116
15
Всем привет. Пытаюсь написать свой первый скрипт. Использую mimgui графику. Скрипт должен упростить работу следящих за гетто админов на одном сервере.

На данный момент имею вот это:
mimgui часть:
function imgui.OnDrawFrame()
    imgui.SetNextWindowSize(imgui.ImVec2(500, 300), imgui.Cond.FirstUseEver)
    imgui.SetNextWindowPos(imgui.ImVec2((sw / 2), sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))

    imgui.Begin("Ghetto Helper", main_window_state) -- название окна


    imgui.RadioButton(u8"Грув", checked_band, 2)            -- название круга, переменная,
    imgui.SameLine()
    imgui.RadioButton(u8"Баллас", checked_band, 3)            -- название круга, переменная,
    imgui.SameLine()
    imgui.RadioButton(u8"Вагос", checked_band, 4)            -- название круга, переменная,
    imgui.SameLine()
    imgui.RadioButton(u8"Ацтек", checked_band, 5)            -- название круга, переменная,
    imgui.SameLine()
    imgui.RadioButton(u8"Рифа", checked_band, 6)            -- название круга, переменная,

    imgui.Separator()

    imgui.Checkbox(u8"Наказание 1/3", checked_NakNumber)            -- название квадрата, переменная.
    imgui.Checkbox(u8"Наказание 2/3", checked_NakNumber_2)            -- название квадрата, переменная.
    imgui.Checkbox(u8"Наказание 3/3", checked_NakNumber_3)            -- название квадрата, переменная.

    imgui.Combo(u8"Причина", combo_select, arr_cheat, #arr_cheat)

    imgui.End()
end
Выглядит это Вот так:
1623194670731.png

Так же имею массив
Lua:
local arr_cheat = {"Aimbot", "WallHack", "Spread", "Speedhack", "Saim", "DMG", "SK", "Provo na SK", "Fly", "AirBreak", "Flycar"}

Нужна помощь.
Как мне реализовать следующее:
Ставится галочка на одну из бан и один из видов наказаний (Наказание 1/3 и т.д.)
После чего выбирается наказание. В зависимости от нарушения - jail / ban.

То есть скрипт собирает информацию из этой менюшки, после чего выводит samdSendChat(/ban[или джаил] id причину и какое это наказание по счёту.

Буду очень благодарен.

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

local tag = "[My First Script]:" -- локальная переменная
local label = 0
local main_color = 0x5A90CE
local main_color_text = "{5A90CE}"
local white_color = "{FFFFFF}"
local arr_cheat = {"Aimbot", "WallHack", "Spread", "Speedhack", "Saim", "DMG", "SK", "Provo na SK", "Fly", "AirBreak", "Flycar"}

local main_window_state = imgui.ImBool(false)
local text_buffer = imgui.ImBuffer(256)


-- чекбоксы
    local checked_NakNumber        = imgui.ImBool(false)
    local checked_NakNumber_2    = imgui.ImBool(false)
    local checked_NakNumber_3    = imgui.ImBool(false)
--

-- радиокнопки
    local checked_band        = imgui.ImInt(1)
 
--

--комбобоксы
    local combo_select         =imgui.ImInt(0)
--

local sw, sh = getScreenResolution()

function SetStyle()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4
    style.ScrollbarSize = 13.0
    style.ScrollbarRounding = 0
    style.ChildWindowRounding = 4.0
    colors[clr.PopupBg]                = ImVec4(0.08, 0.08, 0.08, 0.94)
    colors[clr.ComboBg]                = colors[clr.PopupBg]
    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.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.CloseButton]            = ImVec4(0.41, 0.41, 0.41, 0.50)-- (0.1, 0.9, 0.1, 1.0)
    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.TextSelectedBg]         = ImVec4(0.26, 0.59, 0.98, 0.35)
    colors[clr.Text]                   = ImVec4(1.00, 1.00, 1.00, 1.00)
    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.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.CheckMark]              = ImVec4(0.26, 0.59, 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.SliderGrab]             = ImVec4(0.24, 0.52, 0.88, 1.00)
    colors[clr.SliderGrabActive]       = ImVec4(0.26, 0.59, 0.98, 1.00)
end
SetStyle()

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

    sampRegisterChatCommand("imgui", cmd_imgui)
    sampRegisterChatCommand("check", cmd_check)
    _, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
    nick = sampGetPlayerNickname(id)

    imgui.Process = false
    --sampAddChatMessage("Скрипт imgui перезагружен", -1)

    while true do
        wait(0)
        if isKeyJustPressed(VK_F3) then
            cmd_imgui()
        end
        if isKeyJustPressed(VK_F4) then
            cmd_check()
        end

        if main_window_state.v == false then
            imgui.Process = false
        end
        -- Блок выполняющийся бесконечно (пока самп активен)

    end
end

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

function cmd_check(arg)
    sampAddChatMessage(checked_band.v, -1)
end

function imgui.OnDrawFrame()
    imgui.SetNextWindowSize(imgui.ImVec2(500, 300), imgui.Cond.FirstUseEver)
    imgui.SetNextWindowPos(imgui.ImVec2((sw / 2), sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))

    imgui.Begin("Ghetto Helper", main_window_state) -- название окна


    imgui.RadioButton(u8"Грув", checked_band, 2)            -- название круга, переменная,
    imgui.SameLine()
    imgui.RadioButton(u8"Баллас", checked_band, 3)            -- название круга, переменная,
    imgui.SameLine()
    imgui.RadioButton(u8"Вагос", checked_band, 4)            -- название круга, переменная,
    imgui.SameLine()
    imgui.RadioButton(u8"Ацтек", checked_band, 5)            -- название круга, переменная,

    imgui.Separator()

    imgui.Checkbox(u8"Наказание 1/3", checked_NakNumber)            -- название квадрата, переменная.
    imgui.Checkbox(u8"Наказание 2/3", checked_NakNumber_2)            -- название квадрата, переменная.
    imgui.Checkbox(u8"Наказание 3/3", checked_NakNumber_3)            -- название квадрата, переменная.

    arr_cheat = {"Aimbot", "WallHack", "Spread", "Speedhack", "Saim", "DMG", "SK", "Provo na SK", "Fly", "AirBreak", "Flycar"}

    imgui.Combo(u8"Причина", combo_select, arr_cheat, #arr_cheat)



    imgui.End()
end


--[[
    radiobutton - круглешки, выбрать 1 пункт
    checkbox - поставить галочку на чекбокс
    combobox - список в котором выбрать пункт

                if imgui.Button("press Me") then
                    sampAddChatMessage(u8:decode(text_buffer.v), -1)
                end

]]
 
Последнее редактирование:

Dmitriy Makarov

25.05.2021
Проверенный
2,481
1,113
Всем привет. Пытаюсь написать свой первый скрипт. Использую mimgui графику. Скрипт должен упростить работу следящих за гетто админов на одном сервере.

На данный момент имею вот это:
mimgui часть:
function imgui.OnDrawFrame()
    imgui.SetNextWindowSize(imgui.ImVec2(500, 300), imgui.Cond.FirstUseEver)
    imgui.SetNextWindowPos(imgui.ImVec2((sw / 2), sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))

    imgui.Begin("Ghetto Helper", main_window_state) -- название окна


    imgui.RadioButton(u8"Грув", checked_band, 2)            -- название круга, переменная,
    imgui.SameLine()
    imgui.RadioButton(u8"Баллас", checked_band, 3)            -- название круга, переменная,
    imgui.SameLine()
    imgui.RadioButton(u8"Вагос", checked_band, 4)            -- название круга, переменная,
    imgui.SameLine()
    imgui.RadioButton(u8"Ацтек", checked_band, 5)            -- название круга, переменная,
    imgui.SameLine()
    imgui.RadioButton(u8"Рифа", checked_band, 6)            -- название круга, переменная,

    imgui.Separator()

    imgui.Checkbox(u8"Наказание 1/3", checked_NakNumber)            -- название квадрата, переменная.
    imgui.Checkbox(u8"Наказание 2/3", checked_NakNumber_2)            -- название квадрата, переменная.
    imgui.Checkbox(u8"Наказание 3/3", checked_NakNumber_3)            -- название квадрата, переменная.

    imgui.Combo(u8"Причина", combo_select, arr_cheat, #arr_cheat)

    imgui.End()
end
Выглядит это Вот так:
Посмотреть вложение 100339

Так же имею массив
Lua:
local arr_cheat = {"Aimbot", "WallHack", "Spread", "Speedhack", "Saim", "DMG", "SK", "Provo na SK", "Fly", "AirBreak", "Flycar"}

Нужна помощь.
Как мне реализовать следующее:
Ставится галочка на одну из бан и один из видов наказаний (Наказание 1/3 и т.д.)
После чего выбирается наказание. В зависимости от нарушения - jail / ban.

То есть скрипт собирает информацию из этой менюшки, после чего выводит samdSendChat(/ban[или джаил] id причину и какое это наказание по счёту.

Буду очень благодарен.

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

local tag = "[My First Script]:" -- локальная переменная
local label = 0
local main_color = 0x5A90CE
local main_color_text = "{5A90CE}"
local white_color = "{FFFFFF}"
local arr_cheat = {"Aimbot", "WallHack", "Spread", "Speedhack", "Saim", "DMG", "SK", "Provo na SK", "Fly", "AirBreak", "Flycar"}

local main_window_state = imgui.ImBool(false)
local text_buffer = imgui.ImBuffer(256)


-- чекбоксы
    local checked_NakNumber        = imgui.ImBool(false)
    local checked_NakNumber_2    = imgui.ImBool(false)
    local checked_NakNumber_3    = imgui.ImBool(false)
--

-- радиокнопки
    local checked_band        = imgui.ImInt(1)

--

--комбобоксы
    local combo_select         =imgui.ImInt(0)
--

local sw, sh = getScreenResolution()

function SetStyle()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4
    style.ScrollbarSize = 13.0
    style.ScrollbarRounding = 0
    style.ChildWindowRounding = 4.0
    colors[clr.PopupBg]                = ImVec4(0.08, 0.08, 0.08, 0.94)
    colors[clr.ComboBg]                = colors[clr.PopupBg]
    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.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.CloseButton]            = ImVec4(0.41, 0.41, 0.41, 0.50)-- (0.1, 0.9, 0.1, 1.0)
    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.TextSelectedBg]         = ImVec4(0.26, 0.59, 0.98, 0.35)
    colors[clr.Text]                   = ImVec4(1.00, 1.00, 1.00, 1.00)
    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.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.CheckMark]              = ImVec4(0.26, 0.59, 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.SliderGrab]             = ImVec4(0.24, 0.52, 0.88, 1.00)
    colors[clr.SliderGrabActive]       = ImVec4(0.26, 0.59, 0.98, 1.00)
end
SetStyle()

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

    sampRegisterChatCommand("imgui", cmd_imgui)
    sampRegisterChatCommand("check", cmd_check)
    _, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
    nick = sampGetPlayerNickname(id)

    imgui.Process = false
    --sampAddChatMessage("Скрипт imgui перезагружен", -1)

    while true do
        wait(0)
        if isKeyJustPressed(VK_F3) then
            cmd_imgui()
        end
        if isKeyJustPressed(VK_F4) then
            cmd_check()
        end

        if main_window_state.v == false then
            imgui.Process = false
        end
        -- Блок выполняющийся бесконечно (пока самп активен)

    end
end

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

function cmd_check(arg)
    sampAddChatMessage(checked_band.v, -1)
end

function imgui.OnDrawFrame()
    imgui.SetNextWindowSize(imgui.ImVec2(500, 300), imgui.Cond.FirstUseEver)
    imgui.SetNextWindowPos(imgui.ImVec2((sw / 2), sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))

    imgui.Begin("Ghetto Helper", main_window_state) -- название окна


    imgui.RadioButton(u8"Грув", checked_band, 2)            -- название круга, переменная,
    imgui.SameLine()
    imgui.RadioButton(u8"Баллас", checked_band, 3)            -- название круга, переменная,
    imgui.SameLine()
    imgui.RadioButton(u8"Вагос", checked_band, 4)            -- название круга, переменная,
    imgui.SameLine()
    imgui.RadioButton(u8"Ацтек", checked_band, 5)            -- название круга, переменная,

    imgui.Separator()

    imgui.Checkbox(u8"Наказание 1/3", checked_NakNumber)            -- название квадрата, переменная.
    imgui.Checkbox(u8"Наказание 2/3", checked_NakNumber_2)            -- название квадрата, переменная.
    imgui.Checkbox(u8"Наказание 3/3", checked_NakNumber_3)            -- название квадрата, переменная.

    arr_cheat = {"Aimbot", "WallHack", "Spread", "Speedhack", "Saim", "DMG", "SK", "Provo na SK", "Fly", "AirBreak", "Flycar"}

    imgui.Combo(u8"Причина", combo_select, arr_cheat, #arr_cheat)



    imgui.End()
end


--[[
    radiobutton - круглешки, выбрать 1 пункт
    checkbox - поставить галочку на чекбокс
    combobox - список в котором выбрать пункт

                if imgui.Button("press Me") then
                    sampAddChatMessage(u8:decode(text_buffer.v), -1)
                end

]]
Там же по идее кнопка выполнения этих действий должна быть в самом ImGui окне. 🤔
И ещё, чей ID должен вводиться в чат, когда ты выбираешь одну из банд?
 

PanSeek

t.me/dailypanseek
Всефорумный модератор
899
1,746
Всем привет. Пытаюсь написать свой первый скрипт. Использую mimgui графику. Скрипт должен упростить работу следящих за гетто админов на одном сервере.

На данный момент имею вот это:
mimgui часть:
function imgui.OnDrawFrame()
    imgui.SetNextWindowSize(imgui.ImVec2(500, 300), imgui.Cond.FirstUseEver)
    imgui.SetNextWindowPos(imgui.ImVec2((sw / 2), sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))

    imgui.Begin("Ghetto Helper", main_window_state) -- название окна


    imgui.RadioButton(u8"Грув", checked_band, 2)            -- название круга, переменная,
    imgui.SameLine()
    imgui.RadioButton(u8"Баллас", checked_band, 3)            -- название круга, переменная,
    imgui.SameLine()
    imgui.RadioButton(u8"Вагос", checked_band, 4)            -- название круга, переменная,
    imgui.SameLine()
    imgui.RadioButton(u8"Ацтек", checked_band, 5)            -- название круга, переменная,
    imgui.SameLine()
    imgui.RadioButton(u8"Рифа", checked_band, 6)            -- название круга, переменная,

    imgui.Separator()

    imgui.Checkbox(u8"Наказание 1/3", checked_NakNumber)            -- название квадрата, переменная.
    imgui.Checkbox(u8"Наказание 2/3", checked_NakNumber_2)            -- название квадрата, переменная.
    imgui.Checkbox(u8"Наказание 3/3", checked_NakNumber_3)            -- название квадрата, переменная.

    imgui.Combo(u8"Причина", combo_select, arr_cheat, #arr_cheat)

    imgui.End()
end
Выглядит это Вот так:
Посмотреть вложение 100339

Так же имею массив
Lua:
local arr_cheat = {"Aimbot", "WallHack", "Spread", "Speedhack", "Saim", "DMG", "SK", "Provo na SK", "Fly", "AirBreak", "Flycar"}

Нужна помощь.
Как мне реализовать следующее:
Ставится галочка на одну из бан и один из видов наказаний (Наказание 1/3 и т.д.)
После чего выбирается наказание. В зависимости от нарушения - jail / ban.

То есть скрипт собирает информацию из этой менюшки, после чего выводит samdSendChat(/ban[или джаил] id причину и какое это наказание по счёту.

Буду очень благодарен.

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

local tag = "[My First Script]:" -- локальная переменная
local label = 0
local main_color = 0x5A90CE
local main_color_text = "{5A90CE}"
local white_color = "{FFFFFF}"
local arr_cheat = {"Aimbot", "WallHack", "Spread", "Speedhack", "Saim", "DMG", "SK", "Provo na SK", "Fly", "AirBreak", "Flycar"}

local main_window_state = imgui.ImBool(false)
local text_buffer = imgui.ImBuffer(256)


-- чекбоксы
    local checked_NakNumber        = imgui.ImBool(false)
    local checked_NakNumber_2    = imgui.ImBool(false)
    local checked_NakNumber_3    = imgui.ImBool(false)
--

-- радиокнопки
    local checked_band        = imgui.ImInt(1)

--

--комбобоксы
    local combo_select         =imgui.ImInt(0)
--

local sw, sh = getScreenResolution()

function SetStyle()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4
    style.ScrollbarSize = 13.0
    style.ScrollbarRounding = 0
    style.ChildWindowRounding = 4.0
    colors[clr.PopupBg]                = ImVec4(0.08, 0.08, 0.08, 0.94)
    colors[clr.ComboBg]                = colors[clr.PopupBg]
    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.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.CloseButton]            = ImVec4(0.41, 0.41, 0.41, 0.50)-- (0.1, 0.9, 0.1, 1.0)
    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.TextSelectedBg]         = ImVec4(0.26, 0.59, 0.98, 0.35)
    colors[clr.Text]                   = ImVec4(1.00, 1.00, 1.00, 1.00)
    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.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.CheckMark]              = ImVec4(0.26, 0.59, 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.SliderGrab]             = ImVec4(0.24, 0.52, 0.88, 1.00)
    colors[clr.SliderGrabActive]       = ImVec4(0.26, 0.59, 0.98, 1.00)
end
SetStyle()

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

    sampRegisterChatCommand("imgui", cmd_imgui)
    sampRegisterChatCommand("check", cmd_check)
    _, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
    nick = sampGetPlayerNickname(id)

    imgui.Process = false
    --sampAddChatMessage("Скрипт imgui перезагружен", -1)

    while true do
        wait(0)
        if isKeyJustPressed(VK_F3) then
            cmd_imgui()
        end
        if isKeyJustPressed(VK_F4) then
            cmd_check()
        end

        if main_window_state.v == false then
            imgui.Process = false
        end
        -- Блок выполняющийся бесконечно (пока самп активен)

    end
end

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

function cmd_check(arg)
    sampAddChatMessage(checked_band.v, -1)
end

function imgui.OnDrawFrame()
    imgui.SetNextWindowSize(imgui.ImVec2(500, 300), imgui.Cond.FirstUseEver)
    imgui.SetNextWindowPos(imgui.ImVec2((sw / 2), sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))

    imgui.Begin("Ghetto Helper", main_window_state) -- название окна


    imgui.RadioButton(u8"Грув", checked_band, 2)            -- название круга, переменная,
    imgui.SameLine()
    imgui.RadioButton(u8"Баллас", checked_band, 3)            -- название круга, переменная,
    imgui.SameLine()
    imgui.RadioButton(u8"Вагос", checked_band, 4)            -- название круга, переменная,
    imgui.SameLine()
    imgui.RadioButton(u8"Ацтек", checked_band, 5)            -- название круга, переменная,

    imgui.Separator()

    imgui.Checkbox(u8"Наказание 1/3", checked_NakNumber)            -- название квадрата, переменная.
    imgui.Checkbox(u8"Наказание 2/3", checked_NakNumber_2)            -- название квадрата, переменная.
    imgui.Checkbox(u8"Наказание 3/3", checked_NakNumber_3)            -- название квадрата, переменная.

    arr_cheat = {"Aimbot", "WallHack", "Spread", "Speedhack", "Saim", "DMG", "SK", "Provo na SK", "Fly", "AirBreak", "Flycar"}

    imgui.Combo(u8"Причина", combo_select, arr_cheat, #arr_cheat)



    imgui.End()
end


--[[
    radiobutton - круглешки, выбрать 1 пункт
    checkbox - поставить галочку на чекбокс
    combobox - список в котором выбрать пункт

                if imgui.Button("press Me") then
                    sampAddChatMessage(u8:decode(text_buffer.v), -1)
                end

]]
Lua:
require "lib.moonloader"
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
--imgui vars
local main_window_state = imgui.ImBool(false)
local number_puns = imgui.ImBuffer(512)
local number_id = imgui.ImBuffer(1024)
local checked_band = imgui.ImInt(0)
local checked_nak = imgui.ImInt(0)
local checked_act = imgui.ImInt(0)
local combo_select = imgui.ImInt(0)
--other vars
local arr = {
    cheat = {
        "Aimbot",
        "WallHack",
        "Spread",
        "Speedhack",
        "Saim",
        "DMG",
        "SK",
        "Provo na SK",
        "Fly",
        "AirBreak",
        "Flycar"
    },
    band = {
        'Грув',
        'Баллас',
        'Вагос',
        'Ацтек'
    },
    nak = {
        '1/3',
        '2/3',
        '3/3'
    },
    act = {
        '/ban',
        '/jail'
    }
}
local tag = "[My First Script]:"
local sw, sh = getScreenResolution()

function SetStyle()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4
    style.ScrollbarSize = 13.0
    style.ScrollbarRounding = 0
    style.ChildWindowRounding = 4.0
    colors[clr.PopupBg]                = ImVec4(0.08, 0.08, 0.08, 0.94)
    colors[clr.ComboBg]                = colors[clr.PopupBg]
    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.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.CloseButton]            = ImVec4(0.41, 0.41, 0.41, 0.50)-- (0.1, 0.9, 0.1, 1.0)
    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.TextSelectedBg]         = ImVec4(0.26, 0.59, 0.98, 0.35)
    colors[clr.Text]                   = ImVec4(1.00, 1.00, 1.00, 1.00)
    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.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.CheckMark]              = ImVec4(0.26, 0.59, 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.SliderGrab]             = ImVec4(0.24, 0.52, 0.88, 1.00)
    colors[clr.SliderGrabActive]       = ImVec4(0.26, 0.59, 0.98, 1.00)
end
SetStyle()

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

    sampRegisterChatCommand("imgui", function() main_window_state.v = not main_window_state.v end)
    sampRegisterChatCommand("check", cmd_check)

    while true do
        wait(0)
        imgui.Process = main_window_state.v
        if isKeyJustPressed(VK_F3) then main_window_state.v = not main_window_state.v end
        if isKeyJustPressed(VK_F4) then cmd_check() end
    end
end

function imgui.OnDrawFrame()
    if main_window_state.v then
        imgui.SetNextWindowSize(imgui.ImVec2(500, 300), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowPos(imgui.ImVec2((sw / 2), sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.Begin("Ghetto Helper", main_window_state)
        imgui.RadioButton(u8"Грув", checked_band, 0); imgui.SameLine()
        imgui.RadioButton(u8"Баллас", checked_band, 1); imgui.SameLine()
        imgui.RadioButton(u8"Вагос", checked_band, 2); imgui.SameLine()
        imgui.RadioButton(u8"Ацтек", checked_band, 3)
        imgui.Separator()
        imgui.Combo(u8"Причина", combo_select, arr.cheat, #arr.cheat)
        imgui.RadioButton("1/3", checked_nak, 0); imgui.SameLine()
        imgui.RadioButton("2/3", checked_nak, 1); imgui.SameLine()
        imgui.RadioButton("3/3", checked_nak, 2)
        imgui.Text(u8'Наказание: '); imgui.SameLine()
        imgui.RadioButton("Ban", checked_act, 0); imgui.SameLine()
        imgui.RadioButton("Jail", checked_act, 1); imgui.SameLine()
        imgui.PushItemWidth(50)
        imgui.InputText(checked_act.v == 0 and u8'Кол-во дней' or u8'Кол-во минут', number_puns)
        imgui.InputText('ID', number_id)
        imgui.PopItemWidth()
        if imgui.Button(u8'Выдать наказание!') then
            sampSendChat(arr.act[checked_act.v + 1]..' '..number_id.v..' '..number_puns.v..' '..arr.cheat[combo_select.v + 1]..' '..arr.band[checked_band.v + 1]..' ['..arr.nak[checked_nak.v + 1]..']')
        end
        imgui.End()
    end
end

function cmd_check()
    sampAddChatMessage(string.format('Выбрана банда: %s | Выбрано наказание: %s %s | Чит: %s', arr.band[checked_band.v + 1], arr.nak[checked_nak.v + 1], arr.act[checked_act.v + 1], arr.cheat[combo_select.v + 1]), -1)
end
Не знаю зачем тебе стиль, просто он обычный.
И это не mimgui, не путай.
С ID не знал что делать, сделал так, думаю разберешься +-.
2021-06-09 03-05-37-130.png

2021-06-09 03-07-26-018.png
 

asensio dredds

Участник
48
0
Lua:
require 'moonloader'
local imgui = require 'imgui'
local active = false

function main()
    repeat wait(0) until isSampAvailable()
    imgui.Process = false
    while true do wait(0)
        if isKeyJustPressed(VK_M) then
        active = not active
        end
        imgui.Process = active
    end
end

А если у меня их несколько, то как сделать на определенное окно?
 

LelHack

Известный
456
124
А если у меня их несколько, то как сделать на определенное окно?
кодик:
require 'moonloader'
local imgui = require 'imgui'
local active = false

function main()
    repeat wait(0) until isSampAvailable()
    imgui.Process = false
    while true do wait(0)
        if isKeyJustPressed(VK_M) then
        active = not active
        end
        imgui.Process = main_windows.v
    end
end
 

Adrian G.

Известный
Проверенный
521
454
А если у меня их несколько, то как сделать на определенное окно?

Lua:
require 'moonloader'
local imgui = require 'imgui'
local active = false
local window = imgui.ImBool(false) --окно имгуи
local window2 = imgui.ImBool(false) --второе окно
function main()
    repeat wait(0) until isSampAvailable()
    imgui.Process = false
    while true do wait(0)
        if isKeyJustPressed(VK_M) then
        window.v = not window.v
        elseif isKeyJustPressed(VK_N) then
        window2.v = not window2.v
        end
        imgui.Process = window.v or window2.v
    end
end
 

asensio dredds

Участник
48
0
Lua:
require 'moonloader'
local imgui = require 'imgui'
local active = false
local window = imgui.ImBool(false) --окно имгуи
local window2 = imgui.ImBool(false) --второе окно
function main()
    repeat wait(0) until isSampAvailable()
    imgui.Process = false
    while true do wait(0)
        if isKeyJustPressed(VK_M) then
        window.v = not window.v
        elseif isKeyJustPressed(VK_N) then
        window2.v = not window2.v
        end
        imgui.Process = window.v or window2.v
    end
end
Получилось, большое спасибо