- 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.
Вот сам код:
[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