координаты ближайшего 3д текста

shitcodes

Известный
Автор темы
1,430
658
Версия MoonLoader
.026-beta
как получить координаты ближайшего к игру 3д текста с определенным текстом?
если, к примеру, в зоне стрима есть много 3д текстов с текстом "текст", и нужно получить координаты именно того, который находится ближе всех к игроку
 
Решение
Lua:
local array = {}

local function GetNearest3DText(search)
    for i = 0, 2049 do
        if sampIs3dTextDefined(i) then
            local text, color, x, y, z, distance, ignoreWalls, playerId, vehicleId = sampGet3dTextInfoById(i)
            local myX, myY, myZ = getCharCoordinates(PLAYER_PED)
            local distance = getDistanceBetweenCoords3d(myX, myY, myZ, x, y, z)

            if text:find(search) then
                table.insert(array, {['text'] = text, ['position'] = {x, y, z}, ['distance'] = distance})
            end
        end
    end

    if #array >= 1 then
        table.sort( array, function(a, b) return (a.distance < b.distance) end)
        return true, array[1].text, array[1].position, array[1].distance
    end...

EclipsedFlow

Известный
Проверенный
1,040
464
Lua:
local array = {}

local function GetNearest3DText(search)
    for i = 0, 2049 do
        if sampIs3dTextDefined(i) then
            local text, color, x, y, z, distance, ignoreWalls, playerId, vehicleId = sampGet3dTextInfoById(i)
            local myX, myY, myZ = getCharCoordinates(PLAYER_PED)
            local distance = getDistanceBetweenCoords3d(myX, myY, myZ, x, y, z)

            if text:find(search) then
                table.insert(array, {['text'] = text, ['position'] = {x, y, z}, ['distance'] = distance})
            end
        end
    end

    if #array >= 1 then
        table.sort( array, function(a, b) return (a.distance < b.distance) end)
        return true, array[1].text, array[1].position, array[1].distance
    end
    return false
end

local result, text, position, distance = GetNearest3DText('Привет') -- Поиск ближайшего 3д-текста с текстом 'Привет'

if result then
    print(text)
    print(position[1]) -- x
    print(position[2]) -- y
    print(position[3]) -- z
    print(distance)
end
 
  • Влюблен
Реакции: shitcodes