Как сделать нормальный рендеринг текста

demonvir

Участник
Автор темы
27
3
Версия MoonLoader
.026-beta
Пытался сделать так, чтобы рендер текста вёл себя адекватно, не наслаивался и выглядел как обычный текст над головой игрока, но так и не понял, как это сделать. Либо я плохо гуглю, либо действительно очень мало информации, связанной с этой темой. Единственное, насколько я правильно понял, чтобы текст не двигался при движении камеры, нужно сделать компенсацию (могу ошибаться).

Lua:
function renderPlayerRanks()
    if hideranks[0] then return end
    for id, rank in pairs(rankLabels) do
        if sampIsPlayerConnected(id) then
            local exists, ped = sampGetCharHandleBySampPlayerId(id)
            if exists and doesCharExist(ped) then
                local px, py, pz = getCharCoordinates(ped)
                if isPointOnScreen(px, py, pz, 0) then
                    local cx, cy, cz = getActiveCameraCoordinates()
                    if isLineOfSightClear(
                            cx, cy, cz,
                            px, py, pz + 0.8,
                            true,
                            false,
                            false,
                            true,
                            false,
                            false,
                            false,
                            false
                        ) then
                        local dist = getDistanceBetweenCoords3d(
                            cx, cy, cz,
                            px, py, pz
                        )
                        if dist <= 30.0 then
                            local sx, sy = convert3DCoordsToScreen(
                                px,
                                py,
                                pz + 1.0
                            )
                            local finalY = sy - 55
                            if afkRenderState[id] then
                                if afkLastSeen[id] and os.clock() - afkLastSeen[id] > 1.5 then
                                    afkRenderState[id] = nil
                                    afkLastSeen[id] = nil
                                end
                            end
                            if afkRenderState[id] then
                                finalY = finalY - 70
                            end
                            if sy > 0 and finalY > 0 then
                                local len = renderGetFontDrawTextLength(rankFont, rank)
                                renderFontDrawText(
                                    rankFont,
                                    rank,
                                    sx - (len / 2),
                                    finalY,
                                    0xFFFFFFFF
                                )
                            end
                        end
                    end
                end
            end
        end
    end
end
 

Lokapon

Участник
55
28
Код:
function renderPlayerRanks()
    if hideranks[0] then return end
    local cx, cy, cz = getActiveCameraCoordinates()
    for id, rank in pairs(rankLabels) do
        if sampIsPlayerConnected(id) then
            local exists, ped = sampGetCharHandleBySampPlayerId(id)
            if exists and doesCharExist(ped) then
                local px, py, pz = getCharCoordinates(ped)
                local dist = getDistanceBetweenCoords3d(cx, cy, cz, px, py, pz)
                if dist <= 30.0 and isPointOnScreen(px, py, pz, 0) then
                    local zOffset = 1.1 + (dist * 0.015)
                    if isLineOfSightClear(cx, cy, cz, px, py, pz + zOffset, true, false, false, true, false, false, false, false) then
                        local sx, sy = convert3DCoordsToScreen(px, py, pz + zOffset)
                        local textWidth = renderGetFontTextWidth(myFont, rank)
                        local finalX = sx - (textWidth / 2)
                        local finalY = sy - (30 / (dist * 0.1))
                        if finalY > sy then finalY = sy - 15 end
                        
                        renderFontDrawText(myFont, rank, finalX, finalY, 0xFFFFFFFF)
                        
                        if afkRenderState[id] then
                            if afkLastSeen[id] and os.clock() - afkLastSeen[id] > 1.5 then
                                afkRenderState[id] = nil
                                afkLastSeen[id] = nil
                            end
                        end
                    end
                end
            end
        end
    end
end

Так попробуй