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

Carl_Henderson

Участник
34
8
lua:
require('lib.moonloader')
local imgui = require 'mimgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
local u8 = encoding.UTF8
local new = imgui.new

local WinState = new.bool()


imgui.OnFrame(function() return WinState[0] end, function(player)
    imgui.SetNextWindowPos(imgui.ImVec2(500,500), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(850, 400), imgui.Cond.Always)
    imgui.Begin('Helper in Taxi for MyHome RP', WinState, imgui.WindowFlags.NoResize)

    imgui.SetCursorPos(imgui.ImVec2(50, 20)) -- 50 = по горизонтали, 170 по вертикали
    if imgui.Button(u8'501', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 501")
    end

    imgui.SetCursorPos(imgui.ImVec2(200, 20))
    if imgui.Button(u8'502', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 502")
    end

    imgui.SetCursorPos(imgui.ImVec2(350, 20))
    if imgui.Button(u8'503', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 503")
    end

    imgui.SetCursorPos(imgui.ImVec2(500, 20))
    if imgui.Button(u8'504', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 504")
    end

    imgui.SetCursorPos(imgui.ImVec2(650, 20))
    if imgui.Button(u8'505', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 505")
    end

    imgui.SetCursorPos(imgui.ImVec2(50, 60))
    if imgui.Button(u8'506', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 506")
    end

    imgui.SetCursorPos(imgui.ImVec2(200, 60))
    if imgui.Button(u8'507', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 507")
    end

    imgui.SetCursorPos(imgui.ImVec2(350, 60))
    if imgui.Button(u8'508', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 508")
    end

    imgui.SetCursorPos(imgui.ImVec2(500, 60))
    if imgui.Button(u8'509', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 509")
    end

    imgui.SetCursorPos(imgui.ImVec2(650, 60))
    if imgui.Button(u8'510', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 510")
    end

    imgui.SetCursorPos(imgui.ImVec2(350, 100))
    if imgui.Button(u8'Доклад', imgui.ImVec2(150, 35)) then
        sampSendChat("/f  диспетчеру. Принимаю вызов с улицы WillowField")
    end

function apply_custom_style()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4
    style.WindowRounding = 2
    style.WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
    style.ChildWindowRounding = 2.0
    style.FrameRounding = 3
    style.ItemSpacing = imgui.ImVec2(5.0, 4.0)
    style.ScrollbarSize = 13.0
    style.ScrollbarRounding = 0
    style.GrabMinSize = 8.0
    style.GrabRounding = 1.0
    style.WindowPadding = imgui.ImVec2(4.0, 4.0)
    style.FramePadding = imgui.ImVec2(3.5, 3.5)
    style.ButtonTextAlign = imgui.ImVec2(0.0, 0.5)
    colors[clr.WindowBg]              = ImVec4(0.14, 0.12, 0.16, 1.00);
    colors[clr.ChildWindowBg]         = ImVec4(0.30, 0.20, 0.39, 0.00);
    colors[clr.PopupBg]               = ImVec4(0.05, 0.05, 0.10, 0.90);
    colors[clr.Border]                = ImVec4(0.89, 0.85, 0.92, 0.30);
    colors[clr.BorderShadow]          = ImVec4(0.00, 0.00, 0.00, 0.00);
    colors[clr.FrameBg]               = ImVec4(0.30, 0.20, 0.39, 1.00);
    colors[clr.FrameBgHovered]        = ImVec4(0.41, 0.19, 0.63, 0.68);
    colors[clr.FrameBgActive]         = ImVec4(0.41, 0.19, 0.63, 1.00);
    colors[clr.TitleBg]               = ImVec4(0.41, 0.19, 0.63, 0.45);
    colors[clr.TitleBgCollapsed]      = ImVec4(0.41, 0.19, 0.63, 0.35);
    colors[clr.TitleBgActive]         = ImVec4(0.41, 0.19, 0.63, 0.78);
    colors[clr.MenuBarBg]             = ImVec4(0.30, 0.20, 0.39, 0.57);
    colors[clr.ScrollbarBg]           = ImVec4(0.30, 0.20, 0.39, 1.00);
    colors[clr.ScrollbarGrab]         = ImVec4(0.41, 0.19, 0.63, 0.31);
    colors[clr.ScrollbarGrabHovered]  = ImVec4(0.41, 0.19, 0.63, 0.78);
    colors[clr.ScrollbarGrabActive]   = ImVec4(0.41, 0.19, 0.63, 1.00);
    colors[clr.ComboBg]               = ImVec4(0.30, 0.20, 0.39, 1.00);
    colors[clr.CheckMark]             = ImVec4(0.56, 0.61, 1.00, 1.00);
    colors[clr.SliderGrab]            = ImVec4(0.41, 0.19, 0.63, 0.24);
    colors[clr.SliderGrabActive]      = ImVec4(0.41, 0.19, 0.63, 1.00);
    colors[clr.Button]                = ImVec4(0.41, 0.19, 0.63, 0.44);
    colors[clr.ButtonHovered]         = ImVec4(0.41, 0.19, 0.63, 0.86);
    colors[clr.ButtonActive]          = ImVec4(0.64, 0.33, 0.94, 1.00);
    colors[clr.Header]                = ImVec4(0.41, 0.19, 0.63, 0.76);
    colors[clr.HeaderHovered]         = ImVec4(0.41, 0.19, 0.63, 0.86);
    colors[clr.HeaderActive]          = ImVec4(0.41, 0.19, 0.63, 1.00);
    colors[clr.ResizeGrip]            = ImVec4(0.41, 0.19, 0.63, 0.20);
    colors[clr.ResizeGripHovered]     = ImVec4(0.41, 0.19, 0.63, 0.78);
    colors[clr.ResizeGripActive]      = ImVec4(0.41, 0.19, 0.63, 1.00);
    colors[clr.CloseButton]           = ImVec4(1.00, 1.00, 1.00, 0.75);
    colors[clr.CloseButtonHovered]    = ImVec4(0.88, 0.74, 1.00, 0.59);
    colors[clr.CloseButtonActive]     = ImVec4(0.88, 0.85, 0.92, 1.00);
    colors[clr.PlotLines]             = ImVec4(0.89, 0.85, 0.92, 0.63);
    colors[clr.PlotLinesHovered]      = ImVec4(0.41, 0.19, 0.63, 1.00);
    colors[clr.PlotHistogram]         = ImVec4(0.89, 0.85, 0.92, 0.63);
    colors[clr.PlotHistogramHovered]  = ImVec4(0.41, 0.19, 0.63, 1.00);
    colors[clr.TextSelectedBg]        = ImVec4(0.41, 0.19, 0.63, 0.43);
    colors[clr.ModalWindowDarkening]  = ImVec4(0.20, 0.20, 0.20, 0.35);
end
apply_custom_style()

    imgui.End()
end)

function main()

    imgui.OnInitialize(function()
    theme()
end)

local _, id = sampGetPlayerIdByCharHandle(PLAYER_PED)

    while not isSampAvailable() do wait(0) end

    while true do
        wait(0)
        if wasKeyPressed(VK_R) and not sampIsCursorActive() then -- Если нажата клавиша R и не активен самп курсор (во избежании активации при открытом чате/диалоге)
            WinState[0] = not WinState[0]
        end
    end
end

не работает, можете исправить?
 

MLycoris

Режим чтения
Проверенный
1,825
1,882
lua:
require('lib.moonloader')
local imgui = require 'mimgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
local u8 = encoding.UTF8
local new = imgui.new

local WinState = new.bool()


imgui.OnFrame(function() return WinState[0] end, function(player)
    imgui.SetNextWindowPos(imgui.ImVec2(500,500), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(850, 400), imgui.Cond.Always)
    imgui.Begin('Helper in Taxi for MyHome RP', WinState, imgui.WindowFlags.NoResize)

    imgui.SetCursorPos(imgui.ImVec2(50, 20)) -- 50 = по горизонтали, 170 по вертикали
    if imgui.Button(u8'501', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 501")
    end

    imgui.SetCursorPos(imgui.ImVec2(200, 20))
    if imgui.Button(u8'502', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 502")
    end

    imgui.SetCursorPos(imgui.ImVec2(350, 20))
    if imgui.Button(u8'503', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 503")
    end

    imgui.SetCursorPos(imgui.ImVec2(500, 20))
    if imgui.Button(u8'504', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 504")
    end

    imgui.SetCursorPos(imgui.ImVec2(650, 20))
    if imgui.Button(u8'505', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 505")
    end

    imgui.SetCursorPos(imgui.ImVec2(50, 60))
    if imgui.Button(u8'506', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 506")
    end

    imgui.SetCursorPos(imgui.ImVec2(200, 60))
    if imgui.Button(u8'507', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 507")
    end

    imgui.SetCursorPos(imgui.ImVec2(350, 60))
    if imgui.Button(u8'508', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 508")
    end

    imgui.SetCursorPos(imgui.ImVec2(500, 60))
    if imgui.Button(u8'509', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 509")
    end

    imgui.SetCursorPos(imgui.ImVec2(650, 60))
    if imgui.Button(u8'510', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 510")
    end

    imgui.SetCursorPos(imgui.ImVec2(350, 100))
    if imgui.Button(u8'Доклад', imgui.ImVec2(150, 35)) then
        sampSendChat("/f  диспетчеру. Принимаю вызов с улицы WillowField")
    end

function apply_custom_style()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4
    style.WindowRounding = 2
    style.WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
    style.ChildWindowRounding = 2.0
    style.FrameRounding = 3
    style.ItemSpacing = imgui.ImVec2(5.0, 4.0)
    style.ScrollbarSize = 13.0
    style.ScrollbarRounding = 0
    style.GrabMinSize = 8.0
    style.GrabRounding = 1.0
    style.WindowPadding = imgui.ImVec2(4.0, 4.0)
    style.FramePadding = imgui.ImVec2(3.5, 3.5)
    style.ButtonTextAlign = imgui.ImVec2(0.0, 0.5)
    colors[clr.WindowBg]              = ImVec4(0.14, 0.12, 0.16, 1.00);
    colors[clr.ChildWindowBg]         = ImVec4(0.30, 0.20, 0.39, 0.00);
    colors[clr.PopupBg]               = ImVec4(0.05, 0.05, 0.10, 0.90);
    colors[clr.Border]                = ImVec4(0.89, 0.85, 0.92, 0.30);
    colors[clr.BorderShadow]          = ImVec4(0.00, 0.00, 0.00, 0.00);
    colors[clr.FrameBg]               = ImVec4(0.30, 0.20, 0.39, 1.00);
    colors[clr.FrameBgHovered]        = ImVec4(0.41, 0.19, 0.63, 0.68);
    colors[clr.FrameBgActive]         = ImVec4(0.41, 0.19, 0.63, 1.00);
    colors[clr.TitleBg]               = ImVec4(0.41, 0.19, 0.63, 0.45);
    colors[clr.TitleBgCollapsed]      = ImVec4(0.41, 0.19, 0.63, 0.35);
    colors[clr.TitleBgActive]         = ImVec4(0.41, 0.19, 0.63, 0.78);
    colors[clr.MenuBarBg]             = ImVec4(0.30, 0.20, 0.39, 0.57);
    colors[clr.ScrollbarBg]           = ImVec4(0.30, 0.20, 0.39, 1.00);
    colors[clr.ScrollbarGrab]         = ImVec4(0.41, 0.19, 0.63, 0.31);
    colors[clr.ScrollbarGrabHovered]  = ImVec4(0.41, 0.19, 0.63, 0.78);
    colors[clr.ScrollbarGrabActive]   = ImVec4(0.41, 0.19, 0.63, 1.00);
    colors[clr.ComboBg]               = ImVec4(0.30, 0.20, 0.39, 1.00);
    colors[clr.CheckMark]             = ImVec4(0.56, 0.61, 1.00, 1.00);
    colors[clr.SliderGrab]            = ImVec4(0.41, 0.19, 0.63, 0.24);
    colors[clr.SliderGrabActive]      = ImVec4(0.41, 0.19, 0.63, 1.00);
    colors[clr.Button]                = ImVec4(0.41, 0.19, 0.63, 0.44);
    colors[clr.ButtonHovered]         = ImVec4(0.41, 0.19, 0.63, 0.86);
    colors[clr.ButtonActive]          = ImVec4(0.64, 0.33, 0.94, 1.00);
    colors[clr.Header]                = ImVec4(0.41, 0.19, 0.63, 0.76);
    colors[clr.HeaderHovered]         = ImVec4(0.41, 0.19, 0.63, 0.86);
    colors[clr.HeaderActive]          = ImVec4(0.41, 0.19, 0.63, 1.00);
    colors[clr.ResizeGrip]            = ImVec4(0.41, 0.19, 0.63, 0.20);
    colors[clr.ResizeGripHovered]     = ImVec4(0.41, 0.19, 0.63, 0.78);
    colors[clr.ResizeGripActive]      = ImVec4(0.41, 0.19, 0.63, 1.00);
    colors[clr.CloseButton]           = ImVec4(1.00, 1.00, 1.00, 0.75);
    colors[clr.CloseButtonHovered]    = ImVec4(0.88, 0.74, 1.00, 0.59);
    colors[clr.CloseButtonActive]     = ImVec4(0.88, 0.85, 0.92, 1.00);
    colors[clr.PlotLines]             = ImVec4(0.89, 0.85, 0.92, 0.63);
    colors[clr.PlotLinesHovered]      = ImVec4(0.41, 0.19, 0.63, 1.00);
    colors[clr.PlotHistogram]         = ImVec4(0.89, 0.85, 0.92, 0.63);
    colors[clr.PlotHistogramHovered]  = ImVec4(0.41, 0.19, 0.63, 1.00);
    colors[clr.TextSelectedBg]        = ImVec4(0.41, 0.19, 0.63, 0.43);
    colors[clr.ModalWindowDarkening]  = ImVec4(0.20, 0.20, 0.20, 0.35);
end
apply_custom_style()

    imgui.End()
end)

function main()

    imgui.OnInitialize(function()
    theme()
end)

local _, id = sampGetPlayerIdByCharHandle(PLAYER_PED)

    while not isSampAvailable() do wait(0) end

    while true do
        wait(0)
        if wasKeyPressed(VK_R) and not sampIsCursorActive() then -- Если нажата клавиша R и не активен самп курсор (во избежании активации при открытом чате/диалоге)
            WinState[0] = not WinState[0]
        end
    end
end

не работает, можете исправить?
получаешь ид до загрузки сампа от чего крашит скрипт, не в том месте указываешь параметры темы, а потом и применяешь через жопу, ну и самое сладкое это сама кривая тема в которой были параметры, которые обычно крашат скрипт
Lua:
require('lib.moonloader')
local imgui = require 'mimgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
local u8 = encoding.UTF8
local new = imgui.new

local WinState = new.bool(1)


imgui.OnFrame(function() return WinState[0] end, function(player)
    imgui.SetNextWindowPos(imgui.ImVec2(500,500), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(850, 400), imgui.Cond.Always)
    imgui.Begin('Helper in Taxi for MyHome RP', WinState, imgui.WindowFlags.NoResize)

    imgui.SetCursorPos(imgui.ImVec2(50, 20)) -- 50 = по горизонтали, 170 по вертикали
    if imgui.Button(u8'501', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 501")
    end

    imgui.SetCursorPos(imgui.ImVec2(200, 20))
    if imgui.Button(u8'502', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 502")
    end

    imgui.SetCursorPos(imgui.ImVec2(350, 20))
    if imgui.Button(u8'503', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 503")
    end

    imgui.SetCursorPos(imgui.ImVec2(500, 20))
    if imgui.Button(u8'504', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 504")
    end

    imgui.SetCursorPos(imgui.ImVec2(650, 20))
    if imgui.Button(u8'505', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 505")
    end

    imgui.SetCursorPos(imgui.ImVec2(50, 60))
    if imgui.Button(u8'506', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 506")
    end

    imgui.SetCursorPos(imgui.ImVec2(200, 60))
    if imgui.Button(u8'507', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 507")
    end

    imgui.SetCursorPos(imgui.ImVec2(350, 60))
    if imgui.Button(u8'508', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 508")
    end

    imgui.SetCursorPos(imgui.ImVec2(500, 60))
    if imgui.Button(u8'509', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 509")
    end

    imgui.SetCursorPos(imgui.ImVec2(650, 60))
    if imgui.Button(u8'510', imgui.ImVec2(150, 35)) then
        sampSendChat("/takecall 510")
    end

    imgui.SetCursorPos(imgui.ImVec2(350, 100))
    if imgui.Button(u8'Доклад', imgui.ImVec2(150, 35)) then
        sampSendChat("/f  диспетчеру. Принимаю вызов с улицы WillowField")
    end
    imgui.End()
end)

function apply_custom_style()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4
    style.WindowRounding = 2
    style.WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
    style.FrameRounding = 3
    style.ItemSpacing = imgui.ImVec2(5.0, 4.0)
    style.ScrollbarSize = 13.0
    style.ScrollbarRounding = 0
    style.GrabMinSize = 8.0
    style.GrabRounding = 1.0
    style.WindowPadding = imgui.ImVec2(4.0, 4.0)
    style.FramePadding = imgui.ImVec2(3.5, 3.5)
    style.ButtonTextAlign = imgui.ImVec2(0.0, 0.5)
    colors[clr.WindowBg]              = ImVec4(0.14, 0.12, 0.16, 1.00);
    colors[clr.PopupBg]               = ImVec4(0.05, 0.05, 0.10, 0.90);
    colors[clr.Border]                = ImVec4(0.89, 0.85, 0.92, 0.30);
    colors[clr.BorderShadow]          = ImVec4(0.00, 0.00, 0.00, 0.00);
    colors[clr.FrameBg]               = ImVec4(0.30, 0.20, 0.39, 1.00);
    colors[clr.FrameBgHovered]        = ImVec4(0.41, 0.19, 0.63, 0.68);
    colors[clr.FrameBgActive]         = ImVec4(0.41, 0.19, 0.63, 1.00);
    colors[clr.TitleBg]               = ImVec4(0.41, 0.19, 0.63, 0.45);
    colors[clr.TitleBgCollapsed]      = ImVec4(0.41, 0.19, 0.63, 0.35);
    colors[clr.TitleBgActive]         = ImVec4(0.41, 0.19, 0.63, 0.78);
    colors[clr.MenuBarBg]             = ImVec4(0.30, 0.20, 0.39, 0.57);
    colors[clr.ScrollbarBg]           = ImVec4(0.30, 0.20, 0.39, 1.00);
    colors[clr.ScrollbarGrab]         = ImVec4(0.41, 0.19, 0.63, 0.31);
    colors[clr.ScrollbarGrabHovered]  = ImVec4(0.41, 0.19, 0.63, 0.78);
    colors[clr.ScrollbarGrabActive]   = ImVec4(0.41, 0.19, 0.63, 1.00);
    colors[clr.CheckMark]             = ImVec4(0.56, 0.61, 1.00, 1.00);
    colors[clr.SliderGrab]            = ImVec4(0.41, 0.19, 0.63, 0.24);
    colors[clr.SliderGrabActive]      = ImVec4(0.41, 0.19, 0.63, 1.00);
    colors[clr.Button]                = ImVec4(0.41, 0.19, 0.63, 0.44);
    colors[clr.ButtonHovered]         = ImVec4(0.41, 0.19, 0.63, 0.86);
    colors[clr.ButtonActive]          = ImVec4(0.64, 0.33, 0.94, 1.00);
    colors[clr.Header]                = ImVec4(0.41, 0.19, 0.63, 0.76);
    colors[clr.HeaderHovered]         = ImVec4(0.41, 0.19, 0.63, 0.86);
    colors[clr.HeaderActive]          = ImVec4(0.41, 0.19, 0.63, 1.00);
    colors[clr.ResizeGrip]            = ImVec4(0.41, 0.19, 0.63, 0.20);
    colors[clr.ResizeGripHovered]     = ImVec4(0.41, 0.19, 0.63, 0.78);
    colors[clr.ResizeGripActive]      = ImVec4(0.41, 0.19, 0.63, 1.00);
    colors[clr.PlotLines]             = ImVec4(0.89, 0.85, 0.92, 0.63);
    colors[clr.PlotLinesHovered]      = ImVec4(0.41, 0.19, 0.63, 1.00);
    colors[clr.PlotHistogram]         = ImVec4(0.89, 0.85, 0.92, 0.63);
    colors[clr.PlotHistogramHovered]  = ImVec4(0.41, 0.19, 0.63, 1.00);
    colors[clr.TextSelectedBg]        = ImVec4(0.41, 0.19, 0.63, 0.43);
end

imgui.OnInitialize(function()
    apply_custom_style()
end)

function main()
    while not isSampAvailable() do wait(0) end
    while true do
        wait(0)
        if wasKeyPressed(VK_R) and not sampIsCursorActive() then -- Если нажата клавиша R и не активен самп курсор (во избежании активации при открытом чате/диалоге)
            WinState[0] = not WinState[0]
        end
    end
end
 

хуега)

РП игрок
Модератор
2,568
2,269
Вместо new.bool() на 8-ой строке нужно new.bool(false)
оно по стандарту инициализируется как false
1714919834029.png
 
  • Нравится
Реакции: MLycoris

Majak1234

Новичок
16
0
Как реализовать функцию, которая бы при вводе команды /cub *название* брала бы данные из таблицы в зависимости от используемого названия
К примеру ввел, /cub E2 и условно ставился бы маркер именно на координаты привязанные к E2?
1714920007356.png
 

MLycoris

Режим чтения
Проверенный
1,825
1,882
Как реализовать функцию, которая бы при вводе команды /cub *название* брала бы данные из таблицы в зависимости от используемого названия
К примеру ввел, /cub E2 и условно ставился бы маркер именно на координаты привязанные к E2?
Посмотреть вложение 239257
попробуй
Lua:
sampRegisterChatCommand('cub', function(arg)
    local result = squares[arg]
    if result then
        sampAddChatMessage(string.format('Coords: %s // %s',result[1],result[2]),-1)
    end
end)
 
  • Влюблен
Реакции: Majak1234

kenny.stress

Новичок
8
0
Что если пишу команду показывается менюшка, курсор виндовс, а окно не кликабельное
 

A.Hellsing

Новичок
1
0
quit:
local act = false

function main()   
    sampAddChatMessage('asd', -1)
    sampRegisterChatCommand("asd", checkScoreAndQuit)
end

function checkScoreAndQuit()
if act then
    local score = sampGetPlayerScore(sampGetPlayerIdByCharHandle(PLAYER_PED))
    if score == 1 then
    sampProcessChatInput("/quit")
end
end
end
почему не работает код? Мне нужно чтобы на 1 уровне игрок выходил из игры
 

MiskerKifira

Участник
73
23
quit:
local act = false

function main() 
    sampAddChatMessage('asd', -1)
    sampRegisterChatCommand("asd", checkScoreAndQuit)
end

function checkScoreAndQuit()
if act then
    local score = sampGetPlayerScore(sampGetPlayerIdByCharHandle(PLAYER_PED))
    if score == 1 then
    sampProcessChatInput("/quit")
end
end
end
почему не работает код? Мне нужно чтобы на 1 уровне игрок выходил из игры
Зачем тебе переменная act если она даже не меняется? (ниже должен быть рабочий код)
Lua:
function main()   
    sampAddChatMessage('asd', -1)
    sampRegisterChatCommand("asd", checkScoreAndQuit)
end

function checkScoreAndQuit()
    local score = sampGetPlayerScore(sampGetPlayerIdByCharHandle(PLAYER_PED))
    if score == 1 then
        sampProcessChatInput("/quit")
    end
end
 
  • Bug
Реакции: minxty

minxty

Известный
929
800
quit:
local act = false

function main()  
    sampAddChatMessage('asd', -1)
    sampRegisterChatCommand("asd", checkScoreAndQuit)
end

function checkScoreAndQuit()
if act then
    local score = sampGetPlayerScore(sampGetPlayerIdByCharHandle(PLAYER_PED))
    if score == 1 then
    sampProcessChatInput("/quit")
end
end
end
почему не работает код? Мне нужно чтобы на 1 уровне игрок выходил из игры
1. нету проверки на инициализирование сампа, изза этого скрипт может крашиться
2. нету бесконечного цикла, изза него скрипт моментально завершается
Lua:
local act = false

function main()
    repeat wait(0) until isSampAvailable()
    sampAddChatMessage('asd', -1)
    sampRegisterChatCommand("asd", checkScoreAndQuit)
    wait(-1)
end

function checkScoreAndQuit()
    if act then
        local score = sampGetPlayerScore(sampGetPlayerIdByCharHandle(PLAYER_PED))
        if score == 1 then
            sampProcessChatInput("/quit")
        end
    end
end
 
  • Нравится
Реакции: MiskerKifira

хуега)

РП игрок
Модератор
2,568
2,269
quit:
local act = false

function main()  
    sampAddChatMessage('asd', -1)
    sampRegisterChatCommand("asd", checkScoreAndQuit)
end

function checkScoreAndQuit()
if act then
    local score = sampGetPlayerScore(sampGetPlayerIdByCharHandle(PLAYER_PED))
    if score == 1 then
    sampProcessChatInput("/quit")
end
end
end
почему не работает код? Мне нужно чтобы на 1 уровне игрок выходил из игры
Зачем тебе переменная act если она даже не меняется? (ниже должен быть рабочий код)
Lua:
function main()  
    sampAddChatMessage('asd', -1)
    sampRegisterChatCommand("asd", checkScoreAndQuit)
end

function checkScoreAndQuit()
    local score = sampGetPlayerScore(sampGetPlayerIdByCharHandle(PLAYER_PED))
    if score == 1 then
        sampProcessChatInput("/quit")
    end
end
1. нету проверки на инициализирование сампа, изза этого скрипт может крашиться
2. нету бесконечного цикла, изза него скрипт моментально завершается
Lua:
local act = false

function main()
    repeat wait(0) until isSampAvailable()
    sampAddChatMessage('asd', -1)
    sampRegisterChatCommand("asd", checkScoreAndQuit)
    wait(-1)
end

function checkScoreAndQuit()
    if act then
        local score = sampGetPlayerScore(sampGetPlayerIdByCharHandle(PLAYER_PED))
        if score == 1 then
            sampProcessChatInput("/quit")
        end
    end
end
Вы все забыли, что sampGetPlayerIdByCharHandle возвращает 2 значения
Lua:
local score = sampGetPlayerScore(select(2, sampGetPlayerIdByCharHandle(PLAYER_PED)))
 
  • Нравится
Реакции: Winstаl и minxty

MSIshka

Новичок
2
0
Как реализовать телепорт по чекпоинту(функция телепорта по чекпоинту есть). чтобы когда на экране не было текстдравов происходил телепорт с задержкой?
Lua:
[/B]
function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    sampRegisterChatCommand("click", cmd_bot)
    sampRegisterChatCommand("velocity", cmd_velocity)
    sampRegisterChatCommand('extpc', cmd_extpc)
        while true do
        wait(0)
        if isPlayerPlaying(playerHandle) and enabled then
---------------------------------------------------------------------------
if sampTextdrawIsExists(2245)then
    wait(velocity)
sampSendClickTextdraw(2245)
end
if sampTextdrawIsExists(2246)then
    wait(velocity)
sampSendClickTextdraw(2246)
end
if sampTextdrawIsExists(2247)then
    wait(velocity)
sampSendClickTextdraw(2247)
end
if sampTextdrawIsExists(2248)then
    wait(velocity)
sampSendClickTextdraw(2248)
end
if sampTextdrawIsExists(2249)then
    wait(velocity)
sampSendClickTextdraw(2249)
end
if sampTextdrawIsExists(2250)then
    wait(velocity)
sampSendClickTextdraw(2250)
end
if sampTextdrawIsExists(2251)then
    wait(velocity)
sampSendClickTextdraw(2251)
end
if sampTextdrawIsExists(2252)then
    wait(velocity)
sampSendClickTextdraw(2252)
end
if sampTextdrawIsExists(2253)then
    wait(velocity)
sampSendClickTextdraw(2253)
end
if sampTextdrawIsExists(2254)then
    wait(velocity)
sampSendClickTextdraw(2254)
end
if sampTextdrawIsExists(2255)then
    wait(velocity)
sampSendClickTextdraw(2255)
end
if sampTextdrawIsExists(2256)then
    wait(velocity)
sampSendClickTextdraw(2256)
end
if sampTextdrawIsExists(2257)then
    wait(velocity)
sampSendClickTextdraw(2257)
end
if sampTextdrawIsExists(2258)then
    wait(velocity)
sampSendClickTextdraw(2258)
end
if sampTextdrawIsExists(2259)then
    wait(velocity)
sampSendClickTextdraw(2259)
end
if sampTextdrawIsExists(2260)then
    wait(velocity)
sampSendClickTextdraw(2260)
end
if sampTextdrawIsExists(2261)then
    wait(velocity)
sampSendClickTextdraw(2261)
end
if sampTextdrawIsExists(2262)then
    wait(velocity)
sampSendClickTextdraw(2262)
end
if sampTextdrawIsExists(2263)then
    wait(velocity)
sampSendClickTextdraw(2263)
end
if sampTextdrawIsExists(2264)then
    wait(velocity)
sampSendClickTextdraw(2264)
end
if sampTextdrawIsExists(2265)then
    wait(velocity)
sampSendClickTextdraw(2265)
end
if sampTextdrawIsExists(2266)then
    wait(velocity)
sampSendClickTextdraw(2266)
end
if sampTextdrawIsExists(2267)then
    wait(velocity)
sampSendClickTextdraw(2267)
end
if sampTextdrawIsExists(2268)then
    wait(velocity)
sampSendClickTextdraw(2268)
end
if sampTextdrawIsExists(2269)then
    wait(velocity)
sampSendClickTextdraw(2269)
end
if sampTextdrawIsExists(2270)then
    wait(velocity)
sampSendClickTextdraw(2270)
end
if sampTextdrawIsExists(2271)then
    wait(velocity)
sampSendClickTextdraw(2271)
end
if sampTextdrawIsExists(2272)then
    wait(velocity)
sampSendClickTextdraw(2272)
end
if sampTextdrawIsExists(2273)then
    wait(velocity)
sampSendClickTextdraw(2273)
end
if sampTextdrawIsExists(2274)then
    wait(velocity)
sampSendClickTextdraw(2274)
end
if sampTextdrawIsExists(2275)then
    wait(velocity)
sampSendClickTextdraw(2275)
end
if sampTextdrawIsExists(2276)then
    wait(velocity)
sampSendClickTextdraw(2276)
end
if sampTextdrawIsExists(2277)then
    wait(velocity)
sampSendClickTextdraw(2277)
end
if sampTextdrawIsExists(2278)then
    wait(velocity)
sampSendClickTextdraw(2278)
end
if sampTextdrawIsExists(2279)then
    wait(velocity)
sampSendClickTextdraw(2279)
end
if sampTextdrawIsExists(2280)then
    wait(velocity)
sampSendClickTextdraw(2280)
end
if sampTextdrawIsExists(2281)then
    wait(velocity)
sampSendClickTextdraw(2281)
end
if sampTextdrawIsExists(2282)then
    wait(velocity)
sampSendClickTextdraw(2282)
end
if sampTextdrawIsExists(2283)then
    wait(velocity)
sampSendClickTextdraw(2283)
end
if sampTextdrawIsExists(2284)then
    wait(velocity)
sampSendClickTextdraw(2284)
end
if sampTextdrawIsExists(2285)then
    wait(velocity)
sampSendClickTextdraw(2285)
end
if sampTextdrawIsExists(2286)then
    wait(velocity)
sampSendClickTextdraw(2286)
end
if sampTextdrawIsExists(2287)then
    wait(velocity)
sampSendClickTextdraw(2287)
end
if sampTextdrawIsExists(2288)then
    wait(velocity)
sampSendClickTextdraw(2288)
end
if sampTextdrawIsExists(2289)then
    wait(velocity)
sampSendClickTextdraw(2289)
end
if sampTextdrawIsExists(2290)then
    wait(velocity)
sampSendClickTextdraw(2290)
end
if sampTextdrawIsExists(2291)then
    wait(velocity)
sampSendClickTextdraw(2291)
end
if sampTextdrawIsExists(2292)then
    wait(velocity)
sampSendClickTextdraw(2292)
end
if sampTextdrawIsExists(2293)then
    wait(velocity)
sampSendClickTextdraw(2293)
end
if sampTextdrawIsExists(2294)then
    wait(velocity)
sampSendClickTextdraw(2294)
end
if sampTextdrawIsExists(2295)then
    wait(velocity)
sampSendClickTextdraw(2295)
end
if sampTextdrawIsExists(2296)then
    wait(velocity)
sampSendClickTextdraw(2296)
end
if sampTextdrawIsExists(2297)then
    wait(velocity)
sampSendClickTextdraw(2297)
end
if sampTextdrawIsExists(2298)then
    wait(velocity)
sampSendClickTextdraw(2298)
end
if sampTextdrawIsExists(2299)then
    wait(velocity)
sampSendClickTextdraw(2299)
end
if sampTextdrawIsExists(2300)then
    wait(velocity)
    sampSendClickTextdraw(2300)
end

---------------------------------------------------------------------------
enabled = true
        end
    end
end 
[B]
 
Последнее редактирование:
  • Эм
Реакции: mooh

Carl_Henderson

Участник
34
8
[20:39:06.151397] (error) ANSAI - OpenAI Auto Answer (v2): ...P\moonloader\ANSAI v2 - Open AI Auto Answer by chapo.lua:8: module 'fAwesome6' not found:
no field package.preload['fAwesome6']
no file 'C:\Program Files (x86)\MyHome Launcher\bin\SAMP\moonloader\lib\fAwesome6.lua'
no file 'C:\Program Files (x86)\MyHome Launcher\bin\SAMP\moonloader\lib\fAwesome6\init.lua'
no file 'C:\Program Files (x86)\MyHome Launcher\bin\SAMP\moonloader\fAwesome6.lua'
no file 'C:\Program Files (x86)\MyHome Launcher\bin\SAMP\moonloader\fAwesome6\init.lua'
no file '.\fAwesome6.lua'
no file 'C:\Program Files (x86)\MyHome Launcher\bin\SAMP\moonloader\lib\fAwesome6.luac'
no file 'C:\Program Files (x86)\MyHome Launcher\bin\SAMP\moonloader\lib\fAwesome6\init.luac'
no file 'C:\Program Files (x86)\MyHome Launcher\bin\SAMP\moonloader\fAwesome6.luac'
no file 'C:\Program Files (x86)\MyHome Launcher\bin\SAMP\moonloader\fAwesome6\init.luac'
no file '.\fAwesome6.luac'
no file 'C:\Program Files (x86)\MyHome Launcher\bin\SAMP\moonloader\lib\fAwesome6.dll'
stack traceback:
[C]: in function 'require'
...P\moonloader\ANSAI v2 - Open AI Auto Answer by chapo.lua:8: in main chunk
[20:39:06.151397] (error) ANSAI - OpenAI Auto Answer (v2): Script died due to an error. (165794BC
что не так
 
  • Bug
Реакции: MLycoris

tfornik

Известный
314
227
[20:39:06.151397] (error) ANSAI - OpenAI Auto Answer (v2): ...P\moonloader\ANSAI v2 - Open AI Auto Answer by chapo.lua:8: module 'fAwesome6' not found:
no field package.preload['fAwesome6']
no file 'C:\Program Files (x86)\MyHome Launcher\bin\SAMP\moonloader\lib\fAwesome6.lua'
no file 'C:\Program Files (x86)\MyHome Launcher\bin\SAMP\moonloader\lib\fAwesome6\init.lua'
no file 'C:\Program Files (x86)\MyHome Launcher\bin\SAMP\moonloader\fAwesome6.lua'
no file 'C:\Program Files (x86)\MyHome Launcher\bin\SAMP\moonloader\fAwesome6\init.lua'
no file '.\fAwesome6.lua'
no file 'C:\Program Files (x86)\MyHome Launcher\bin\SAMP\moonloader\lib\fAwesome6.luac'
no file 'C:\Program Files (x86)\MyHome Launcher\bin\SAMP\moonloader\lib\fAwesome6\init.luac'
no file 'C:\Program Files (x86)\MyHome Launcher\bin\SAMP\moonloader\fAwesome6.luac'
no file 'C:\Program Files (x86)\MyHome Launcher\bin\SAMP\moonloader\fAwesome6\init.luac'
no file '.\fAwesome6.luac'
no file 'C:\Program Files (x86)\MyHome Launcher\bin\SAMP\moonloader\lib\fAwesome6.dll'
stack traceback:
[C]: in function 'require'
...P\moonloader\ANSAI v2 - Open AI Auto Answer by chapo.lua:8: in main chunk
[20:39:06.151397] (error) ANSAI - OpenAI Auto Answer (v2): Script died due to an error. (165794BC
что не так