DrawText position fix

I want to have static scale of text but when I am too far or too cloose to target position becomes wrong. Is there are any ways how to fix it?

  1. Looks normal
    https://i.imgur.com/D2DCE75.jpg

  2. Text overlays on each other
    https://i.imgur.com/jrBJ9lB.jpg

  3. Too big spaces when I am close to target
    https://i.imgur.com/CD9EH7K.jpg

How I am drawing text:

x, y, z = table.unpack(GetEntityCoords(ped, true))
DrawName3D(x, y, z + 1.30, GetPlayerName(id))

function DrawName3D(x,y,z, text) -- some useful function, use it if you want!
    SetDrawOrigin(x, y, z, 0);
	SetTextFont(0)
	SetTextProportional(0)
	SetTextScale(0.0, 0.23)
	SetTextColour(19, 232, 46, 240)
	SetTextDropshadow(0, 0, 0, 0, 255)
	SetTextEdge(2, 0, 0, 0, 150)
	SetTextDropShadow()
	SetTextOutline()
	SetTextEntry("STRING")
	SetTextCentre(1)
	AddTextComponentString(text)
	DrawText(0.0, 0.0)
	ClearDrawOrigin()
end
1 Like

That isnt how you are drawing text, the function must be called twice to show the distance. Its a whole lot easier to fix something if all the code is shown.

You took code from a pastebin without understanding it.

Look at the code again (the original one) and look at where/how it sets the scale. It does this based on distance (and so should you).

I know about Scale but I don’t want to change it. I want to keep same size on any distance.

What another part of code do you want? I given a part where text draws. Another part of code doesn’t affect on text. This code is looped. That how distance updates.

Ok so, don’t use the Draw3D method then as it draws into 3D space. Instead, use the world to screen native that I mentioned to place the text above the player keeping it the same size.

Otherwise, you’ll have to do some math to scale the text up the further away the player is and make it smaller they are. Giving the illusion that it stays the same size.

World to screen func lags that’s why I am asking about Draw3D. Could you tell me how to make correct scale? To make the illusion that it text still has same size?

1 Like

You know how as you get closer to an object it gets bigger and, the further away you go the smaller it gets? Basically you want to null-ify this. So, it doesn’t “get bigger” or “smaller” but, stays the same size. I don’t know how exactly you would do this but, it would probably be some sort of multiplication. All I know is you will need to use the distance.

That’s what I am talking about. I don’t know how to calculate it.

Hm… Just had a play around with the natives and you don’t need to do anything…

function DrawText3D(x,y,z, text) -- some useful function, use it if you want!
    local onScreen,_x,_y= World3dToScreen2d(x,y,z)
		
    if onScreen then
		BeginTextCommandDisplayText("STRING")
        
		SetTextScale(0.0, 0.55)
        SetTextFont(0)
        SetTextProportional(1)
        -- SetTextScale(0.0, 0.55)
        SetTextColour(255, 255, 255, 255)
        SetTextDropshadow(0, 0, 0, 0, 255)
        SetTextEdge(2, 0, 0, 0, 150)
        SetTextDropShadow()
        SetTextOutline()
        
        SetTextCentre(1)
        AddTextComponentString(text)
        EndTextCommandDisplayText(_x,_y)
    end
end

Works.

http://tgrhavoc.me/fuck_you/seriously/11-938855f7a74500e61882bda8e.mp4

I’ve even got yours to work:

function DrawText3D(x,y,z, text) -- some useful function, use it if you want!
    SetDrawOrigin(x, y, z, 0);
	SetTextFont(0)
	SetTextProportional(0)
	SetTextScale(0.0, 0.53)
	SetTextColour(19, 232, 46, 240)
	SetTextDropshadow(0, 0, 0, 0, 255)
	SetTextEdge(2, 0, 0, 0, 150)
	SetTextDropShadow()
	SetTextOutline()
	SetTextEntry("STRING")
	SetTextCentre(1)
	AddTextComponentString(text)
	DrawText(0.0, 0.0)
	ClearDrawOrigin()
end

Which results in:

http://tgrhavoc.me/fuck_you/seriously/11-456865be4f015be9998db31e5.mp4

So, how you’re having issues is beyond me :confused:

Try just having a normal Z coord, adding 0.5 and 1.5 to the Z. For the bottom text and top text respectively. It’s not the natives that are at fault, it looks like the values you’re passing.

1 Like

Are you really can’t see lags of white ‘This is test’ text when you are moving camera? And code with SerDrawOrigin was working already. Pls check screenshots to see my issue.

It’s not that noticeable. And, AFAIK, that’s the only way to get the effect you want cleanly. Also, doesn’t the player’s name (In GTA:O) “lag” like you say? If so, then they’re probably using this method (or a derivative of). And, if R* are using it, it’s probably the best method of doing it.

If not, then maybe you can make the Z coord on the bottom text lower (based on distance) to maintain its “distance” from the top text.

If you want to draw 2 lines with SET_DRAW_ORIGIN, simply set END_TEXT_COMMAND_DISPLAY_TEXT (or _DRAW_TEXT in ancient wrong natives) Y coordinate to be different the second time, don’t try to draw multiple lines of text by altering the Z as this won’t work because of perspective (as you can see, SET_DRAW_ORIGIN does not scale the size, so that is not the issue here). It wouldn’t work with ‘world-to-screen’ methods either, by the way, so this is no reason to recommend using this horrible method instead.

As you can see in the SET_DRAW_ORIGIN documentation, it moves 0.0, 0.0 to be the specified world coordinate, so if you want to draw 2 lines, simply do not draw at 0.0, 0.0, but draw at, say, 0.0, 0.02 or whatever text size you use.

People blindly copy-pasting snippets like stringsplit and these text drawing snippets cause constant issues and bad experience on servers, please take the time to understand what a snippet you are using does before using it!

Names from GTA: O uses own native. I can’t use it because I am not able to create multiple lines of text with it. Only components from this function. And yes it doesn’t have any lags.

Ubderstood what do you mean. Thx a lot this advice very usefull. Now lines doesn’t overlays each other but I still have one problem. My lines not linked to head of ped. When I move away from target all my lines slides lower and lower. How can I calculate correct Z value for SET_DRAW_ORIGIN when my distance changes? Let me know if you need video/code.

try drawing the lines further up in 2d space, not down

I am not drawing anything down. I am drawing text at ped position.