Draw text though the walls

Is there are any method how can I draw any text above the head though the walls? For example name and wanted level.

I’m not sure what you mean.

1 Like

Like on this screenshot. Check ‘RAID’ text. It displayed over any 3D objects. Is it possible to make same thing with text in gta?

1 Like

SetDrawOrigin?
http://runtime.fivem.net/doc/reference.html#_0xAA0008F3BBB8F416

1 Like

But how can I print any text? Can’t find correct function in natives becuase the only one function that I’ve found for text is a debug fuction which will not work in retail release.

You could use the normal draw natives with the _GET_SCREEN_COORD_FROM_WORLD_COORD native.

Edit: There’s even a gtaforum post about this very thing. I know it’s for a different game but, the concept/natives should be very similar.

Edit 2: You might also want to have a look at this code to get an idea on how to draw text in 3D space

1 Like

Thanks a lot. Will try it now.

No. When you draw to the HUD, it gets rendered last so, it should appear on top of all other elements. This includes walls. There’s no need to use HTML (you can if you want but, you could just as easily use natives).

How would I use the native in Lua

If you look at the page, the second comment has the Lua equivilent (GetScreenCoordFromWorldCoord). Bear in mind it has two pointer values in it so, it would return these. Example: local boolean, screenX, screenY = GetScreenCoordFromWorldCoord.

Understood how it works. Awesome. No lags and text displays at the correct position. Thanks a lot.

Do you know also how to draw text not though the walls? And how to check is object in player fov?

1 Like

shape test natives to check if the position isn’t colliding

IS_SPHERE_VISIBLE

1 Like

How to do that? And thx for IS_SPHERE_VISIBLE

http://runtime.fivem.net/doc/reference.html#_n_SHAPETEST

1 Like

Already found it. Thx a lot

Doesn’t work properly. It is very buggy. Sometimes it understand that entity is visible sometimes no. What’s wrong with my code?

			ped = GetPlayerPed(id)
                            x, y, z = table.unpack(GetEntityCoords(ped, true))
			x2, y2, z2 = table.unpack(GetEntityCoords(GetPlayerPed(-1), true))
			distance = GetDistanceBetweenCoords(x, y, z, x2, y2, z2, true)
			
			local ray = StartShapeTestRay(x2, y2, z2 + 10, x, y, z, -1, GetPlayerPed(-1), 7)
			local shit0, shit1, shit2, shit3, entity_hit = GetRaycastResult(ray)
			
			if entity_hit == ped then
				if distance < 51 then
					DrawName3D(x, y, z + 1.1, GetPlayerName(id))
					DrawName3D(x, y, z + 1, math.floor(distance) .. "m")
				end
			end

EDIT: Nvrm, fixed it by adding addition value to z.

function DrawText3DTest(x,y,z, text)
    local onScreen,_x,_y=World3dToScreen2d(x,y,z)
    local px,py,pz=table.unpack(GetGameplayCamCoords())
    
    if onScreen then
        SetTextScale(0.2, 0.2)
        SetTextFont(0)
        SetTextProportional(1)
        -- SetTextScale(0.0, 0.55)
        SetTextColour(255, 255, 255, 255)
        SetTextDropshadow(0, 0, 0, 0, 55)
        SetTextEdge(2, 0, 0, 0, 150)
        SetTextDropShadow()
        SetTextOutline()
        SetTextEntry("STRING")
        SetTextCentre(1)
        AddTextComponentString(text)
        DrawText(_x,_y)
    end
end


Citizen.CreateThread(function()
    while true do
        for i = 1, #objectlist do
            local objectCoords = GetEntityCoords( GetPlayerPed(-1) )
            local closechair = GetClosestObjectOfType(objectCoords.x, objectCoords.y, objectCoords.z, 1000.0, GetHashKey(objectlist[i]), false, false, false)
            local objectCoordsDraw = GetEntityCoords( closechair )
            DrawText3DTest(objectCoordsDraw.x, objectCoordsDraw.y, objectCoordsDraw.z + 1, "[E] to take a seat.")
        end
        Citizen.Wait(0)
    end
end)

objectlist = {
    [1] = 'prop_bench_01a',
    [2] = 'prop_bench_01b',
    [3] = 'prop_bench_01c',
    [4] = 'prop_bench_02',
    [5] = 'prop_bench_03',
    [6] = 'prop_bench_04',
    [7] = 'prop_bench_05',
    [8] = 'prop_bench_06',
    [9] = 'prop_bench_05',
    [10] = 'prop_bench_08',
    [11] = 'prop_bench_09',
    [12] = 'prop_bench_10',
    [13] = 'prop_bench_11'
}

This will find the closest object of all listed objects and display text to your choosing up to 1000.0 metres. You could also just add designated coords from a similar table if the objects are static and do them yourself.

2 Likes

World3dToScreen2d function sucks. It has lags when you are moving your camera.

Might be your CPU or something, never noticed problems with it.