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

Corrygаn

Участник
225
6
Немного не понял, в чём ошибка?
WallHack:
script_properties("work-in-pause")

local keys = require "vkeys"
local sampev = require "lib.samp.events"
local imgui = require "imgui"
local encoding = require "encoding"
encoding.default = "CP1251"
u8 = encoding.UTF8
local ffi = require "ffi"
local getBonePosition = ffi.cast("int (__thiscall*)(void*, float*, int, bool)", 0x5E4280)
local fa = require "faIcons"
local rkeys = require "rkeys"
imgui.ToggleButton = require("imgui_addons").ToggleButton

local ds_glyph_ranges = imgui.GetIO().Fonts:GetGlyphRangesCyrillic()
local fas_glyph_ranges = imgui.GetIO().Fonts:GetGlyphRangesCyrillic()
local fa_glyph_ranges = imgui.ImGlyphRanges({ fa.min_range, fa.max_range })

function imgui.BeforeDrawFrame()
    if default_font == nil then
        default_font = imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\trebucbd.ttf', 16.0, nil, imgui.GetIO().Fonts:GetGlyphRangesCyrillic())
    end

    if ds_font == nil then
        local font_config = imgui.ImFontConfig()
        font_config.MergeMode = true
        ds_font = imgui.GetIO().Fonts:AddFontFromFileTTF("moonloader/resource/fonts/Dopestyle.ttf", 62.0, font_config, ds_glyph_ranges)
    end

    if fa_font == nil then
        local font_config = imgui.ImFontConfig()
        font_config.MergeMode = true
        fa_font = imgui.GetIO().Fonts:AddFontFromFileTTF("moonloader/resource/fonts/fontawesome-webfont.ttf", 14.0, font_config, fa_glyph_ranges)
    end
end

function imgui.TextColoredRGB(text)
    local style = imgui.GetStyle()
    local colors = style.Colors
    local ImVec4 = imgui.ImVec4

    local explode_argb = function(argb)
        local a = bit.band(bit.rshift(argb, 24), 0xFF)
        local r = bit.band(bit.rshift(argb, 16), 0xFF)
        local g = bit.band(bit.rshift(argb, 8), 0xFF)
        local b = bit.band(argb, 0xFF)
        return a, r, g, b
    end

    local getcolor = function(color)
        if color:sub(1, 6):upper() == 'SSSSSS' then
            local r, g, b = colors[1].x, colors[1].y, colors[1].z
            local a = tonumber(color:sub(7, 8), 16) or colors[1].w * 255
            return ImVec4(r, g, b, a / 255)
        end
        local color = type(color) == 'string' and tonumber(color, 16) or color
        if type(color) ~= 'number' then return end
        local r, g, b, a = explode_argb(color)
        return imgui.ImColor(r, g, b, a):GetVec4()
    end

    local render_text = function(text_)
        for w in text_:gmatch('[^\r\n]+') do
            local text, colors_, m = {}, {}, 1
            w = w:gsub('{(......)}', '{%1FF}')
            while w:find('{........}') do
                local n, k = w:find('{........}')
                local color = getcolor(w:sub(n + 1, k - 1))
                if color then
                    text[#text], text[#text + 1] = w:sub(m, n - 1), w:sub(k + 1, #w)
                    colors_[#colors_ + 1] = color
                    m = n
                end
                w = w:sub(1, n - 1) .. w:sub(k + 1, #w)
            end
            if text[0] then
                for i = 0, #text do
                    imgui.TextColored(colors_[i] or colors[1], u8(text[i]))
                    imgui.SameLine(nil, 0)
                end
                imgui.NewLine()
            else imgui.Text(u8(w)) end
        end
    end

    render_text(text)
end

function imgui.CenterText(text)
    local width = imgui.GetWindowWidth()
    local calc = imgui.CalcTextSize(text)
    imgui.SetCursorPosX( width / 2 - calc.x / 2 )
    imgui.Text(text)
end

local sw, sh = getScreenResolution()
local main_wh = imgui.ImBool(false)

local skeleton_bones = imgui.ImBool(false)
local wallhack = imgui.ImBool(false)
local tolsh = imgui.ImBuffer(256)
local sl_thickness = imgui.ImInt(2)
local sl_dist = imgui.ImInt(25)
local boxes = imgui.ImBool(false)
local type_of_box = imgui.ImInt()
local wopp = imgui.ImBool(false)
local boxsize = imgui.ImInt(2)
local bx_thickness = imgui.ImInt(4)

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

    --sampRegisterChatCommand("wh", cmd_wh)
    sampfuncsRegisterConsoleCommand("wh", cmd_wh)

    imgui.Process = false
    apply_custom_style()
    
    while true do
        wait(0)
        if main_wh.v == false then
            imgui.Process = false
        end

        if skeleton_bones.v then
            bones_wh()
        end

        if type_of_box.v == 1 then
            Boxes()
        elseif type_of_box.v == 2 then
            Boxes2D()
        end
    end
end

function cmd_wh()
    main_wh.v = not main_wh.v
    imgui.Process = main_wh.v
end

function imgui.OnDrawFrame()
    imgui.SetNextWindowSize(imgui.ImVec2(1200, 720), imgui.Cond.FirstUseEver)
    imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.Begin("##1", main_wh, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
    imgui.NewLine()
    imgui.NewLine()
    imgui.PushFont(ds_font)
    imgui.Text("WallHack  by Corrygan")
    imgui.PopFont()
    imgui.NewLine()
    imgui.Separator()
    imgui.Columns(2, "", true)
    imgui.SetColumnWidth(-1, 300)
    imgui.BeginChild("##child1", imgui.ImVec2(290, 600), false)
        imgui.BeginChild("##child2", imgui.ImVec2(280, 130), true)
        _, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
        imgui.Text(u8"NickName: " .. sampGetPlayerNickname(id))
        imgui.Text(u8"Ваш игровой уровень: " .. sampGetPlayerScore(id))
        imgui.Text(u8"Ваш пинг на данный момент: " .. sampGetPlayerPing(id))
        imgui.Text(u8"Ваш ID: " .. id)
        imgui.Text(u8"Уровень здоровья: " .. sampGetPlayerHealth(id))
        imgui.Text(u8"Кол-во брони: " .. sampGetPlayerArmor(id))
        imgui.EndChild()
    imgui.SetCursorPosX((imgui.GetWindowWidth() - 270) / 2)
    if imgui.Button(u8"Разработчик скрипта:\n        Связь в ВК", imgui.ImVec2(270, 55)) then
        os.execute("start https://vk.com/corryganyashka")
    end
    imgui.EndChild()
    imgui.NextColumn()
    imgui.ToggleButton(u8'Кости', skeleton_bones)
    imgui.SameLine()
    imgui.PushItemWidth(128)
    imgui.SliderInt(u8'Толщина костей', sl_thickness, 1, 10)
    imgui.PushItemWidth(128)
    imgui.SliderInt(u8'Дистанция', sl_dist, 1, 50)
    imgui.NewLine()
    imgui.ToggleButton(u8"Боксы", boxes)
    imgui.SameLine()
    imgui.RadioButton("3D", type_of_box, 1)
    imgui.SameLine()
    imgui.RadioButton("2    D", type_of_box, 2)
    imgui.SliderInt(u8"Размер боксов", boxsize, 0.1, 5)
    imgui.SameLine()
    imgui.SliderInt(u8"Толщина боксов", bx_thickness, 0.1, 10)
    imgui.Checkbox(u8"Работает на мне?", wopp)
    imgui.End()
end

function join_argb(a, r, g, b)
    local argb = b  -- b
    argb = bit.bor(argb, bit.lshift(g, 8))  -- g
    argb = bit.bor(argb, bit.lshift(r, 16)) -- r
    argb = bit.bor(argb, bit.lshift(a, 24)) -- a
    return argb
end
 
function explode_argb(argb)
    local a = bit.band(bit.rshift(argb, 24), 0xFF)
    local r = bit.band(bit.rshift(argb, 16), 0xFF)
    local g = bit.band(bit.rshift(argb, 8), 0xFF)
    local b = bit.band(argb, 0xFF)
    return a, r, g, b
end

function bones_wh()
    lua_thread.create(function()
        for k, i in ipairs(getAllChars()) do
            pedX, pedY, pedZ = getCharCoordinates(i)
            myX, myY, myZ = getCharCoordinates(PLAYER_PED)
            distance = getDistanceBetweenCoords3d(pedX, pedY, pedZ, myX, myY, myZ)
            
            if doesCharExist(i) and isCharOnScreen(i) and i ~= PLAYER_PED and distance <= sl_dist.v then
            _, id = sampGetPlayerIdByCharHandle(i)
            local color = sampGetPlayerColor(id)
            local aa, rr, gg, bb = explode_argb(color)
            local color = join_argb(255, rr, gg, bb)
    
            thickness = sl_thickness.v --толщина
            
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(6, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(7, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(7, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(8, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(8, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(6, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
            
            
            
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(1, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(4, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(4, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(8, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
            
    
            
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(21, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(22, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(22, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(23, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(23, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(24, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(24, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(25, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
            
    
            
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(31, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(32, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(32, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(33, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(33, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(34, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(34, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(35, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
            
    
            
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(1, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(51, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(51, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(52, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(52, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(53, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(53, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(54, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
            
    
            
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(1, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(41, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(41, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(42, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(42, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(43, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)
    
            pos1X, pos1Y, pos1Z = getBodyPartCoordinates(43, i)
            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(44, i)
            
            pos1, pos2 = convert3DCoordsToScreen(pos1X, pos1Y, pos1Z)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawLine(pos1, pos2, pos3, pos4, thickness, color)

            pos2X, pos2Y, pos2Z = getBodyPartCoordinates(44, i)
            pos3, pos4 = convert3DCoordsToScreen(pos2X, pos2Y, pos2Z)
            renderDrawPolygon(pos3, pos4, thickness, thickness, 100, 0, color)   
            end   
        end
    end)
end

function getBodyPartCoordinates(id, handle)
    if doesCharExist(handle) then
        local pedptr = getCharPointer(handle)
        local vec = ffi.new("float[3]")
        getBonePosition(ffi.cast("void*", pedptr), vec, id, true)
        return vec[0], vec[1], vec[2]
    end
end

function Boxes()
    lua_thread.create(function()
        for k,v in ipairs(getAllChars()) do
            if isCharOnScreen(v) then
                if boxes.v then
                    if type_of_box.v == 1 then
                        if wopp.v then
                            size = boxsize.v
                            size_vertical = 0.7
                            thickness = bx_thickness.v
                            local pos = {getCharCoordinates(v)}
                            local pos_1 = {convert3DCoordsToScreen(pos[1] + size, pos[2] - size, pos[3] - size_vertical)}
                            local pos_2 = {convert3DCoordsToScreen(pos[1] + size, pos[2] + size, pos[3] - size_vertical)}
                            renderDrawLine(pos_2[1], pos_2[2], pos_1[1], pos_1[2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                            local pos_3 = {convert3DCoordsToScreen(pos[1] + size, pos[2] + size, pos[3] + size_vertical)}
                            renderDrawLine(pos_2[1], pos_2[2], pos_3[1], pos_3[2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                            local pos_4 = {convert3DCoordsToScreen(pos[1] + size, pos[2] - size, pos[3] + size_vertical)}
                            renderDrawLine(pos_3[1], pos_3[2], pos_4[1], pos_4[2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                            local pos_5 = {convert3DCoordsToScreen(pos[1] + size, pos[2] - size, pos[3] - size_vertical)}
                            renderDrawLine(pos_4[1], pos_4[2], pos_5[1], pos_5[2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                            local pos_1 = {convert3DCoordsToScreen(pos[1] - size, pos[2] - size, pos[3] - size_vertical)}
                            local pos_2 = {convert3DCoordsToScreen(pos[1] + size, pos[2] - size, pos[3] - size_vertical)}
                            renderDrawLine(pos_2[1], pos_2[2], pos_1[1], pos_1[2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                            local pos_3 = {convert3DCoordsToScreen(pos[1] - size, pos[2] + size, pos[3] - size_vertical)}
                            local pos_4 = {convert3DCoordsToScreen(pos[1] + size, pos[2] + size, pos[3] - size_vertical)}
                            renderDrawLine(pos_3[1], pos_3[2], pos_4[1], pos_4[2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                            local pos_5 = {convert3DCoordsToScreen(pos[1] - size, pos[2] + size, pos[3] + size_vertical)}
                            local pos_6 = {convert3DCoordsToScreen(pos[1] + size, pos[2] + size, pos[3] + size_vertical)}
                            renderDrawLine(pos_5[1], pos_5[2], pos_6[1], pos_6[2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                            local pos_5 = {convert3DCoordsToScreen(pos[1] - size, pos[2] - size, pos[3] + size_vertical)}
                            local pos_6 = {convert3DCoordsToScreen(pos[1] + size, pos[2] - size, pos[3] + size_vertical)}
                            renderDrawLine(pos_5[1], pos_5[2], pos_6[1], pos_6[2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                            local pos_1 = {convert3DCoordsToScreen(pos[1] - size, pos[2] - size, pos[3] - size_vertical)}
                            local pos_2 = {convert3DCoordsToScreen(pos[1] - size, pos[2] + size, pos[3] - size_vertical)}
                            renderDrawLine(pos_2[1], pos_2[2], pos_1[1], pos_1[2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                            local pos_3 = {convert3DCoordsToScreen(pos[1] - size, pos[2] + size, pos[3] + size_vertical)}
                            renderDrawLine(pos_2[1], pos_2[2], pos_3[1], pos_3[2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                            local pos_4 = {convert3DCoordsToScreen(pos[1] - size, pos[2] - size, pos[3] + size_vertical)}
                            renderDrawLine(pos_3[1], pos_3[2], pos_4[1], pos_4[2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                            local pos_5 = {convert3DCoordsToScreen(pos[1] - size, pos[2] - size, pos[3] - size_vertical)}
                            renderDrawLine(pos_4[1], pos_4[2], pos_5[1], pos_5[2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                        else
                            if v ~= PLAYER_PED then
                                size = boxsize.v
                                size_vertical = 0.7
                                thickness = bx_thickness.v
                                local pos = {getCharCoordinates(v)}
                                local pos_1 = {convert3DCoordsToScreen(pos[1] + size, pos[2] - size, pos[3] - size_vertical)}
                                local pos_2 = {convert3DCoordsToScreen(pos[1] + size, pos[2] + size, pos[3] - size_vertical)}
                                renderDrawLine(pos_2[1], pos_2[2], pos_1[1], pos_1[2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                                local pos_3 = {convert3DCoordsToScreen(pos[1] + size, pos[2] + size, pos[3] + size_vertical)}
                                renderDrawLine(pos_2[1], pos_2[2], pos_3[1], pos_3[2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                                local pos_4 = {convert3DCoordsToScreen(pos[1] + size, pos[2] - size, pos[3] + size_vertical)}
                                renderDrawLine(pos_3[1], pos_3[2], pos_4[1], pos_4[2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                                local pos_5 = {convert3DCoordsToScreen(pos[1] + size, pos[2] - size, pos[3] - size_vertical)}
                                renderDrawLine(pos_4[1], pos_4[2], pos_5[1], pos_5[2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                                local pos_1 = {convert3DCoordsToScreen(pos[1] - size, pos[2] - size, pos[3] - size_vertical)}
                                local pos_2 = {convert3DCoordsToScreen(pos[1] + size, pos[2] - size, pos[3] - size_vertical)}
                                renderDrawLine(pos_2[1], pos_2[2], pos_1[1], pos_1[2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                                local pos_3 = {convert3DCoordsToScreen(pos[1] - size, pos[2] + size, pos[3] - size_vertical)}
                                local pos_4 = {convert3DCoordsToScreen(pos[1] + size, pos[2] + size, pos[3] - size_vertical)}
                                renderDrawLine(pos_3[1], pos_3[2], pos_4[1], pos_4[2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                                local pos_5 = {convert3DCoordsToScreen(pos[1] - size, pos[2] + size, pos[3] + size_vertical)}
                                local pos_6 = {convert3DCoordsToScreen(pos[1] + size, pos[2] + size, pos[3] + size_vertical)}
                                renderDrawLine(pos_5[1], pos_5[2], pos_6[1], pos_6[2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                                local pos_5 = {convert3DCoordsToScreen(pos[1] - size, pos[2] - size, pos[3] + size_vertical)}
                                local pos_6 = {convert3DCoordsToScreen(pos[1] + size, pos[2] - size, pos[3] + size_vertical)}
                                renderDrawLine(pos_5[1], pos_5[2], pos_6[1], pos_6[2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                                local pos_1 = {convert3DCoordsToScreen(pos[1] - size, pos[2] - size, pos[3] - size_vertical)}
                                local pos_2 = {convert3DCoordsToScreen(pos[1] - size, pos[2] + size, pos[3] - size_vertical)}
                                renderDrawLine(pos_2[1], pos_2[2], pos_1[1], pos_1[2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                                local pos_3 = {convert3DCoordsToScreen(pos[1] - size, pos[2] + size, pos[3] + size_vertical)}
                                renderDrawLine(pos_2[1], pos_2[2], pos_3[1], pos_3[2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                                local pos_4 = {convert3DCoordsToScreen(pos[1] - size, pos[2] - size, pos[3] + size_vertical)}
                                renderDrawLine(pos_3[1], pos_3[2], pos_4[1], pos_4[2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                                local pos_5 = {convert3DCoordsToScreen(pos[1] - size, pos[2] - size, pos[3] - size_vertical)}
                                renderDrawLine(pos_4[1], pos_4[2], pos_5[1], pos_5[2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                            end
                        end
                    else
                        size = boxsize.v
                        size_vertical = 0.7
                        thickness = bx_thickness.v
                        pos2dX, pos2dY = getCharCoordinates(PLAYER_PED)
                        wposX, wposY = convert3DCoordsToScreen(pos2dX, pos2dY)
                        renderDrawBox(wposX, wposY, 500, 500, 0xFFFFFFFF)
                        renderDrawBox(500, 500, 1, 2, 0xFFFF0000)
                    end
                end
            end
        end
    end)
end

function Boxes2D()
    lua_thread.create(function()
        for k,v in ipairs(getAllChars()) do
            if isCharOnScreen(v) then 
                if boxes.v  then
                    if wopp.v then   
                        
                        size = 1
                        size_vertical = 0.3
                        thickness = bx_thickness.v
                        local head_pos = {getBodyPartCoordinates(8, v)}
                        local leg_pos = {getBodyPartCoordinates(44, v)}
                        local pos_1 = {convert3DCoordsToScreen(head_pos[1], head_pos[2], head_pos[3] + 0.2)}
                        local pos_2 = {convert3DCoordsToScreen(head_pos[1], head_pos[2], head_pos[3] - (head_pos[3] - leg_pos[3]) - 0.1)}
                        a = boxWidth(pos_1[2], pos_2[2])
                        local box_corners = {
                            {pos_1[1] - a, pos_1[2]},
                            {pos_1[1] + a, pos_1[2]},
                            {pos_2[1] - a, pos_2[2]},
                            {pos_2[1] + a, pos_2[2]}
                        }
                        renderDrawLine(box_corners[1][1], box_corners[1][2], box_corners[2][1], box_corners[2][2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                        renderDrawLine(box_corners[3][1], box_corners[3][2], box_corners[4][1], box_corners[4][2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                        renderDrawLine(box_corners[1][1], box_corners[1][2], box_corners[3][1], box_corners[3][2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                        renderDrawLine(box_corners[2][1], box_corners[2][2], box_corners[4][1], box_corners[4][2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                    else
                        if v ~= PLAYER_PED then
                            size = 1
                            size_vertical = 0.3
                            thickness = 1
                            local head_pos = {getBodyPartCoordinates(8, v)}
                            local leg_pos = {getBodyPartCoordinates(44, v)}
                            local pos_1 = {convert3DCoordsToScreen(head_pos[1], head_pos[2], head_pos[3] + 0.2)}
                            local pos_2 = {convert3DCoordsToScreen(head_pos[1], head_pos[2], head_pos[3] - (head_pos[3] - leg_pos[3]) - 0.1)}
                            a = boxWidth(pos_1[2], pos_2[2])
                            local box_corners = {
                                {pos_1[1] - a, pos_1[2]},
                                {pos_1[1] + a, pos_1[2]},
                                {pos_2[1] - a, pos_2[2]},
                                {pos_2[1] + a, pos_2[2]}
                            }
                            renderDrawLine(box_corners[1][1], box_corners[1][2], box_corners[2][1], box_corners[2][2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                            renderDrawLine(box_corners[3][1], box_corners[3][2], box_corners[4][1], box_corners[4][2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                            renderDrawLine(box_corners[1][1], box_corners[1][2], box_corners[3][1], box_corners[3][2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                            renderDrawLine(box_corners[2][1], box_corners[2][2], box_corners[4][1], box_corners[4][2], thickness, sampGetPlayerColor(select(2, sampGetPlayerIdByCharHandle(v))))
                        end
                    end
                end
            end
        end
    end)
end

function boxWidth(a,b)
    h = b - a
    ang = (7 * math.pi)/180
    x = (h * math.tan(ang)) * 2
    return x
end

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

    style.WindowPadding       = ImVec2(10, 10)
    style.WindowRounding      = 16
    style.ChildWindowRounding = 16
    style.FramePadding        = ImVec2(10, 5)
    style.FrameRounding       = 8
    style.ItemSpacing         = ImVec2(8, 5)
    style.TouchExtraPadding   = ImVec2(0, 0)
    style.IndentSpacing       = 21
    style.ScrollbarSize       = 11
    style.ScrollbarRounding   = 10
    style.GrabMinSize         = 10
    style.GrabRounding        = 6
    style.WindowTitleAlign       = ImVec2(0.50, 0.50)
    style.ButtonTextAlign     = ImVec2(0.50, 0.50)

    colors[clr.FrameBg]                = ImVec4(0.16, 0.48, 0.42, 0.54)
    colors[clr.FrameBgHovered]         = ImVec4(0.26, 0.98, 0.85, 0.40)
    colors[clr.FrameBgActive]          = ImVec4(0.26, 0.98, 0.85, 0.67)
    colors[clr.TitleBg]                = ImVec4(0.04, 0.04, 0.04, 1.00)
    colors[clr.TitleBgActive]          = ImVec4(0.16, 0.48, 0.42, 1.00)
    colors[clr.TitleBgCollapsed]       = ImVec4(0.00, 0.00, 0.00, 0.51)
    colors[clr.CheckMark]              = ImVec4(0.26, 0.98, 0.85, 1.00)
    colors[clr.SliderGrab]             = ImVec4(0.24, 0.88, 0.77, 1.00)
    colors[clr.SliderGrabActive]       = ImVec4(0.26, 0.98, 0.85, 1.00)
    colors[clr.Button]                 = ImVec4(0.26, 0.98, 0.85, 0.40)
    colors[clr.ButtonHovered]          = ImVec4(0.26, 0.98, 0.85, 1.00)
    colors[clr.ButtonActive]           = ImVec4(0.06, 0.98, 0.82, 1.00)
    colors[clr.Header]                 = ImVec4(0.26, 0.98, 0.85, 0.31)
    colors[clr.HeaderHovered]          = ImVec4(0.26, 0.98, 0.85, 0.80)
    colors[clr.HeaderActive]           = ImVec4(0.26, 0.98, 0.85, 1.00)
    colors[clr.Separator]              = ImVec4(0.43, 0.43, 0.50, 0.50)
    colors[clr.SeparatorHovered]       = ImVec4(0.10, 0.75, 0.63, 0.78)
    colors[clr.SeparatorActive]        = ImVec4(0.10, 0.75, 0.63, 1.00)
    colors[clr.ResizeGrip]             = ImVec4(0.26, 0.98, 0.85, 0.25)
    colors[clr.ResizeGripHovered]      = ImVec4(0.26, 0.98, 0.85, 0.67)
    colors[clr.ResizeGripActive]       = ImVec4(0.26, 0.98, 0.85, 0.95)
    colors[clr.PlotLines]              = ImVec4(0.61, 0.61, 0.61, 1.00)
    colors[clr.PlotLinesHovered]       = ImVec4(1.00, 0.81, 0.35, 1.00)
    colors[clr.TextSelectedBg]         = ImVec4(0.26, 0.98, 0.85, 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]                = ImVec4(0.08, 0.08, 0.08, 0.94)
    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.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

[ML] (error) MVD Helper.lua: D:\ARIZONA GAMES\bin\Arizona\moonloader\MVD Helper.lua:184: stack index 3, expected number, received number: not a numeric type or numeric string (bad argument into 'bool(const char*, ImValue<int>*, int, int, sol::optional<char const *>)')
stack traceback:
[C]: in function 'SliderInt'
D:\ARIZONA GAMES\bin\Arizona\moonloader\MVD Helper.lua:184: in function 'OnDrawFrame'
D:\ARIZONA GAMES\bin\Arizona\moonloader\lib\imgui.lua:1378: in function <D:\ARIZONA GAMES\bin\Arizona\moonloader\lib\imgui.lua:1367>
[ML] (error) MVD Helper.lua: Script died due to an error. (08A086F4)
 

CaJlaT

Овощ
Модератор
2,806
2,603

#Kai-

Известный
705
292
Где-то видел пример по работе с булевыми значениями в imgui, кто-то типо гайда делал, прошерстил форум не нашел.

Там было что булевые значения закрывали через цикл, типо:


Lua:
--Хуйня
bool = false
bool = false
bool = false
bool = false
bool = false
--Через цикл  с масивом правильно
local bool = {
....
}
Буду благодарен за ссылочку...
 

vegas

Известный
637
444
Где-то видел пример по работе с булевыми значениями в imgui, кто-то типо гайда делал, прошерстил форум не нашел.

Там было что булевые значения закрывали через цикл, типо:


Lua:
--Хуйня
bool = false
bool = false
bool = false
bool = false
bool = false
--Через цикл  с масивом правильно
local bool = {
....
}
Буду благодарен за ссылочку...
Если через цикл значит все булл значения находятся в массиве и через цикл for проходишь по всем значениям
 

#Kai-

Известный
705
292
Если через цикл значит все булл значения находятся в массиве и через цикл for проходишь по всем значениям
Я понимаю все это, мне нужен именно гайд. Это не отдельная тема, вроде в сообщении было от какого-то модератора.
 

dondesanta

Новичок
10
0
Есть вопрос, после того как меня спавнит с помощью sampSendRequestSpawn(), не убираются эти кнокпи, как пофиксить?
1619510446625.png
Сам код:
Код:
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
        _, myid = sampGetPlayerIdByCharHandle(PLAYER_PED)
        nickname = sampGetPlayerNickname(myid)
        sampRegisterChatCommand('free', cmd_free)
        sampRegisterChatCommand('pizdec', cmd_pizdec)
        thread = lua_thread.create_suspended(thread_pizdec)
            wait(4000)
            sampAddChatMessage(tag..'{FFFFFF}Готово!', main_color)
            sampSendRequestSpawn()
            sampSendSpawn()
end
 

saspepir

Участник
64
2
не может возобновить непостоянную сопрограмму
типо оно не может функцию запустить? Как это можно исправить? У меня эта ошибка указывает на строку thread = lua_thread.create(function()
 
Последнее редактирование:

Corrygаn

Участник
225
6
Как сделать второй окно imgui по кнопке в первом?
Код:
function imgui.OnDrawFrame()
    if main_window_state.v then
        imgui.Begin()
        if imgui.Button() then
            second_window_state().v = not second_window_state.v
            imgui.Process = second_window_state.v
        end
        imgui.End()
    end
    
    if second_window_state.v then
        imgui.Begin()
        imgui.End()
    end
end
Код сверху почему-то не работает, точнее он работает. но второе окно по кнопке не открывается.
 

HpP

Известный
368
117
Как сделать второй окно imgui по кнопке в первом?
Код:
function imgui.OnDrawFrame()
    if main_window_state.v then
        imgui.Begin()
        if imgui.Button() then
            second_window_state().v = not second_window_state.v
            imgui.Process = second_window_state.v
        end
        imgui.End()
    end
   
    if second_window_state.v then
        imgui.Begin()
        imgui.End()
    end
end
Код сверху почему-то не работает, точнее он работает. но второе окно по кнопке не открывается.

Lua:
function imgui.OnDrawFrame()
    if main_window_state.v then
        imgui.Begin()
        if imgui.Button('Open') then
            second_window_state.v = true
        end
        imgui.End()
    end
    
    if second_window_state.v then
        imgui.Begin()
        imgui.End()
    end
end
 

histor

Известный
175
111
Приветствую! У меня есть вопрос. Как мне в переменные например a, s, d, f записать числа 3, 4, 5, 6 из строки "Nick_Name| asd - 3, ssd- 4, dsd- 5, fsd - 6."