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

oBrabo

Участник
46
3
Guys, there is an error in the following code:

Код:
local sampev = require 'lib.samp.events'
require 'lib.moonloader'

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

    while true do
        if isKeyJustPressed(VK_L) and sampIsChatInputActive() == false then
            Activate = not Activate printString(Activate and "ON" or "OFF", 1000)
        end
        
        lua_thread.create(function()
            if Activate then
                for k, char in pairs(getAllChars()) do
                    if char ~= PLAYER_PED then
                        taskPlayAnim(char, "FIGHTIDLE", "PED", 4.0, false, false, false, false, -1)
                    end
                end
            elseif not Activate then
                removeAnimation('FIGHTIDLE')
            end
        end)
        return true
    end
    
    while true do
    wait(0)
    end
end

Basically this code applies an animation to all the players around you and removes it whenever you want. It works perfectly when you have 5, 6 players. When you have a crowd it works for a matter of 5 seconds and stops, when that happens, I can't turn it on anymore. Can someone help me?
 

Itachi Uchiha

Участник
124
21
Посмотреть вложение 71668
не работает закрытие диалога. Если вместо 0 1 поставить, то выбирается выбранный пункт диалога. Если оставить 0, то диалог не закрывается

в бесконечный цикл функции main() вставь
попробуй вставить это:
Code:
wait(pping+10)
sampSendDialogResponse(1240, 0, -1, -1)
sampAddChatMessage('hlo', -1)
return false
 

thebestsupreme

Участник
170
12
В чём ошибка


[15:28:15.259993] (error) Helper.lua: C:\SBORKA LETO 2020 BY OSVALDO\moonloader\Helper.lua:28: ')' expected (to close '(' at line 24) near 'end'
[15:28:15.260970] (error) Helper.lua: Script died due to an error. (15366E4C)


Код:
script_name ("Helper") -- название скрипта
script_author ("C.Kot") -- автор скрипта

require "lib.moonloader" -- поиск библиотеки
local imgui = require 'imgui'
local samp = require 'lib.samp.events'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local main_window_state = imgui.ImBool(false)
local tag = "{00fab3}[Helper]:{ffffff} " -- тэг
local main_color = 0x5A90CE
local second_color = 0x518fd1
local main_color_text = "[5A90CE]"
local white_color = "[FFFFFF]"
local nick = "Christopher_Kot"

local themes = import "lib/imgui_themes.lua"

function main()
    while not  isSampAvailable() do wait(100) end
    sampAddChatMessage(tag .. 'Скрипт успешно активирован.Автор {00fab3}Christopher_Kot', -1)
    end
    sampRegisterChatCommand("mz", function()
    sampAddChatMessage(tag .. "*U*", -1)
    main_window_state.v = not main_window_state.v
    end
end

function imgui.OnDrawFrame()
    if main_window_state.v then
        local ex, ey = getScreenResolution()
        imgui.ShowCursor = true
        imgui.SetNextWindowPos(imgui.ImVec2(ex / 6, ey / 6), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowSize(imgui.ImVec2(660, 660), imgui.Cond.FirstUseEver)
        imgui.Begin(u8"Панель", main_window_state,imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
        imgui.End() -- конец окна
    end
end

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()
 

Fott

Простреленный
3,436
2,280
В чём ошибка


[15:28:15.259993] (error) Helper.lua: C:\SBORKA LETO 2020 BY OSVALDO\moonloader\Helper.lua:28: ')' expected (to close '(' at line 24) near 'end'
[15:28:15.260970] (error) Helper.lua: Script died due to an error. (15366E4C)


Код:
script_name ("Helper") -- название скрипта
script_author ("C.Kot") -- автор скрипта

require "lib.moonloader" -- поиск библиотеки
local imgui = require 'imgui'
local samp = require 'lib.samp.events'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local main_window_state = imgui.ImBool(false)
local tag = "{00fab3}[Helper]:{ffffff} " -- тэг
local main_color = 0x5A90CE
local second_color = 0x518fd1
local main_color_text = "[5A90CE]"
local white_color = "[FFFFFF]"
local nick = "Christopher_Kot"

local themes = import "lib/imgui_themes.lua"

function main()
    while not  isSampAvailable() do wait(100) end
    sampAddChatMessage(tag .. 'Скрипт успешно активирован.Автор {00fab3}Christopher_Kot', -1)
    end
    sampRegisterChatCommand("mz", function()
    sampAddChatMessage(tag .. "*U*", -1)
    main_window_state.v = not main_window_state.v
    end
end

function imgui.OnDrawFrame()
    if main_window_state.v then
        local ex, ey = getScreenResolution()
        imgui.ShowCursor = true
        imgui.SetNextWindowPos(imgui.ImVec2(ex / 6, ey / 6), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowSize(imgui.ImVec2(660, 660), imgui.Cond.FirstUseEver)
        imgui.Begin(u8"Панель", main_window_state,imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
        imgui.End() -- конец окна
    end
end

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()
Lua:
script_name ("Helper") -- название скрипта
script_author ("C.Kot") -- автор скрипта

require "lib.moonloader" -- поиск библиотеки
local imgui = require 'imgui'
local samp = require 'lib.samp.events'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local main_window_state = imgui.ImBool(false)
local tag = "{00fab3}[Helper]:{ffffff} " -- тэг
local main_color = 0x5A90CE
local second_color = 0x518fd1
local main_color_text = "[5A90CE]"
local white_color = "[FFFFFF]"
local nick = "Christopher_Kot"

local themes = import "lib/imgui_themes.lua"

function main()
    while not  isSampAvailable() do wait(100) end
    sampAddChatMessage(tag .. 'Скрипт успешно активирован.Автор {00fab3}Christopher_Kot', -1)
    sampRegisterChatCommand("mz", function()
        sampAddChatMessage(tag .. "*U*", -1)
        main_window_state.v = not main_window_state.v
    end)
    while true do
        wait(0)
    end
end

function imgui.OnDrawFrame()
    if main_window_state.v then
        local ex, ey = getScreenResolution()
        imgui.ShowCursor = true
        imgui.SetNextWindowPos(imgui.ImVec2(ex / 6, ey / 6), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowSize(imgui.ImVec2(660, 660), imgui.Cond.FirstUseEver)
        imgui.Begin(u8"Панель", main_window_state,imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
        imgui.End() -- конец окна
    end
end

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()
 

thebestsupreme

Участник
170
12
Lua:
script_name ("Helper") -- название скрипта
script_author ("C.Kot") -- автор скрипта

require "lib.moonloader" -- поиск библиотеки
local imgui = require 'imgui'
local samp = require 'lib.samp.events'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local main_window_state = imgui.ImBool(false)
local tag = "{00fab3}[Helper]:{ffffff} " -- тэг
local main_color = 0x5A90CE
local second_color = 0x518fd1
local main_color_text = "[5A90CE]"
local white_color = "[FFFFFF]"
local nick = "Christopher_Kot"

local themes = import "lib/imgui_themes.lua"

function main()
    while not  isSampAvailable() do wait(100) end
    sampAddChatMessage(tag .. 'Скрипт успешно активирован.Автор {00fab3}Christopher_Kot', -1)
    sampRegisterChatCommand("mz", function()
        sampAddChatMessage(tag .. "*U*", -1)
        main_window_state.v = not main_window_state.v
    end)
    while true do
        wait(0)
    end
end

function imgui.OnDrawFrame()
    if main_window_state.v then
        local ex, ey = getScreenResolution()
        imgui.ShowCursor = true
        imgui.SetNextWindowPos(imgui.ImVec2(ex / 6, ey / 6), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowSize(imgui.ImVec2(660, 660), imgui.Cond.FirstUseEver)
        imgui.Begin(u8"Панель", main_window_state,imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
        imgui.End() -- конец окна
    end
end

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()
Я сделал но окно imgui не появляется при активации команды
ошибок нету
 

Fott

Простреленный
3,436
2,280
Я сделал но окно imgui не появляется при активации команды
ошибок нету
Lua:
script_name ("Helper") -- название скрипта
script_author ("C.Kot") -- автор скрипта

require "lib.moonloader" -- поиск библиотеки
local imgui = require 'imgui'
local samp = require 'lib.samp.events'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local main_window_state = imgui.ImBool(false)
local tag = "{00fab3}[Helper]:{ffffff} " -- тэг
local main_color = 0x5A90CE
local second_color = 0x518fd1
local main_color_text = "[5A90CE]"
local white_color = "[FFFFFF]"
local nick = "Christopher_Kot"

local themes = import "lib/imgui_themes.lua"

function main()
    while not  isSampAvailable() do wait(100) end
    sampAddChatMessage(tag .. 'Скрипт успешно активирован.Автор {00fab3}Christopher_Kot', -1)
    sampRegisterChatCommand("mz", function()
        sampAddChatMessage(tag .. "*U*", -1)
        main_window_state.v = not main_window_state.v
        imgui.Process = main_window_state.v
    end)
    while true do
        wait(0)
    end
end

function imgui.OnDrawFrame()
    if main_window_state.v then
        local ex, ey = getScreenResolution()
        imgui.ShowCursor = true
        imgui.SetNextWindowPos(imgui.ImVec2(ex / 6, ey / 6), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowSize(imgui.ImVec2(660, 660), imgui.Cond.FirstUseEver)
        imgui.Begin(u8"Панель", main_window_state,imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
        imgui.End() -- конец окна
    end
end

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()
 

Itachi Uchiha

Участник
124
21
[ML] (error) Family Helper: cannot resume non-suspended coroutine
[ML] (error) Family Helper: cannot resume non-suspended coroutine
[ML] (error) Family Helper: Script died due to error. (2370CC14)
[ML] (error) Family Helper: Script died due to error. (2370CC14)
При выполнении следующих строк:

Lua:
if imgui.Checkbox(u8'##8', OFF) then
            if al.v then
                sampSendChat(u8:decode('/al '..text_piara.v))
            end
            wait(delay.v)
            if fam.v then
                sampSendChat(u8:decode('/fam '..text_piara.v))
            end
        end
 

Fott

Простреленный
3,436
2,280
[ML] (error) Family Helper: cannot resume non-suspended coroutine
[ML] (error) Family Helper: cannot resume non-suspended coroutine
[ML] (error) Family Helper: Script died due to error. (2370CC14)
[ML] (error) Family Helper: Script died due to error. (2370CC14)
При выполнении следующих строк:

Lua:
if imgui.Checkbox(u8'##8', OFF) then
            if al.v then
                sampSendChat(u8:decode('/al '..text_piara.v))
            end
            wait(delay.v)
            if fam.v then
                sampSendChat(u8:decode('/fam '..text_piara.v))
            end
        end
А че это вообще за код такой?
 

oBrabo

Участник
46
3
Guys, there is an error in the following code:

Код:
local sampev = require 'lib.samp.events'
require 'lib.moonloader'

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

    while true do
        if isKeyJustPressed(VK_L) and sampIsChatInputActive() == false then
            Activate = not Activate printString(Activate and "ON" or "OFF", 1000)
        end
       
        lua_thread.create(function()
            if Activate then
                for k, char in pairs(getAllChars()) do
                    if char ~= PLAYER_PED then
                        taskPlayAnim(char, "FIGHTIDLE", "PED", 4.0, false, false, false, false, -1)
                    end
                end
            elseif not Activate then
                removeAnimation('FIGHTIDLE')
            end
        end)
        return true
    end
   
    while true do
    wait(0)
    end
end

Basically this code applies an animation to all the players around you and removes it whenever you want. It works perfectly when you have 5, 6 players. When you have a crowd it works for a matter of 5 seconds and stops, when that happens, I can't turn it on anymore. Can someone help me?

Can someone help me?
 

Itachi Uchiha

Участник
124
21
Зачем ты слепил все в чекбокс?
при нажатии изменении чекбокса должны проигрыватся следущие строчки, разве не? Мне просто выше подсказали как сделать так
[ML] (error) Family Helper: cannot resume non-suspended coroutine
[ML] (error) Family Helper: cannot resume non-suspended coroutine
[ML] (error) Family Helper: Script died due to error. (2370CC14)
[ML] (error) Family Helper: Script died due to error. (2370CC14)
При выполнении следующих строк:

Lua:
if imgui.Checkbox(u8'##8', OFF) then
            if al.v then
                sampSendChat(u8:decode('/al '..text_piara.v))
            end
            wait(delay.v)
            if fam.v then
                sampSendChat(u8:decode('/fam '..text_piara.v))
            end
        end
актуально
 
Последнее редактирование:

thebestsupreme

Участник
170
12

актуально
 
  • Нравится
Реакции: Wycmpblu

Slava Stetem

Участник
106
5
Всем привет хочу узнать как зделать чтобы в ImGUI кнопки закрывались. Например : я решил открыть кнопку "Основное" и там открываеться ещё больше кнопок. Теперь решил открыть кнопку "настройки" и сразу все кнопки которые были открыты с кнопки "Основное" закрылись