Не получается получить id игрока

555Maximka556

Новичок
Автор темы
10
0
Версия MoonLoader
.027.0-preview
Не получается получить ид игрока, уже и код менять пробовал, выдает такую ошибку:

[14:34:35.547455] (error) rvanka.lua: stack index 1, expected number, received nil: not a numeric type or numeric string (bad argument to native function)
stack traceback:
[C]: in function 'getCharCoordinates'
...d/0/Android/data/com.arizona.game/monetloader/rvanka.lua:29: in function <...d/0/Android/data/com.arizona.game/monetloader/rvanka.lua:19>
[14:34:35.547513] (error) rvanka.lua: Script died due to an er
ror.

Вот сам код:
Lua:
require "moonloader"
local encoding = require "encoding"
encoding.default = "CP1251"
u8 = encoding.UTF8
local imgui = require "mimgui"

local new = imgui.new
local renderWindow = new.bool()
local sizeX, sizeY = getScreenResolution()
local vkladka = 1

local onfrv = new.bool()
local incrv = new.bool()
local orslide = new.int(5)
local crslide = new.int(10)
local lineesp = new.bool(true)
local rvstatus = new.bool(true)

function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand("test", rvmenu)
    while true do
        if onfrv[0] then
            if lineesp[0] then
                local x,y,z = getCharCoordinates(PLAYER_PED)
                local playerid = getClosestPlayerId()
                local res, chel = sampGetCharHandleBySampPlayerId(playerid)
                local px,py,pz = getCharCoordinates(chel)
                local wx,wy = convert3DCoordsToScreen(x,y,z)
                local ex, ey = convert3DCoordsToScreen(px,py,pz)
                renderDrawLine(wx,wy,ex,ey, 4, 0x00FF00)
            end
        end
        wait(0)
    end
end

function rvmenu()
    renderWindow[0] = not renderWindow[0]
end

local newFrame = imgui.OnFrame(
    function() return renderWindow[0] end,
    function(player)
        imgui.SetNextWindowPos(imgui.ImVec2(sizeX / 2, sizeY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(485, 250), imgui.Cond.FirstUseEver)
        imgui.Begin("rvanka")
        imgui.Dummy(imgui.ImVec2(5, 5))
        imgui.Dummy(imgui.ImVec2(7, 0))
        imgui.SameLine()
        if imgui.Button(u8"Основное", imgui.ImVec2(200, 50)) then
            vkladka = 1
        end
        imgui.SameLine()
        imgui.Dummy(imgui.ImVec2(20, 0))
        imgui.SameLine()
        if imgui.Button(u8"Настройки", imgui.ImVec2(200, 50)) then
            vkladka = 2
        end
        imgui.Separator()
        if vkladka == 1 then
            imgui.Dummy(imgui.ImVec2(0, 5))
            imgui.Checkbox("Onfoot Rvanka", onfrv)
            imgui.SameLine()
            imgui.Dummy(imgui.ImVec2(15, 0))
            imgui.SameLine()
            imgui.Checkbox("InCar Rvanka", incrv)
            imgui.Text(u8"     Радиус")
            imgui.SameLine()
            imgui.Dummy(imgui.ImVec2(100, 0))
            imgui.SameLine()
            imgui.Text(u8"     Радиус")
            imgui.PushItemWidth(150)
            imgui.SliderInt(u8" ", orslide, 1, 30)
            imgui.SameLine()
            imgui.Dummy(imgui.ImVec2(57, 0))
            imgui.SameLine()
            imgui.SliderInt(u8"  ", crslide, 1, 30)
            imgui.PopItemWidth() 
        elseif vkladka == 2 then
            imgui.Dummy(imgui.ImVec2(0, 5))
            imgui.Checkbox(u8"Отображать цель", lineesp)
            imgui.SameLine()
            imgui.Dummy(imgui.ImVec2(20, 0))
            imgui.SameLine()
            imgui.Checkbox(u8"Статус", rvstatus)
        end
        imgui.End()
    end
)

function getClosestPlayerId()
    local closestId = -1
    mydist = 30
    local x, y, z = getCharCoordinates(PLAYER_PED)
    for i = 0, 999 do
        local streamed, pedID = sampGetCharHandleBySampPlayerId(i)
        if streamed and getCharHealth(pedID) > 0 and not sampIsPlayerPaused(pedID) then
            local xi, yi, zi = getCharCoordinates(pedID)
            local dist = getDistanceBetweenCoords3d(x, y, z, xi, yi, zi)
            if dist <= mydist then
                mydist = dist
                closestId = i
            end
        end
    end
    return closestId
end
 
  • Грустно
Реакции: qdIbp

qdIbp

Автор темы
Проверенный
1,386
1,141
Lua:
require("moonloader")
local imgui = require ("mimgui")
local encoding = require("encoding")
encoding.default = "CP1251"
u8 = encoding.UTF8

local new = imgui.new
local renderWindow = new.bool()
local sizeX, sizeY = getScreenResolution()
local vkladka = 1

local onfrv = new.bool()
local incrv = new.bool()
local orslide = new.int(5)
local crslide = new.int(10)
local lineesp = new.bool(true)
local rvstatus = new.bool(true)

function main()
    repeat wait(0) until isSampAvailable()
    sampRegisterChatCommand("test", function()
        renderWindow[0] = not renderWindow[0]
    end)
    while true do
        if onfrv[0] then
            if lineesp[0] then
                local x,y,z = getCharCoordinates(PLAYER_PED)
                local playerid = getClosestPlayerId()
                local chel = select(2,sampGetCharHandleBySampPlayerId(playerid)) -- select вытягивает 2 значение из функции, то есть сразу получаем хэндл без твоего res
                if doesCharExist(chel) then -- проверка на существование хендла, хотя у функции sampGetCharHandleBySampPlayerId, 1 значение это результат, 2 хэндл
                    local px, py, pz = getCharCoordinates(chel)
                    local wx, wy = convert3DCoordsToScreen(x, y, z)
                    local ex, ey = convert3DCoordsToScreen(px, py, pz)
                    if isCharOnScreen(chel) then -- проверка, видел ли ближайший к тебе пед, не то линия лезть куда не надо
                        renderDrawLine(wx, wy, ex, ey, 4.0, 0xFF00FF00)
                    end
                end
            end
        end
        wait(0)
    end
end

local newFrame = imgui.OnFrame(
    function() return renderWindow[0] end,
    function(player)
        imgui.SetNextWindowPos(imgui.ImVec2(sizeX / 2, sizeY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(485, 250), imgui.Cond.FirstUseEver)
        imgui.Begin("rvanka", renderWindow)
            imgui.Dummy(imgui.ImVec2(5, 5))
            imgui.Dummy(imgui.ImVec2(7, 0))
                imgui.SameLine()
            if imgui.Button(u8"Основное", imgui.ImVec2(200, 50)) then
                vkladka = 1
            end
                imgui.SameLine()
            imgui.Dummy(imgui.ImVec2(20, 0))
                imgui.SameLine()
            if imgui.Button(u8"Настройки", imgui.ImVec2(200, 50)) then
                vkladka = 2
            end
            imgui.Separator()
            if vkladka == 1 then
                imgui.Dummy(imgui.ImVec2(0, 5))
                imgui.Checkbox("Onfoot Rvanka", onfrv)
                    imgui.SameLine()
                imgui.Dummy(imgui.ImVec2(15, 0))
                    imgui.SameLine()
                imgui.Checkbox("InCar Rvanka", incrv)
                imgui.Text(u8"Радиус")
                    imgui.SameLine()
                imgui.Dummy(imgui.ImVec2(100, 0))
                    imgui.SameLine()
                imgui.Text(u8"\t\t\t\t  Радиус")
                imgui.PushItemWidth(150)
                imgui.SliderInt("##1", orslide, 1, 30)
                    imgui.SameLine()
                imgui.Dummy(imgui.ImVec2(57, 0))
                    imgui.SameLine()
                imgui.SliderInt("##2", crslide, 1, 30)
                imgui.PopItemWidth()
            elseif vkladka == 2 then
                imgui.Dummy(imgui.ImVec2(0, 5))
                imgui.Checkbox(u8"Отображать цель", lineesp)
                    imgui.SameLine()
                imgui.Dummy(imgui.ImVec2(20, 0))
                    imgui.SameLine()
                imgui.Checkbox(u8"Статус", rvstatus)
            end
        imgui.End()
    end
)

function getClosestPlayerId()
    local closestId, mydist  = -1, 30
    local x, y, z = getCharCoordinates(PLAYER_PED)
    for i = 0, 999 do
        local streamed, pedID = sampGetCharHandleBySampPlayerId(i)
        if streamed and getCharHealth(pedID) > 0 and not(sampIsPlayerPaused(pedID)) then
            local xi, yi, zi = getCharCoordinates(pedID)
            local dist = getDistanceBetweenCoords3d(x, y, z, xi, yi, zi)
            if dist <= mydist then
                closestId, mydist = i, dist
            end
        end
    end
    return closestId
end
 
  • Вау
Реакции: cord

555Maximka556

Новичок
Автор темы
10
0
Lua:
require("moonloader")
local imgui = require ("mimgui")
local encoding = require("encoding")
encoding.default = "CP1251"
u8 = encoding.UTF8

local new = imgui.new
local renderWindow = new.bool()
local sizeX, sizeY = getScreenResolution()
local vkladka = 1

local onfrv = new.bool()
local incrv = new.bool()
local orslide = new.int(5)
local crslide = new.int(10)
local lineesp = new.bool(true)
local rvstatus = new.bool(true)

function main()
    repeat wait(0) until isSampAvailable()
    sampRegisterChatCommand("test", function()
        renderWindow[0] = not renderWindow[0]
    end)
    while true do
        if onfrv[0] then
            if lineesp[0] then
                local x,y,z = getCharCoordinates(PLAYER_PED)
                local playerid = getClosestPlayerId()
                local chel = select(2,sampGetCharHandleBySampPlayerId(playerid)) -- select вытягивает 2 значение из функции, то есть сразу получаем хэндл без твоего res
                if doesCharExist(chel) then -- проверка на существование хендла, хотя у функции sampGetCharHandleBySampPlayerId, 1 значение это результат, 2 хэндл
                    local px, py, pz = getCharCoordinates(chel)
                    local wx, wy = convert3DCoordsToScreen(x, y, z)
                    local ex, ey = convert3DCoordsToScreen(px, py, pz)
                    if isCharOnScreen(chel) then -- проверка, видел ли ближайший к тебе пед, не то линия лезть куда не надо
                        renderDrawLine(wx, wy, ex, ey, 4.0, 0xFF00FF00)
                    end
                end
            end
        end
        wait(0)
    end
end

local newFrame = imgui.OnFrame(
    function() return renderWindow[0] end,
    function(player)
        imgui.SetNextWindowPos(imgui.ImVec2(sizeX / 2, sizeY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(485, 250), imgui.Cond.FirstUseEver)
        imgui.Begin("rvanka", renderWindow)
            imgui.Dummy(imgui.ImVec2(5, 5))
            imgui.Dummy(imgui.ImVec2(7, 0))
                imgui.SameLine()
            if imgui.Button(u8"Основное", imgui.ImVec2(200, 50)) then
                vkladka = 1
            end
                imgui.SameLine()
            imgui.Dummy(imgui.ImVec2(20, 0))
                imgui.SameLine()
            if imgui.Button(u8"Настройки", imgui.ImVec2(200, 50)) then
                vkladka = 2
            end
            imgui.Separator()
            if vkladka == 1 then
                imgui.Dummy(imgui.ImVec2(0, 5))
                imgui.Checkbox("Onfoot Rvanka", onfrv)
                    imgui.SameLine()
                imgui.Dummy(imgui.ImVec2(15, 0))
                    imgui.SameLine()
                imgui.Checkbox("InCar Rvanka", incrv)
                imgui.Text(u8"Радиус")
                    imgui.SameLine()
                imgui.Dummy(imgui.ImVec2(100, 0))
                    imgui.SameLine()
                imgui.Text(u8"\t\t\t\t  Радиус")
                imgui.PushItemWidth(150)
                imgui.SliderInt("##1", orslide, 1, 30)
                    imgui.SameLine()
                imgui.Dummy(imgui.ImVec2(57, 0))
                    imgui.SameLine()
                imgui.SliderInt("##2", crslide, 1, 30)
                imgui.PopItemWidth()
            elseif vkladka == 2 then
                imgui.Dummy(imgui.ImVec2(0, 5))
                imgui.Checkbox(u8"Отображать цель", lineesp)
                    imgui.SameLine()
                imgui.Dummy(imgui.ImVec2(20, 0))
                    imgui.SameLine()
                imgui.Checkbox(u8"Статус", rvstatus)
            end
        imgui.End()
    end
)

function getClosestPlayerId()
    local closestId, mydist  = -1, 30
    local x, y, z = getCharCoordinates(PLAYER_PED)
    for i = 0, 999 do
        local streamed, pedID = sampGetCharHandleBySampPlayerId(i)
        if streamed and getCharHealth(pedID) > 0 and not(sampIsPlayerPaused(pedID)) then
            local xi, yi, zi = getCharCoordinates(pedID)
            local dist = getDistanceBetweenCoords3d(x, y, z, xi, yi, zi)
            if dist <= mydist then
                closestId, mydist = i, dist
            end
        end
    end
    return closestId
end
rvanka.lua: stack index 1, expected number, received nil: not a numeric type or numeric string (bad argument to native function)
stack traceback:
[C]: in function 'doesCharExist'
...d/0/Android/data/com.arizona.game/monetloader/rvanka.lua:30: in function <...d/0/Android/data/com.arizona.game/monetloader/rvanka.lua:19>
[15:49:06.422116] (error) rvanka.lua: Script died due to an error.
 
  • Эм
Реакции: qdIbp

Maxim25012

Известный
279
101
Используй res. Первая переменная, возвращаемая функцией sampGetCharHandleBySampPlayerId, обозначает то, получилось ли получить хендл по айди или нет.
Lua:
if res then
    local px,py,pz = getCharCoordinates(chel)
    local wx,wy = convert3DCoordsToScreen(x,y,z)
    local ex, ey = convert3DCoordsToScreen(px,py,pz)
    renderDrawLine(wx,wy,ex,ey, 4, 0x00FF00)
end
 
  • Вау
Реакции: qdIbp

qdIbp

Автор темы
Проверенный
1,386
1,141
rvanka.lua: stack index 1, expected number, received nil: not a numeric type or numeric string (bad argument to native function)
stack traceback:
[C]: in function 'doesCharExist'
...d/0/Android/data/com.arizona.game/monetloader/rvanka.lua:30: in function <...d/0/Android/data/com.arizona.game/monetloader/rvanka.lua:19>
[15:49:06.422116] (error) rvanka.lua: Script died due to an error.
Lua:
require("moonloader")
local imgui = require ("mimgui")
local encoding = require("encoding")
encoding.default = "CP1251"
u8 = encoding.UTF8

local new = imgui.new
local renderWindow = new.bool()
local sizeX, sizeY = getScreenResolution()
local vkladka = 1

local onfrv = new.bool()
local incrv = new.bool()
local orslide = new.int(5)
local crslide = new.int(10)
local lineesp = new.bool(true)
local rvstatus = new.bool(true)

function main()
    repeat wait(0) until isSampAvailable()
    sampRegisterChatCommand("test", function()
        renderWindow[0] = not renderWindow[0]
    end)
    while true do
        if onfrv[0] then
            if lineesp[0] then
                local x,y,z = getCharCoordinates(PLAYER_PED)
                local playerid = getClosestPlayerId()
                local res, chel = sampGetCharHandleBySampPlayerId(playerid)
                if res then
                    local px, py, pz = getCharCoordinates(chel)
                    local wx, wy = convert3DCoordsToScreen(x, y, z)
                    local ex, ey = convert3DCoordsToScreen(px, py, pz)
                    if isCharOnScreen(chel) then -- проверка, видел ли ближайший к тебе пед, не то линия лезть куда не надо
                        renderDrawLine(wx, wy, ex, ey, 4.0, 0xFF00FF00)
                    end
                end
            end
        end
        wait(0)
    end
end

local newFrame = imgui.OnFrame(
    function() return renderWindow[0] end,
    function(player)
        imgui.SetNextWindowPos(imgui.ImVec2(sizeX / 2, sizeY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(485, 250), imgui.Cond.FirstUseEver)
        imgui.Begin("rvanka", renderWindow)
            imgui.Dummy(imgui.ImVec2(5, 5))
            imgui.Dummy(imgui.ImVec2(7, 0))
                imgui.SameLine()
            if imgui.Button(u8"Основное", imgui.ImVec2(200, 50)) then
                vkladka = 1
            end
                imgui.SameLine()
            imgui.Dummy(imgui.ImVec2(20, 0))
                imgui.SameLine()
            if imgui.Button(u8"Настройки", imgui.ImVec2(200, 50)) then
                vkladka = 2
            end
            imgui.Separator()
            if vkladka == 1 then
                imgui.Dummy(imgui.ImVec2(0, 5))
                imgui.Checkbox("Onfoot Rvanka", onfrv)
                    imgui.SameLine()
                imgui.Dummy(imgui.ImVec2(15, 0))
                    imgui.SameLine()
                imgui.Checkbox("InCar Rvanka", incrv)
                imgui.Text(u8"Радиус")
                    imgui.SameLine()
                imgui.Dummy(imgui.ImVec2(100, 0))
                    imgui.SameLine()
                imgui.Text(u8"\t\t\t\t  Радиус")
                imgui.PushItemWidth(150)
                imgui.SliderInt("##1", orslide, 1, 30)
                    imgui.SameLine()
                imgui.Dummy(imgui.ImVec2(57, 0))
                    imgui.SameLine()
                imgui.SliderInt("##2", crslide, 1, 30)
                imgui.PopItemWidth()
            elseif vkladka == 2 then
                imgui.Dummy(imgui.ImVec2(0, 5))
                imgui.Checkbox(u8"Отображать цель", lineesp)
                    imgui.SameLine()
                imgui.Dummy(imgui.ImVec2(20, 0))
                    imgui.SameLine()
                imgui.Checkbox(u8"Статус", rvstatus)
            end
        imgui.End()
    end
)

function getClosestPlayerId()
    local closestId, mydist  = -1, 30
    local x, y, z = getCharCoordinates(PLAYER_PED)
    for i = 0, 999 do
        local streamed, pedID = sampGetCharHandleBySampPlayerId(i)
        if streamed and getCharHealth(pedID) > 0 and not(sampIsPlayerPaused(pedID)) then
            local xi, yi, zi = getCharCoordinates(pedID)
            local dist = getDistanceBetweenCoords3d(x, y, z, xi, yi, zi)
            if dist <= mydist then
                closestId, mydist = i, dist
            end
        end
    end
    return closestId
end

Сибирские морозы дают своё :(