Имгуи

Seaside_

Участник
Автор темы
64
2
Версия MoonLoader
.026-beta
Как же вывести в окно имгуи ник и айди пользователя?
 
Решение
Там два параметра просто
Lua:
imgui = require 'imgui'
samp = require 'samp.events'
encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
active_menu = imgui.ImBool(false)
local main_window_state = imgui.ImBool(false)
sw,sh = getScreenResolution()

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('test', function() main_window_state.v = not main_window_state.v end)
    sampAddChatMessage('{FFCD0A}Test', -1)

    imgui.Process = false

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

function imgui.OnDrawFrame()...

Dmitriy Makarov

25.05.2021
Проверенный
2,478
1,113
Lua:
-- В самый верх, где local'ки
local playerid = -1
local main_window_state = imgui.ImBool(false) -- Твоё окно (Если есть своё - юзай его)

-- Бесконечный цикл
local valid, ped = getCharPlayerIsTargeting(PLAYER_HANDLE)
if valid and doesCharExist(ped) then
    local result, id = sampGetPlayerIdByCharHandle(ped)
    if result and isKeyJustPressed(VK_Q) then -- На ПКМ+Q
        main_window_state.v = not main_window_state.v
        playerid = id
    end
end


-- OnDrawFrame
-- if main_window_state.v then
imgui.Begin(u8"Взаимодействие с "..sampGetPlayerNickname(tostring(playerid)).."["..tostring(playerid).."]", main_window_state.v)
if imgui.Button(u8"Показать пасспорт") then
    sampSendChat("/pass "..tostring(playerid))
end
-- Если нужен NickName: sampGetPlayerNickname(tostring(playerid))
-- Если нужен NickName без _ : sampGetPlayerNickname(tostring(playerid)):gsub('_', ' ')
-- Если нужен ID: tostring(playerid)
 

Seaside_

Участник
Автор темы
64
2
Lua:
-- В самый верх, где local'ки
local playerid = -1
local main_window_state = imgui.ImBool(false) -- Твоё окно (Если есть своё - юзай его)

-- Бесконечный цикл
local valid, ped = getCharPlayerIsTargeting(PLAYER_HANDLE)
if valid and doesCharExist(ped) then
    local result, id = sampGetPlayerIdByCharHandle(ped)
    if result and isKeyJustPressed(VK_Q) then -- На ПКМ+Q
        main_window_state.v = not main_window_state.v
        playerid = id
    end
end


-- OnDrawFrame
-- if main_window_state.v then
imgui.Begin(u8"Взаимодействие с "..sampGetPlayerNickname(tostring(playerid)).."["..tostring(playerid).."]", main_window_state.v)
if imgui.Button(u8"Показать пасспорт") then
    sampSendChat("/pass "..tostring(playerid))
end
-- Если нужен NickName: sampGetPlayerNickname(tostring(playerid))
-- Если нужен NickName без _ : sampGetPlayerNickname(tostring(playerid)):gsub('_', ' ')
-- Если нужен ID: tostring(playerid)
Как в этот код вставить Nick и ID пользователя?

Lua:
imgui = require 'imgui'
samp = require 'samp.events'
encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
active_menu = imgui.ImBool(false)
local main_window_state = imgui.ImBool(false)

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('test', function() main_window_state.v = not main_window_state.v end)
    sampAddChatMessage('{FFCD0A}Test', -1)

    imgui.Process = false

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

function imgui.OnDrawFrame()
    imgui.SetNextWindowSize(imgui.ImVec2(500, 300), imgui.Cond.FirstUseEver)
    imgui.SetNextWindowPos(imgui.ImVec2((sw / 2), sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))

    imgui.LockPlayer = false
    imgui.Begin(u8'Test', main_window_state)
    imgui.SetCursorPosY(25)
    imgui.SetCursorPosX(50)
    imgui.Text(u8'TEst')
    imgui.Separator()
    imgui.Text(u8'Ваш ник-нэйм: ')  --Вот как сюда вставить чтобы показывался ник и ID пользователя?
    imgui.End()
end
 

Raymond

Известный
206
86
Lua:
imgui = require 'imgui'
samp = require 'samp.events'
encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
active_menu = imgui.ImBool(false)
local main_window_state = imgui.ImBool(false)

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('test', function() main_window_state.v = not main_window_state.v end)
    sampAddChatMessage('{FFCD0A}Test', -1)

    imgui.Process = false

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

function imgui.OnDrawFrame()
    imgui.SetNextWindowSize(imgui.ImVec2(500, 300), imgui.Cond.FirstUseEver)
    imgui.SetNextWindowPos(imgui.ImVec2((sw / 2), sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))

    imgui.LockPlayer = false
    imgui.Begin(u8'Test', main_window_state)
    imgui.SetCursorPosY(25)
    imgui.SetCursorPosX(50)
    imgui.Text(u8'TEst')
    imgui.Separator()
    imgui.Text(u8'Ваш ник-нэйм: '..sampGetPlayerNickname(sampGetPlayerIdByCharHandle(playerPed))..' ID: '..sampGetPlayerIdByCharHandle(playerPed))  --Вот как сюда вставить чтобы показывался ник и ID пользователя?
    imgui.End()
end
 

Seaside_

Участник
Автор темы
64
2
Lua:
imgui = require 'imgui'
samp = require 'samp.events'
encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
active_menu = imgui.ImBool(false)
local main_window_state = imgui.ImBool(false)

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('test', function() main_window_state.v = not main_window_state.v end)
    sampAddChatMessage('{FFCD0A}Test', -1)

    imgui.Process = false

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

function imgui.OnDrawFrame()
    imgui.SetNextWindowSize(imgui.ImVec2(500, 300), imgui.Cond.FirstUseEver)
    imgui.SetNextWindowPos(imgui.ImVec2((sw / 2), sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))

    imgui.LockPlayer = false
    imgui.Begin(u8'Test', main_window_state)
    imgui.SetCursorPosY(25)
    imgui.SetCursorPosX(50)
    imgui.Text(u8'TEst')
    imgui.Separator()
    imgui.Text(u8'Ваш ник-нэйм: '..sampGetPlayerNickname(sampGetPlayerIdByCharHandle(playerPed))..' ID: '..sampGetPlayerIdByCharHandle(playerPed))  --Вот как сюда вставить чтобы показывался ник и ID пользователя?
    imgui.End()
end
Ошибка Warning(s007): Exception 0xC0000005 at 0x59D1979B
 

niki4

Участник
92
10
Там два параметра просто
Lua:
imgui = require 'imgui'
samp = require 'samp.events'
encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
active_menu = imgui.ImBool(false)
local main_window_state = imgui.ImBool(false)
sw,sh = getScreenResolution()

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('test', function() main_window_state.v = not main_window_state.v end)
    sampAddChatMessage('{FFCD0A}Test', -1)

    imgui.Process = false

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

function imgui.OnDrawFrame()
    imgui.SetNextWindowSize(imgui.ImVec2(500, 300), imgui.Cond.FirstUseEver)
    imgui.SetNextWindowPos(imgui.ImVec2((sw / 2), sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))

    imgui.LockPlayer = false
    imgui.Begin(u8'Test', main_window_state)
    imgui.SetCursorPosY(25)
    imgui.SetCursorPosX(50)
    imgui.Text(u8'TEst')
    imgui.Separator()
    _,id = sampGetPlayerIdByCharHandle(playerPed)
    imgui.Text(u8('Ваш ник-нэйм: '.. sampGetPlayerNickname(id) ..' ID: '..tostring(id)))  --Вот как сюда вставить чтобы показывался ник и ID пользователя?
    imgui.End()
end