Change color of the name on player ped

Very interesting! Thank you!

It’s not functionnal… So, I suppose all head display don’t work (I try to makle a lot of test from few hour now, without any success…)

I’m not sure how else to disable them aside from removing the trainer. I had the idea of making my own name tags using GRAPHICS::GET_SCREEN_COORD_FROM_WORLD_COORD for getting players positions and translating it to a screen coordinate. Then using GRAPHICS::SET_DRAW_ORIGIN from the coordinate obtained from the last function to draw text just above their heads. I assume a check to see if the player is actually on screen would need to be done as well with ENTITY::IS_ENTITY_ON_SCREEN.

You could draw the text using NUI. This ( [Release] GUI Editor v0.2 [Updated 15 January 2017 (+7 UTC)] ) is pretty useful to get the text to your liking without constantly having to restart scripts after edits.

I haven’t done any testing, and it is just a theory of mine that this name tag idea would work. I have no idea if it would (or if it would even look good lol), but it might help you out.

Actually, a work on a team based game mode, and I looking for a solution to see what team the player you see is in. My first idea is to change the color of the name… but that look to be hard! So, I think about make a flag with head display function, but that not work to :confused:

My last idea is to draw a little marker on the player head (with DrawMarker) in the color of the team of the player…

Also, the trainer is not needed to have the player name over the head of the player… so, the trainer change nothing for this!

EDIT: draw marker solution work fine :wink:

Did you get GRAPHICS::GET_SCREEN_COORD_FROM_WORLD_COORD work? if yes, how?

I tried this: local x2d, y2d = World3dToScreen2d(streetOfTheDay[1], streetOfTheDay[2], streetOfTheDay[3])

But the x2d and y2d look to be bool value… I don’t understand…

[     82343] Error resuming coroutine: streetrun_cl.lua:27: attempt to perform arithmetic on a boolean value (local 'x')
[     82343] stack traceback:
[     82343] 	streetrun_cl.lua:27: in function 'drawTxt'
[     82343] 	streetrun_cl.lua:36: in function <streetrun_cl.lua:31>

Thanks

Yes and no. No, that function does not work. Yes, because I found another way to do it.

Use SetDrawOrigin(x, y, z, p3)
x y z being world coordinates. It will set 0, 0 (for your screen) to that position. p3 is unused, just put 0.

For example, if you type DrawAdvancedText(0.0, 0.0 … ) without SetDrawOrigin, it will draw in the top left of your screen.

If you use draworigin, and then draw the text with 0.0, 0.0, it will draw where the coords are in the world on your screen. Its hard for me to explain, but I hope you understand that.

Assuming you are using this in a loop, make sure you use ClearDrawOrigin() at the end of your loop, too. Otherwise it will be laggy and weird.

Thanks for the answer, I will perform some test :wink:

@nynjardin No problem. Any issues, let me know.

Well, I got the same error…

I Test this: local x2d, y2d = SetDrawOrigin(streetOfTheDay[1], streetOfTheDay[2], streetOfTheDay[3], 0)
and this local x2d, y2d = SetDrawOrigin(streetOfTheDay[1], streetOfTheDay[2], streetOfTheDay[3], 0)

No no… it doesn’t return a value. It sets where 0,0 is on your screen…

Just do SetDrawOrigin then drawtext with x and y of 0.0.

I can’t test right now, because of typhon in my region, I will test it tomorow afternoon, thank you for your help. But I just have to put SetDrawOrigin at the place of x and y with the x, y, z from my table ? Or if not, can you show me a simple exemple ?

Thank again

I drew a picture here in paint to hopefully try and better explain this. Pretend this box is your screen,

By default, the origin (x and y) of your screen is at the top left, where the green dot is.

Say the red shape is a car in your world (weird looking car). If you get the coordinates of that car and then set the origin to those world coordinates, your new screen origin (0.0 for x and y for the screen) will be on top of that car, where the blue dot inside the red shape is. If you get the coordinates for the brown shape, the origin will be there.

Here is a little code snippet for drawing a name on top of a player. You can put this in a loop to constantly get the location and pretty much make your own name tag.

local ppos = GetEntityCoords(GetPlayerPed(i)) SetDrawOrigin(ppos.x, ppos.y, ppos.z, 0) DrawAdvancedText(0.0, 0.0, 0.0, 0.0, 0.355, " "..GetPlayerName(i).." ", 0, 97, 255, 255, 4, 0) ClearDrawOrigin()

1 Like

Thank you for your draw :wink:

Well, I haven’t understood that, in fact, it’s hard to explain ! I will try when electricity become more stable to use computer ! Thank again !

like, what.

function DrawText3D(x,y,z) -- some useful function, use it if you want!
	local onScreen,_x,_y=World3dToScreen2d(x,y,z)
	local px,py,pz=table.unpack(GetGameplayCamCoords())
	local dist = GetDistanceBetweenCoords(px,py,pz, x,y,z, 1)
	
	local scale = (1/dist)*10
	local fov = (1/GetGameplayCamFov())*100
	local scale = scale*fov
	
	SetTextScale(0.0*scale, 0.55*scale)
	if onScreen then DrawText(_x,_y) end
end

just use this?
it’s easier, but is delayed by a few frames… your pick!

(Look below to find an updated version, do NOT use this function now)

2 Likes

Thank you, interesting, I will try it too as soon as possible !

Didn’t even know the function worked, like what aurum posted. I tried it a while ago and couldn’t get it working.

Anyway… the method I posted is pretty much the same thing, just a different way of doing it. It doesn’t have any lag with that way either.

Ok, I’ve tested both and I’ve got strange result in both case :stuck_out_tongue:

But the function DrawText3D() look more like I want because SetDrawOrigin() reforme text when it was at screen border… and I saw it at any distance… I should probably write a little function with scale like DrawText3D do to not see text from everywhere on the map :slight_smile:

Thank, both of you, that realy help me!

	local x,y,z = 0.0, 0.0, 72.0
	local px,py,pz=table.unpack(GetGameplayCamCoords())
	local dist = GetDistanceBetweenCoords(px,py,pz, x,y,z, 1)
	
	local scale = (1/dist)*20
	local fov = (1/GetGameplayCamFov())*100
	local scale = scale*fov
	
	SetTextScale(0.0*scale, 0.1*scale)
	
	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()
	SetTextEntry("STRING")
	SetTextCentre(1)
	AddTextComponentString("your text ma mane")
	SetDrawOrigin(x,y,z, 0)
	DrawText(0.0, 0.0)
        ClearDrawOrigin()

Basically a combination of the two. It has non-delayed text (which is very nice) and has very accurate scaling.

1 Like

Excellent! Exacly what I’m looking for! Thank you!

1 Like

Is there a way to stop rendering if view is obstructed (by wall for example)?