Jump to content

nametags + flags


koragg

Recommended Posts

Hey guys, I added player rank and flag in nametags.lua and it works except one annoying part. The flag image does not go along with the text of the nametag. What I mean is that when a player goes far away from you his nametag changes it's size and position. Well the flag doesn't and is left floating in air somewhere next to the player (which looks ugly).

My question is, how to make the flag move in the same places as the text so they look like one thing, not seperate drawings.

--Draw our text
		    local nickLength = dxGetTextWidth( getPlayerName(player):gsub( '#%x%x%x%x%x%x', '' ), textscale*NAMETAG_TEXTSIZE/100*7, font)
                    local nickHeight = dxGetFontHeight( textscale*NAMETAG_TEXTSIZE/100*6.5, font)
                    local offset = (scale) * NAMETAG_TEXT_BAR_SPACE/2
		    local offset2 = (scale) * 0
                    local offset3 = (scale) * 3
		    local rank = getElementData(player, "race rank")..""..getPrefix(getElementData(player, "race rank"))
                    local flag = ":admin/client/images/flags/" .. (getElementData(player, "countryid") or "gtasa") .. ".png"
                    local FLAG_SIZE_X = 13
                    local FLAG_SIZE_Y = 9
                    local flagLength = textscale*FLAG_SIZE_X
                    local flagHeight = textscale*FLAG_SIZE_Y
                    local rankLength = dxGetTextWidth( rank, textscale*NAMETAG_TEXTSIZE/100*7, font)
					
					-- Edit #1 Colour nicknames
					if not bOnlyHealthBar then
						if not enableCustomNametags then
							dxDrawText(getPlayerNameColored(player), sx, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), textscale*NAMETAG_TEXTSIZE, "default", "center", "bottom", false, false, false, true)
						elseif enableCustomNametags then
							dxDrawText(rank.." "..getPlayerNameColored(player):gsub( '#%x%x%x%x%x%x', '' ), sx-69, sy-offset+1, sx+1, sy-offset-4, tocolor(0, 0, 0, textalpha), textscale*NAMETAG_TEXTSIZE/100*7, font, "center", "bottom", false, false, false, true, true)
							dxDrawText("#00FFFF"..rank.." "..getPlayerNameColored(player), sx-70, sy-offset, sx, sy-offset-5, tocolor(255, 255, 255, textalpha), textscale*NAMETAG_TEXTSIZE/100*7, font, "center", "bottom", false, false, false, true, true)
							dxDrawImage(sx+(nickLength/2)+offset3, (sy-offset)-(nickHeight+offset2), flagLength, flagHeight, flag)
						end
					end

 

Edited by koragg
Link to comment

Here are two screenshots showing what the problem is:

This is how it looks when I am spectating somebody : nLPDInG.png

And this is how it looks when a player goes far away from me :

ueUMGX4.png

Notice how in the second picture the flag is just floating somewhere near the player? That's my problem. How to make it attached to the rank and nickname text so that it always looks like on the first picture (both while spectating and while the player goes far away from me)?

Link to comment

Maybe do some more calculation around text width, etc..

Or take a look at dxCreateRenderTarget. You can create one render target (including nametag and flag), then you'll only calculate and draw that render target as one dx element, so there will be no problems like this and you can easily add new things into this render target whenever you want.

(There may be an easier way to do this, but this is best solution I can think of right now)

  • Like 1
Link to comment

I think I fixed it with the following code. Only the flag's Y position gets sliiiiiiiiightly low when another player is on a higher surface than you and is a bit far away from you but that's a really minor thing which only I see probably xD

		    --Draw our text
		    local nickLength = dxGetTextWidth( getPlayerName(player), textscale*NAMETAG_TEXTSIZE/100*7, font)
                    local nickHeight = dxGetFontHeight( textscale*NAMETAG_TEXTSIZE/100*6.5, font)
                    local offset = (scale) * NAMETAG_TEXT_BAR_SPACE/2
		    local offset2 = (scale) * 0
                    local offset3 = (scale) * 1.8
		    local rank = getElementData(player, "race rank")..""..getPrefix(getElementData(player, "race rank"))
                    local flag = ":admin/client/images/flags/" .. (getElementData(player, "countryid") or "gtasa") .. ".png"
                    local FLAG_SIZE_X = 13
                    local FLAG_SIZE_Y = 9
                    local flagLength = textscale*FLAG_SIZE_X
                    local flagHeight = textscale*FLAG_SIZE_Y
                    local rankLength = dxGetTextWidth( rank, textscale*NAMETAG_TEXTSIZE/100*7, font)
					
					-- Edit #1 Colour nicknames
					if not bOnlyHealthBar then
						if not enableCustomNametags then
							dxDrawText(getPlayerNameColored(player), sx, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), textscale*NAMETAG_TEXTSIZE, "default", "center", "bottom", false, false, false, true)
						elseif enableCustomNametags then
							dxDrawText(rank, sx-(nickLength/2)-rankLength-offset3+1, sy - offset+1, sx+1, sy - offset-4, tocolor(0, 0, 0, textalpha), textscale*NAMETAG_TEXTSIZE/100*7, font, "left", "bottom", false, false, false)
							dxDrawText(getPlayerNameColored(player):gsub( '#%x%x%x%x%x%x', '' ), sx+1, sy-offset+1, sx+1, sy-offset-4, tocolor(0, 0, 0, textalpha), textscale*NAMETAG_TEXTSIZE/100*7, font, "center", "bottom", false, false, false, true, true)
							
							dxDrawText(rank, sx-(nickLength/2)-rankLength-offset3, sy - offset, sx, sy - offset-5, tocolor(0, 255, 255, textalpha), textscale*NAMETAG_TEXTSIZE/100*7, font, "left", "bottom", false, false, false)
							dxDrawText(getPlayerNameColored(player), sx, sy-offset, sx, sy-offset-5, tocolor(255, 255, 255, textalpha), textscale*NAMETAG_TEXTSIZE/100*7, font, "center", "bottom", false, false, false, true, true)
							
							dxDrawImage(sx+(nickLength/2)+offset3, (sy-offset)-(nickHeight+offset2), flagLength, flagHeight, flag)
						end
					end

 

Edited by koragg
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...