imgui

Infinqxw

Новичок
Автор темы
27
1
Закинул вх в imgui меню, все сделал, активирую чекбокс и скрипт оффается


Lua:
local whdist = imgui.ImBool(false) -- начало


function main()
    while not isSampAvailable() do wait(200) end

    sampRegisterChatCommand('rehelp', function()
        window.v = not window.v
    end)
  
    imgui.Process = true
    while true do

        wait(0)
        imgui.Process = window.v

if whdist.v then
    for id = 0, sampGetMaxPlayerId(true)
     do
        if sampIsPlayerConnected(id)
        then
            local exists, handle = sampGetCharHandleBySampPlayerId(id)
            if exists and doesCharExist(handle) then
            local oX,oY,oZ = getCharCoordinates(handle)
                if isPointOnScreen(oX, oY, oZ) then
                local pX, pY, pZ = getCharCoordinates(playerPed)
                local wpX, wpY = convert3DCoordsToScreen(pX, pY, pZ)
                local woX, woY = convert3DCoordsToScreen(oX, oY, oZ)
                local dist = string.format("%.1f", getDistanceBetweenCoords3d(pX, pY, pZ, oX, oY, oZ))     
                res, id = sampGetPlayerIdByCharHandle(handle)
                    if res then
                        renderFontDrawText(font, " Дистанция: " .. dist .. " метров.", woX, woY, -1)
                    end
                end
            end
        end
    end
end

    end
end


function imgui.OnDrawFrame()
    if window.v then
        local resX, resY = getScreenResolution()
        local sizeX, sizeY = 700, 500
        imgui.SetNextWindowPos(imgui.ImVec2(resX / 2 - sizeX / 2, resY / 2 - sizeY / 2), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowSize(imgui.ImVec2(sizeX, sizeY), imgui.Cond.FirstUseEver)
        imgui.Begin(fa.ICON_FA_LAPTOP .. ' -', window)
      
        imgui.Text('-')
        imgui.Text('Author - ')

        if imgui.Checkbox(u8"Дистанция к человеку", whdist) then
            whdist()
           end
           imgui.SameLine()
           imgui.Text('(?)')
           if imgui.IsItemHovered() then
               imgui.BeginTooltip()
               imgui.Text(u8'Позволяет увидеть дистанцию игрока к вам')
               imgui.EndTooltip()
           end


if whdist.v then
    for id = 0, sampGetMaxPlayerId(true)
     do
        if sampIsPlayerConnected(id)
        then
            local exists, handle = sampGetCharHandleBySampPlayerId(id)
            if exists and doesCharExist(handle) then
            local oX,oY,oZ = getCharCoordinates(handle)
                if isPointOnScreen(oX, oY, oZ) then
                local pX, pY, pZ = getCharCoordinates(playerPed)
                local wpX, wpY = convert3DCoordsToScreen(pX, pY, pZ)
                local woX, woY = convert3DCoordsToScreen(oX, oY, oZ)
                local dist = string.format("%.1f", getDistanceBetweenCoords3d(pX, pY, pZ, oX, oY, oZ))     
                res, id = sampGetPlayerIdByCharHandle(handle)
                    if res then
                        renderFontDrawText(font, " Дистанция: " .. dist .. " метров.", woX, woY, -1)
                    end
                end
            end
        end
    end
end
 

kyrtion

Известный
1,119
404
Lua:
local ffi = require('ffi')
local imgui = require('mimgui');
local new, str, sizeof, IV2 = imgui.new, ffi.string, ffi.sizeof, imgui.ImVec2;
local encoding = require('encoding');
encoding.default = 'CP1251';
local u8 = encoding.UTF8;
local fa -- ?

local window = new.bool(false)
local stateShowDistPlayer = new.bool(false)

local newFrame = imgui.OnFrame(function() return window[0] end, function()
    local resX, resY = getScreenResolution()
    local sizeX, sizeY = 700, 500
    imgui.SetNextWindowPos(imgui.ImVec2(resX / 2 - sizeX / 2, resY / 2 - sizeY / 2), imgui.Cond.FirstUseEver)
    imgui.SetNextWindowSize(imgui.ImVec2(sizeX, sizeY), imgui.Cond.FirstUseEver)
    imgui.Begin(fa.ICON_FA_LAPTOP .. ' -', window)

    imgui.Text('-')
    imgui.Text('Author - ')

    imgui.Checkbox(u8'Дистанция к человеку', stateShowDistPlayer)
    imgui.MarkQuestion('Позволяет увидеть дистанцию игрока к вам')

    imgui.End()
end)

local drawListFrame = imgui.OnFrame(function() return stateShowDistPlayer[0] end, function()
    local DL = imgui.GetBackgroundDrawList()

    for id = 0, sampGetMaxPlayerId(true) do
        if sampIsPlayerConnected(id) then
            local exists, ped = sampGetCharHandleBySampPlayerId(id)
            if exists then
                local pedPos = { getCharCoordinates(ped) }
                if isPointOnScreen(pedPos[1], pedPos[2], pedPos[3], _) then
                    local myPos = { getCharCoordinates(PLAYER_PED) }
                    local screenPos = { convert3DCoordsToScreen(pedPos[1], pedPos[2], pedPos[3]) }
                    local distText = string.format('Дистанция: %.1f метров.', getDistanceBetweenCoords3d(myPos[1], myPos[2], myPos[3], pedPos[1], pedPos[2], pedPos[3]))

                    DL:AddText(IV2(screenPos[1], screenPos[2]), -1, distText)
                end
            end
        end
    end
end)
drawListFrame.HideCursor = true

function main()
    while not isSampAvailable() do wait(200) end

    sampRegisterChatCommand('rehelp', function() window[0] = not window[0] end)
end


function imgui.MarkQuestion(comment)
    if not comment or #comment == 0 or type(comment) ~= 'string' then return end

    imgui.SameLine()
    imgui.TextDisabled('(?)')
    if imgui.IsItemHovered() then
        imgui.BeginTooltip()
        imgui.Text(u8(comment))
        imgui.EndTooltip()
    end
end
Писал в неудобном положении, если будут вопросы, задавай. Но и еще я не даю гарантию что этот код будет сработать
 
Последнее редактирование:
  • Нравится
Реакции: minxty

minxty

Известный
1,188
1,070
где обьявлена переменная window?
где обьявлена переменная font?
где функция whdist?
с первого раза даже не понял, что вх в цикле, а не вне меина
для чего ты и в цикл, и в имгуи окно засовываешь рендер? надо только в цикл
имгуи подключил?
fontawesome подключил?
encoding подключил?
u8 обьявил? (не факт, что я все ошибки перечислил)

тут по хорошему, переписать весь скрипт с нуля, и учить ЯП, api moonloader'a
 
  • Нравится
Реакции: kyrtion

Infinqxw

Новичок
Автор темы
27
1
где обьявлена переменная window?
где обьявлена переменная font?
где функция whdist?
с первого раза даже не понял, что вх в цикле, а не вне меина
для чего ты и в цикл, и в имгуи окно засовываешь рендер? надо только в цикл
имгуи подключил?
fontawesome подключил?
encoding подключил?
u8 обьявил? (не факт, что я все ошибки перечислил)

тут по хорошему, переписать весь скрипт с нуля, и учить ЯП, api moonloader'a
я учусь только, ничего особо не понимаю, только визуально рисовать умею имгуишки

Lua:
local ffi = require('ffi')
local imgui = require('mimgui');
local new, str, sizeof, IV2 = imgui.new, ffi.string, ffi.sizeof, imgui.ImVec2;
local encoding = require('encoding');
encoding.default = 'CP1251';
local u8 = encoding.UTF8;
local fa -- ?

local window = new.bool(false)
local stateShowDistPlayer = new.bool(false)

local newFrame = imgui.OnFrame(function() return window[0] end, function()
    local resX, resY = getScreenResolution()
    local sizeX, sizeY = 700, 500
    imgui.SetNextWindowPos(imgui.ImVec2(resX / 2 - sizeX / 2, resY / 2 - sizeY / 2), imgui.Cond.FirstUseEver)
    imgui.SetNextWindowSize(imgui.ImVec2(sizeX, sizeY), imgui.Cond.FirstUseEver)
    imgui.Begin(fa.ICON_FA_LAPTOP .. ' -', window)

    imgui.Text('-')
    imgui.Text('Author - ')

    imgui.Checkbox(u8'Дистанция к человеку', stateShowDistPlayer)
    imgui.MarkQuestion('Позволяет увидеть дистанцию игрока к вам')

    imgui.End()
end)

local drawListFrame = imgui.OnFrame(function() return stateShowDistPlayer[0] end, function()
    local DL = imgui.GetBackgroundDrawList()

    for id = 0, sampGetMaxPlayerId(true) do
        if sampIsPlayerConnected(id) then
            local exists, ped = sampGetCharHandleBySampPlayerId(id)
            if exists then
                local pedPos = { getCharCoordinates(ped) }
                if isPointOnScreen(pedPos[1], pedPos[2], pedPos[3], _) then
                    local myPos = { getCharCoordinates(PLAYER_PED) }
                    local screenPos = { convert3DCoordsToScreen(pedPos[1], pedPos[2], pedPos[3]) }
                    local distText = string.format('Дистанция: %.1f метров.', getDistanceBetweenCoords3d(myPos[1], myPos[2], myPos[3], pedPos[1], pedPos[2], pedPos[3]))

                    DL:AddText(IV2(screenPos[1], screenPos[2]), -1, distText)
                end
            end
        end
    end
end)
drawListFrame.HideCursor = true

function main()
    while not isSampAvailable() do wait(200) end

    sampRegisterChatCommand('rehelp', function() window[0] = not window[0] end)
end


function imgui.MarkQuestion(comment)
    if not comment or #comment == 0 or type(comment) ~= 'string' then return end

    imgui.SameLine()
    imgui.TextDisabled('(?)')
    if imgui.IsItemHovered() then
        imgui.BeginTooltip()
        imgui.Text(u8(comment))
        imgui.EndTooltip()
    end
end
Писал в неудобном положении, если будут вопросы, задавай. Но и еще я не даю гарантию что этот код будет сработать
В имгуишку нельзя закинуть ?

где обьявлена переменная window?
где обьявлена переменная font?
где функция whdist?
с первого раза даже не понял, что вх в цикле, а не вне меина
для чего ты и в цикл, и в имгуи окно засовываешь рендер? надо только в цикл
имгуи подключил?
fontawesome подключил?
encoding подключил?
u8 обьявил? (не факт, что я все ошибки перечислил)

тут по хорошему, переписать весь скрипт с нуля, и учить ЯП, api moonloader'a
Lua:
local imgui = require('imgui')
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
       
local window = imgui.ImBool(false)
show_main_window = imgui.ImBool(false)

local mem = require "memory"

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

local ffi = require "ffi"
local getBonePosition = ffi.cast("int (__thiscall*)(void*, float*, int, bool)", 0x5E4280)

local imgui = require 'imgui'
local vkeys = require 'vkeys'
local fa = require 'fAwesome5'
local event = require 'lib.samp.events'

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

Дальше

local rkeys = require 'rkeys'
imgui.HotKey = require('imgui_addons').HotKey

local tLastKeys = {}
local ActiveClockMenu = {
v = decodeJson("[18,82]")
}

Остальное переменные для чекбоксов