Не корректно работает скрипт

MrCH

Участник
Автор темы
109
17
Версия SA-MP
  1. Любая
По задумке скрипт должен телепортироваться на определенную позицию, получать ид ближайшего пикапа, и дальше с ним работать. Для примера тут стоит сообщение в чат с id пикапа, но почему-то вместо нужного id он выводит -1
lua:
require 'lib.moonloader'
local samp =  require 'samp.events'

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand('clos', getClosestPlayerId)
    wait(-1)

end
function getClosestPlayerId()
    setCharCoordinates(PLAYER_PED, 2205.201171875, 2740.7944335938, 1500.9659423828)
    local closestId = -1
    mydist = 30
    local x, y, z = getCharCoordinates(PLAYER_PED)
    for i = 0, 5000 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
    sampSendChat(closestId)
end

По задумке скрипт должен телепортироваться на определенную позицию, получать ид ближайшего пикапа, и дальше с ним работать. Для примера тут стоит сообщение в чат с id пикапа, но почему-то вместо нужного id он выводит -1
lua:
require 'lib.moonloader'
local samp =  require 'samp.events'

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand('clos', getClosestPlayerId)
    wait(-1)

end
function getClosestPlayerId()
    setCharCoordinates(PLAYER_PED, 2205.201171875, 2740.7944335938, 1500.9659423828)
    local closestId = -1
    mydist = 30
    local x, y, z = getCharCoordinates(PLAYER_PED)
    for i = 0, 5000 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
    sampSendChat(closestId)
end
Up
 
Последнее редактирование: