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

CaJlaT

Овощ
Модератор
2,806
2,607
про первую строку я имел ввиду вверху, как ее убирать?
Lua:
local text = {'Первая строчка'}
function main()
    sampRegisterChatCommand('add', function(arg)
        if #arg < 1 then return sampAddChatMessage('Ошибка, введите текст', -1) end
        table.insert(text, tostring(arg))
        if #text >= 10 then table.remove(text, 1) end
    end)
    local font = renderCreateFont('sagta', 12, 5)
    local pos = {x = 10, y = 400}
    while true do
        wait(0)
        for i, v in ipairs(text) do
            renderFontDrawText(font, v, pos.x, pos.y + 14 * (i-1) --[[14 - размер шрифта + 2 пикселя]], -1)
        end
    end
end
 
  • Клоун
  • Влюблен
Реакции: Fott и minxty

tsunamiqq

Участник
429
16
думаю что нет,а если и есть то платно и на время

потому что это буквально реверс
А не знаешь еще какие-то AIшки кроме ChatGPT которые можно подключить к скрипту?) В ChatGPT есть лимит на отправку сообщений, и со временем он перестает работать, и потом только менять акк в OpenAI
 

ChromiusJ

PARΛDIGM ΛSS
Друг
4,907
3,195
А не знаешь еще какие-то AIшки кроме ChatGPT которые можно подключить к скрипту?) В ChatGPT есть лимит на отправку сообщений, и со временем он перестает работать, и потом только менять акк в OpenAI
ну если это актуально,то наверное можно
 

diva

Известный
251
44
how to minimize fps indicator:
require 'lib.moonloader'

local numbers = {
    ['0'] = {
        {1, 1, 1, 1, 1},
        {1, 0, 0, 0, 1},
        {1, 0, 0, 0, 1},
        {1, 0, 0, 0, 1},
        {1, 0, 0, 0, 1},
        {1, 0, 0, 0, 1},
        {1, 1, 1, 1, 1}
    },
    ['1'] = {
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1}
    },
    ['2'] = {
        {1, 1, 1, 1, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {1, 1, 1, 1, 1},
        {1, 0, 0, 0, 0},
        {1, 0, 0, 0, 0},
        {1, 1, 1, 1, 1}
    },
    ['3'] = {
        {1, 1, 1, 1, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {1, 1, 1, 1, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {1, 1, 1, 1, 1}
    },
    ['4'] = {
        {1, 0, 0, 0, 1},
        {1, 0, 0, 0, 1},
        {1, 0, 0, 0, 1},
        {1, 1, 1, 1, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1}
    },
    ['5'] = {
        {1, 1, 1, 1, 1},
        {1, 0, 0, 0, 0},
        {1, 0, 0, 0, 0},
        {1, 1, 1, 1, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {1, 1, 1, 1, 1}
    },
    ['6'] = {
        {1, 1, 1, 1, 1},
        {1, 0, 0, 0, 0},
        {1, 0, 0, 0, 0},
        {1, 1, 1, 1, 1},
        {1, 0, 0, 0, 1},
        {1, 0, 0, 0, 1},
        {1, 1, 1, 1, 1}
    },
    ['7'] = {
        {1, 1, 1, 1, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1}
    },
    ['8'] = {
        {1, 1, 1, 1, 1},
        {1, 0, 0, 0, 1},
        {1, 0, 0, 0, 1},
        {1, 1, 1, 1, 1},
        {1, 0, 0, 0, 1},
        {1, 0, 0, 0, 1},
        {1, 1, 1, 1, 1}
    },
    ['9'] = {
        {1, 1, 1, 1, 1},
        {1, 0, 0, 0, 1},
        {1, 0, 0, 0, 1},
        {1, 1, 1, 1, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {1, 1, 1, 1, 1}
    },
}

local settings = {
    state = true,
    pos = 0,
    size = 5,
    offset = {0, 0},
}

local memory = require 'memory'
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local spath = getWorkingDirectory() .. "\\config\\fps_nvidia.json"

local o = 1

local fps = 10

local colors = {}

local showfps = imgui.ImBool(false)
local window = imgui.ImBool(false)
local ipos = imgui.ImInt(0)
local offset_x = imgui.ImInt(0)
local offset_y = imgui.ImInt(0)
local size = imgui.ImInt(3)

function getPos()
    local x, y = getScreenResolution()
    if settings.pos == 0 then
        return {x - (5*settings.size)*(#tostring(fps)+1) - settings.offset[1], settings.offset[2]}
    end
    if settings.pos == 1 then
        local rx, ry = (#tostring(fps)*5) + settings.offset[1], settings.offset[2]
        if tostring(fps):sub(1, 1) == "1" then
            rx = rx - settings.size*5
        end
        return {rx, ry}
    end
    if settings.pos == 2 then
        return {x - (5*settings.size)*(#tostring(fps)+1) - settings.offset[1], y - settings.size*5*2 - settings.offset[2]}
    end
    if settings.pos == 3 then
        local rx, ry = (#tostring(fps)*5) + settings.offset[1], y - settings.size*5*2 - settings.offset[2]
        if tostring(fps):sub(1, 1) == "1" then
            rx = rx - settings.size*5
        end
        return {rx, ry}
    end
end

function main()
    while not isSampAvailable() do wait(200) end
    imgui.Process = false
    showfps.v = true
   
    if not doesFileExist(spath) then
        save()
    end

    load()

    showfps.v = settings.state
    ipos.v = settings.pos
    offset_x.v = settings.offset[1]
    offset_y.v = settings.offset[2]
    size.v = settings.size

    sampRegisterChatCommand('nvidia_fps', function()
        window.v = not window.v
    end)

    update_fps()

    while true do
        wait(100)
        imgui.Process = showfps.v or window.v
        imgui.ShowCursor = window.v
    end
end

function imgui.OnDrawFrame()
    if window.v then
        red()
        local x, y = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(x / 2, y / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(5, 5), imgui.Cond.FirstUseEver)
        imgui.Begin('FPS', window)

        if imgui.Checkbox(u8'��������/���������', showfps) then
            settings.state = showfps.v
        end

        if imgui.Combo(u8'���������', ipos, {u8"������ ������", u8"������ �����", u8"����� ������", u8"����� �����"}, -1) then
            settings.pos = ipos.v
            save()
        end

        if imgui.SliderInt(u8"������ �� x", offset_x, 0, 3, 1) then
            settings.offset[1] = offset_x.v
            save()
        end
        if imgui.SliderInt(u8"������ �� y", offset_y, 0, 3, 1) then
            settings.offset[2] = offset_y.v
            save()
        end
        if imgui.SliderInt(u8"������ ������", size, 2, 3, 1) then
            settings.size = size.v
            save()
        end

    end
    if showfps.v then
        invis_imgui()
        imgui.SetNextWindowPos(imgui.ImVec2(getPos()[1]-settings.size, getPos()[2]))
        imgui.SetNextWindowSize(imgui.ImVec2(settings.size*7*(#tostring(fps)), settings.size*9))
        imgui.Begin('fpswindow', showfps, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoTitleBar + imgui.WindowFlags.NoMove)

        imgui.DrawNumber(tostring(fps), settings.size*6)

        imgui.End()
    end
end



function save()
    local f = io.open(spath, "w")
    f:write(encodeJson(settings))
    f:close()
end

function load()
    local f = io.open(spath, "r")
    settings = decodeJson(f:read())
    f:close()
end

function imgui.DrawNumber(a, offset)
    for i=1, #a do
        local number = a:sub(i, i)
        imgui.DrawCharacter(number, (i-1)*offset)
    end
end

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

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

    colors[clr.FrameBg]                = ImVec4(0.48, 0.16, 0.16, 0.54)
    colors[clr.FrameBgHovered]         = ImVec4(0.98, 0.26, 0.26, 0.40)
    colors[clr.FrameBgActive]          = ImVec4(0.98, 0.26, 0.26, 0.67)
    colors[clr.TitleBg]                = ImVec4(0.48, 0.16, 0.16, 1.00)
    colors[clr.TitleBgActive]          = ImVec4(0.48, 0.16, 0.16, 1.00)
    colors[clr.TitleBgCollapsed]       = ImVec4(0.48, 0.16, 0.16, 1.00)
    colors[clr.CheckMark]              = ImVec4(0.98, 0.26, 0.26, 1.00)
    colors[clr.SliderGrab]             = ImVec4(0.88, 0.26, 0.24, 1.00)
    colors[clr.SliderGrabActive]       = ImVec4(0.98, 0.26, 0.26, 1.00)
    colors[clr.Button]                 = ImVec4(0.98, 0.26, 0.26, 0.40)
    colors[clr.ButtonHovered]          = ImVec4(0.98, 0.26, 0.26, 1.00)
    colors[clr.ButtonActive]           = ImVec4(0.98, 0.06, 0.06, 1.00)
    colors[clr.Header]                 = ImVec4(0.98, 0.26, 0.26, 0.31)
    colors[clr.HeaderHovered]          = ImVec4(0.98, 0.26, 0.26, 0.80)
    colors[clr.HeaderActive]           = ImVec4(0.98, 0.26, 0.26, 1.00)
    colors[clr.Separator]              = colors[clr.Border]
    colors[clr.SeparatorHovered]       = ImVec4(0.75, 0.10, 0.10, 0.78)
    colors[clr.SeparatorActive]        = ImVec4(0.75, 0.10, 0.10, 1.00)
    colors[clr.ResizeGrip]             = ImVec4(0.98, 0.26, 0.26, 0.25)
    colors[clr.ResizeGripHovered]      = ImVec4(0.98, 0.26, 0.26, 0.67)
    colors[clr.ResizeGripActive]       = ImVec4(0.98, 0.26, 0.26, 0.95)
    colors[clr.TextSelectedBg]         = ImVec4(0.98, 0.26, 0.26, 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

function imgui.DrawCharacter(a, offset)
    local n = numbers[a]
    if n then
        local dl = imgui.GetWindowDrawList()
        local x, y = getPos()[1], getPos()[2]
        local cof = settings.size
        for i = 1, #n do
            for j = 1, #n[i] do
                if n[i][j] == 1 then
                    dl:AddRectFilled(imgui.ImVec2(x + offset + j * cof, y + (i) * cof), imgui.ImVec2(x + offset + (j+1) * cof, y + (i+1) * cof), 0xFF01b876)
                end
            end
        end
    end
end

function update_fps()
    lua_thread.create(function()
        while true do
            fps = math.ceil(memory.getfloat(0xB7CB50, true))
            wait(650)
        end
    end)
end

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

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

    colors[clr.FrameBg]                = ImVec4(0.48, 0.16, 0.16, 0.00)
    colors[clr.FrameBgHovered]         = ImVec4(0.98, 0.26, 0.26, 0.00)
    colors[clr.FrameBgActive]          = ImVec4(0.98, 0.26, 0.26, 0.00)
    colors[clr.TitleBg]                = ImVec4(0.48, 0.16, 0.16, 0.00)
    colors[clr.TitleBgActive]          = ImVec4(0.48, 0.16, 0.16, 0.00)
    colors[clr.TitleBgCollapsed]       = ImVec4(0.48, 0.16, 0.16, 0.00)
    colors[clr.CheckMark]              = ImVec4(0.98, 0.26, 0.26, 0.00)
    colors[clr.SliderGrab]             = ImVec4(0.88, 0.26, 0.24, 0.00)
    colors[clr.SliderGrabActive]       = ImVec4(0.98, 0.26, 0.26, 0.00)
    colors[clr.Button]                 = ImVec4(0.98, 0.26, 0.26, 0.00)
    colors[clr.ButtonHovered]          = ImVec4(0.98, 0.26, 0.26, 0.00)
    colors[clr.ButtonActive]           = ImVec4(0.98, 0.06, 0.06, 0.00)
    colors[clr.Header]                 = ImVec4(0.98, 0.26, 0.26, 0.00)
    colors[clr.HeaderHovered]          = ImVec4(0.98, 0.26, 0.26, 0.00)
    colors[clr.HeaderActive]           = ImVec4(0.98, 0.26, 0.26, 0.00)
    colors[clr.Separator]              = colors[clr.Border]
    colors[clr.SeparatorHovered]       = ImVec4(0.75, 0.10, 0.10, 0.00)
    colors[clr.SeparatorActive]        = ImVec4(0.75, 0.10, 0.10, 0.00)
    colors[clr.ResizeGrip]             = ImVec4(0.98, 0.26, 0.26, 0.00)
    colors[clr.ResizeGripHovered]      = ImVec4(0.98, 0.26, 0.26, 0.00)
    colors[clr.ResizeGripActive]       = ImVec4(0.98, 0.26, 0.26, 0.00)
    colors[clr.TextSelectedBg]         = ImVec4(0.98, 0.26, 0.26, 0.00)
    colors[clr.Text]                   = ImVec4(1.00, 1.00, 1.00, 1.00)
    colors[clr.TextDisabled]           = ImVec4(0.50, 0.50, 0.50, 0.00)
    colors[clr.WindowBg]               = ImVec4(0.06, 0.06, 0.06, 0.00)
    colors[clr.ChildWindowBg]          = ImVec4(1.00, 1.00, 1.00, 0.00)
    colors[clr.PopupBg]                = ImVec4(0.08, 0.08, 0.08, 0.00)
    colors[clr.ComboBg]                = colors[clr.PopupBg]
    colors[clr.Border]                 = ImVec4(0.43, 0.43, 0.50, 0.00)
    colors[clr.BorderShadow]           = ImVec4(0.00, 0.00, 0.00, 0.00)
    colors[clr.MenuBarBg]              = ImVec4(0.14, 0.14, 0.14, 0.00)
    colors[clr.ScrollbarBg]            = ImVec4(0.02, 0.02, 0.02, 0.00)
    colors[clr.ScrollbarGrab]          = ImVec4(0.31, 0.31, 0.31, 0.00)
    colors[clr.ScrollbarGrabHovered]   = ImVec4(0.41, 0.41, 0.41, 0.00)
    colors[clr.ScrollbarGrabActive]    = ImVec4(0.51, 0.51, 0.51, 0.00)
    colors[clr.CloseButton]            = ImVec4(0.41, 0.41, 0.41, 0.00)
    colors[clr.CloseButtonHovered]     = ImVec4(0.98, 0.39, 0.36, 0.00)
    colors[clr.CloseButtonActive]      = ImVec4(0.98, 0.39, 0.36, 0.00)
    colors[clr.PlotLines]              = ImVec4(0.61, 0.61, 0.61, 0.00)
    colors[clr.PlotLinesHovered]       = ImVec4(1.00, 0.43, 0.35, 0.00)
    colors[clr.PlotHistogram]          = ImVec4(0.90, 0.70, 0.00, 0.00)
    colors[clr.PlotHistogramHovered]   = ImVec4(1.00, 0.60, 0.00, 0.00)
    colors[clr.ModalWindowDarkening]   = ImVec4(0.80, 0.80, 0.80, 0.00)
end
Can't find the minimize thing now it's big fps indicator on screen.
1701357258131.png
 

GORYCH

Известный
63
77
how to minimize fps indicator:
require 'lib.moonloader'

local numbers = {
    ['0'] = {
        {1, 1, 1, 1, 1},
        {1, 0, 0, 0, 1},
        {1, 0, 0, 0, 1},
        {1, 0, 0, 0, 1},
        {1, 0, 0, 0, 1},
        {1, 0, 0, 0, 1},
        {1, 1, 1, 1, 1}
    },
    ['1'] = {
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1}
    },
    ['2'] = {
        {1, 1, 1, 1, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {1, 1, 1, 1, 1},
        {1, 0, 0, 0, 0},
        {1, 0, 0, 0, 0},
        {1, 1, 1, 1, 1}
    },
    ['3'] = {
        {1, 1, 1, 1, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {1, 1, 1, 1, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {1, 1, 1, 1, 1}
    },
    ['4'] = {
        {1, 0, 0, 0, 1},
        {1, 0, 0, 0, 1},
        {1, 0, 0, 0, 1},
        {1, 1, 1, 1, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1}
    },
    ['5'] = {
        {1, 1, 1, 1, 1},
        {1, 0, 0, 0, 0},
        {1, 0, 0, 0, 0},
        {1, 1, 1, 1, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {1, 1, 1, 1, 1}
    },
    ['6'] = {
        {1, 1, 1, 1, 1},
        {1, 0, 0, 0, 0},
        {1, 0, 0, 0, 0},
        {1, 1, 1, 1, 1},
        {1, 0, 0, 0, 1},
        {1, 0, 0, 0, 1},
        {1, 1, 1, 1, 1}
    },
    ['7'] = {
        {1, 1, 1, 1, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1}
    },
    ['8'] = {
        {1, 1, 1, 1, 1},
        {1, 0, 0, 0, 1},
        {1, 0, 0, 0, 1},
        {1, 1, 1, 1, 1},
        {1, 0, 0, 0, 1},
        {1, 0, 0, 0, 1},
        {1, 1, 1, 1, 1}
    },
    ['9'] = {
        {1, 1, 1, 1, 1},
        {1, 0, 0, 0, 1},
        {1, 0, 0, 0, 1},
        {1, 1, 1, 1, 1},
        {0, 0, 0, 0, 1},
        {0, 0, 0, 0, 1},
        {1, 1, 1, 1, 1}
    },
}

local settings = {
    state = true,
    pos = 0,
    size = 5,
    offset = {0, 0},
}

local memory = require 'memory'
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local spath = getWorkingDirectory() .. "\\config\\fps_nvidia.json"

local o = 1

local fps = 10

local colors = {}

local showfps = imgui.ImBool(false)
local window = imgui.ImBool(false)
local ipos = imgui.ImInt(0)
local offset_x = imgui.ImInt(0)
local offset_y = imgui.ImInt(0)
local size = imgui.ImInt(3)

function getPos()
    local x, y = getScreenResolution()
    if settings.pos == 0 then
        return {x - (5*settings.size)*(#tostring(fps)+1) - settings.offset[1], settings.offset[2]}
    end
    if settings.pos == 1 then
        local rx, ry = (#tostring(fps)*5) + settings.offset[1], settings.offset[2]
        if tostring(fps):sub(1, 1) == "1" then
            rx = rx - settings.size*5
        end
        return {rx, ry}
    end
    if settings.pos == 2 then
        return {x - (5*settings.size)*(#tostring(fps)+1) - settings.offset[1], y - settings.size*5*2 - settings.offset[2]}
    end
    if settings.pos == 3 then
        local rx, ry = (#tostring(fps)*5) + settings.offset[1], y - settings.size*5*2 - settings.offset[2]
        if tostring(fps):sub(1, 1) == "1" then
            rx = rx - settings.size*5
        end
        return {rx, ry}
    end
end

function main()
    while not isSampAvailable() do wait(200) end
    imgui.Process = false
    showfps.v = true
  
    if not doesFileExist(spath) then
        save()
    end

    load()

    showfps.v = settings.state
    ipos.v = settings.pos
    offset_x.v = settings.offset[1]
    offset_y.v = settings.offset[2]
    size.v = settings.size

    sampRegisterChatCommand('nvidia_fps', function()
        window.v = not window.v
    end)

    update_fps()

    while true do
        wait(100)
        imgui.Process = showfps.v or window.v
        imgui.ShowCursor = window.v
    end
end

function imgui.OnDrawFrame()
    if window.v then
        red()
        local x, y = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(x / 2, y / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(5, 5), imgui.Cond.FirstUseEver)
        imgui.Begin('FPS', window)

        if imgui.Checkbox(u8'��������/���������', showfps) then
            settings.state = showfps.v
        end

        if imgui.Combo(u8'���������', ipos, {u8"������ ������", u8"������ �����", u8"����� ������", u8"����� �����"}, -1) then
            settings.pos = ipos.v
            save()
        end

        if imgui.SliderInt(u8"������ �� x", offset_x, 0, 3, 1) then
            settings.offset[1] = offset_x.v
            save()
        end
        if imgui.SliderInt(u8"������ �� y", offset_y, 0, 3, 1) then
            settings.offset[2] = offset_y.v
            save()
        end
        if imgui.SliderInt(u8"������ ������", size, 2, 3, 1) then
            settings.size = size.v
            save()
        end

    end
    if showfps.v then
        invis_imgui()
        imgui.SetNextWindowPos(imgui.ImVec2(getPos()[1]-settings.size, getPos()[2]))
        imgui.SetNextWindowSize(imgui.ImVec2(settings.size*7*(#tostring(fps)), settings.size*9))
        imgui.Begin('fpswindow', showfps, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoTitleBar + imgui.WindowFlags.NoMove)

        imgui.DrawNumber(tostring(fps), settings.size*6)

        imgui.End()
    end
end



function save()
    local f = io.open(spath, "w")
    f:write(encodeJson(settings))
    f:close()
end

function load()
    local f = io.open(spath, "r")
    settings = decodeJson(f:read())
    f:close()
end

function imgui.DrawNumber(a, offset)
    for i=1, #a do
        local number = a:sub(i, i)
        imgui.DrawCharacter(number, (i-1)*offset)
    end
end

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

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

    colors[clr.FrameBg]                = ImVec4(0.48, 0.16, 0.16, 0.54)
    colors[clr.FrameBgHovered]         = ImVec4(0.98, 0.26, 0.26, 0.40)
    colors[clr.FrameBgActive]          = ImVec4(0.98, 0.26, 0.26, 0.67)
    colors[clr.TitleBg]                = ImVec4(0.48, 0.16, 0.16, 1.00)
    colors[clr.TitleBgActive]          = ImVec4(0.48, 0.16, 0.16, 1.00)
    colors[clr.TitleBgCollapsed]       = ImVec4(0.48, 0.16, 0.16, 1.00)
    colors[clr.CheckMark]              = ImVec4(0.98, 0.26, 0.26, 1.00)
    colors[clr.SliderGrab]             = ImVec4(0.88, 0.26, 0.24, 1.00)
    colors[clr.SliderGrabActive]       = ImVec4(0.98, 0.26, 0.26, 1.00)
    colors[clr.Button]                 = ImVec4(0.98, 0.26, 0.26, 0.40)
    colors[clr.ButtonHovered]          = ImVec4(0.98, 0.26, 0.26, 1.00)
    colors[clr.ButtonActive]           = ImVec4(0.98, 0.06, 0.06, 1.00)
    colors[clr.Header]                 = ImVec4(0.98, 0.26, 0.26, 0.31)
    colors[clr.HeaderHovered]          = ImVec4(0.98, 0.26, 0.26, 0.80)
    colors[clr.HeaderActive]           = ImVec4(0.98, 0.26, 0.26, 1.00)
    colors[clr.Separator]              = colors[clr.Border]
    colors[clr.SeparatorHovered]       = ImVec4(0.75, 0.10, 0.10, 0.78)
    colors[clr.SeparatorActive]        = ImVec4(0.75, 0.10, 0.10, 1.00)
    colors[clr.ResizeGrip]             = ImVec4(0.98, 0.26, 0.26, 0.25)
    colors[clr.ResizeGripHovered]      = ImVec4(0.98, 0.26, 0.26, 0.67)
    colors[clr.ResizeGripActive]       = ImVec4(0.98, 0.26, 0.26, 0.95)
    colors[clr.TextSelectedBg]         = ImVec4(0.98, 0.26, 0.26, 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

function imgui.DrawCharacter(a, offset)
    local n = numbers[a]
    if n then
        local dl = imgui.GetWindowDrawList()
        local x, y = getPos()[1], getPos()[2]
        local cof = settings.size
        for i = 1, #n do
            for j = 1, #n[i] do
                if n[i][j] == 1 then
                    dl:AddRectFilled(imgui.ImVec2(x + offset + j * cof, y + (i) * cof), imgui.ImVec2(x + offset + (j+1) * cof, y + (i+1) * cof), 0xFF01b876)
                end
            end
        end
    end
end

function update_fps()
    lua_thread.create(function()
        while true do
            fps = math.ceil(memory.getfloat(0xB7CB50, true))
            wait(650)
        end
    end)
end

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

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

    colors[clr.FrameBg]                = ImVec4(0.48, 0.16, 0.16, 0.00)
    colors[clr.FrameBgHovered]         = ImVec4(0.98, 0.26, 0.26, 0.00)
    colors[clr.FrameBgActive]          = ImVec4(0.98, 0.26, 0.26, 0.00)
    colors[clr.TitleBg]                = ImVec4(0.48, 0.16, 0.16, 0.00)
    colors[clr.TitleBgActive]          = ImVec4(0.48, 0.16, 0.16, 0.00)
    colors[clr.TitleBgCollapsed]       = ImVec4(0.48, 0.16, 0.16, 0.00)
    colors[clr.CheckMark]              = ImVec4(0.98, 0.26, 0.26, 0.00)
    colors[clr.SliderGrab]             = ImVec4(0.88, 0.26, 0.24, 0.00)
    colors[clr.SliderGrabActive]       = ImVec4(0.98, 0.26, 0.26, 0.00)
    colors[clr.Button]                 = ImVec4(0.98, 0.26, 0.26, 0.00)
    colors[clr.ButtonHovered]          = ImVec4(0.98, 0.26, 0.26, 0.00)
    colors[clr.ButtonActive]           = ImVec4(0.98, 0.06, 0.06, 0.00)
    colors[clr.Header]                 = ImVec4(0.98, 0.26, 0.26, 0.00)
    colors[clr.HeaderHovered]          = ImVec4(0.98, 0.26, 0.26, 0.00)
    colors[clr.HeaderActive]           = ImVec4(0.98, 0.26, 0.26, 0.00)
    colors[clr.Separator]              = colors[clr.Border]
    colors[clr.SeparatorHovered]       = ImVec4(0.75, 0.10, 0.10, 0.00)
    colors[clr.SeparatorActive]        = ImVec4(0.75, 0.10, 0.10, 0.00)
    colors[clr.ResizeGrip]             = ImVec4(0.98, 0.26, 0.26, 0.00)
    colors[clr.ResizeGripHovered]      = ImVec4(0.98, 0.26, 0.26, 0.00)
    colors[clr.ResizeGripActive]       = ImVec4(0.98, 0.26, 0.26, 0.00)
    colors[clr.TextSelectedBg]         = ImVec4(0.98, 0.26, 0.26, 0.00)
    colors[clr.Text]                   = ImVec4(1.00, 1.00, 1.00, 1.00)
    colors[clr.TextDisabled]           = ImVec4(0.50, 0.50, 0.50, 0.00)
    colors[clr.WindowBg]               = ImVec4(0.06, 0.06, 0.06, 0.00)
    colors[clr.ChildWindowBg]          = ImVec4(1.00, 1.00, 1.00, 0.00)
    colors[clr.PopupBg]                = ImVec4(0.08, 0.08, 0.08, 0.00)
    colors[clr.ComboBg]                = colors[clr.PopupBg]
    colors[clr.Border]                 = ImVec4(0.43, 0.43, 0.50, 0.00)
    colors[clr.BorderShadow]           = ImVec4(0.00, 0.00, 0.00, 0.00)
    colors[clr.MenuBarBg]              = ImVec4(0.14, 0.14, 0.14, 0.00)
    colors[clr.ScrollbarBg]            = ImVec4(0.02, 0.02, 0.02, 0.00)
    colors[clr.ScrollbarGrab]          = ImVec4(0.31, 0.31, 0.31, 0.00)
    colors[clr.ScrollbarGrabHovered]   = ImVec4(0.41, 0.41, 0.41, 0.00)
    colors[clr.ScrollbarGrabActive]    = ImVec4(0.51, 0.51, 0.51, 0.00)
    colors[clr.CloseButton]            = ImVec4(0.41, 0.41, 0.41, 0.00)
    colors[clr.CloseButtonHovered]     = ImVec4(0.98, 0.39, 0.36, 0.00)
    colors[clr.CloseButtonActive]      = ImVec4(0.98, 0.39, 0.36, 0.00)
    colors[clr.PlotLines]              = ImVec4(0.61, 0.61, 0.61, 0.00)
    colors[clr.PlotLinesHovered]       = ImVec4(1.00, 0.43, 0.35, 0.00)
    colors[clr.PlotHistogram]          = ImVec4(0.90, 0.70, 0.00, 0.00)
    colors[clr.PlotHistogramHovered]   = ImVec4(1.00, 0.60, 0.00, 0.00)
    colors[clr.ModalWindowDarkening]   = ImVec4(0.80, 0.80, 0.80, 0.00)
end
Can't find the minimize thing now it's big fps indicator on screen. Посмотреть вложение 222860
In settings object change size from 5 to 3 for example

Lua:
local settings = {
    state = true,
    pos = 0,
    size = 3,
    offset = {0, 0},
}
 

MrDorlik

Известный
977
392
как alias юзать? где-то примерно так видел, но почему-то таблица дублируется в название, а через филды долго очень
Lua:
---@class test_class1
---@field x number
---@field y number
---@type test_class1
local abc1

---@alias test_class2 {x: number, y: number}
---@type test_class2
local abc2
1701365573240.png
1701365590036.png
 
Последнее редактирование:

Mico

Активный
246
46
Всем привет, такой вопрос. Возможно ли реализовать такое и если можно, то дайте пожалуйста так скажем намек, как это сделать)

Допустим, есть специальный файл,, в который я закидываю определенный текст. Допустим:

Антон
Миша
Саша

Далее, захожу в игру, запускаю скрипт и он в свою очередь, берет именно эти имена, проверяет у них допустим стату и выводит в другой файл:

Антон, стата 2:3
Миша, стата 6:3
Саша, стата 8:3
 

ChromiusJ

PARΛDIGM ΛSS
Друг
4,907
3,195
Всем привет, такой вопрос. Возможно ли реализовать такое и если можно, то дайте пожалуйста так скажем намек, как это сделать)

Допустим, есть специальный файл,, в который я закидываю определенный текст. Допустим:

Антон
Миша
Саша

Далее, захожу в игру, запускаю скрипт и он в свою очередь, берет именно эти имена, проверяет у них допустим стату и выводит в другой файл:

Антон, стата 2:3
Миша, стата 6:3
Саша, стата 8:3
 

7 СМЕРТНЫХ ГРЕХОВ

Известный
515
159
Такой вопрос есть ещё какой то способ нажатия ALT?
Кроме этих

1:
local data = samp_create_sync_data('player')
data.keysData = data.keysData + 1024
data.send()

2:
setVirtualKeyDown(VK_LMENU,true)
wait(∞)
setVirtualKeyDown(VK_LMENU,false)

3:
setGameKeyState(int key, int state)
 

why ega

РП игрок
Модератор
2,547
2,238
Такой вопрос есть ещё какой то способ нажатия ALT?
Кроме этих

1:
local data = samp_create_sync_data('player')
data.keysData = data.keysData + 1024
data.send()

2:
setVirtualKeyDown(VK_LMENU,true)
wait(∞)
setVirtualKeyDown(VK_LMENU,false)

3:
setGameKeyState(int key, int state)
Нет скорее всего. Тут скорее зависит от того, что тебе необходимо сделать
 

minxty

Известный
878
757
Такой вопрос есть ещё какой то способ нажатия ALT?
Кроме этих

1:
local data = samp_create_sync_data('player')
data.keysData = data.keysData + 1024
data.send()

2:
setVirtualKeyDown(VK_LMENU,true)
wait(∞)
setVirtualKeyDown(VK_LMENU,false)

3:
setGameKeyState(int key, int state)
https://www.blast.hk/threads/93553/ ?