koragg Posted December 25, 2016 Share Posted December 25, 2016 (edited) 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 December 25, 2016 by koragg Link to comment
koragg Posted December 26, 2016 Author Share Posted December 26, 2016 Here are two screenshots showing what the problem is: This is how it looks when I am spectating somebody : And this is how it looks when a player goes far away from me : 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
Addlibs Posted December 26, 2016 Share Posted December 26, 2016 (edited) [Deleted] Edited December 26, 2016 by MrTasty Link to comment
Rataj Posted December 26, 2016 Share Posted December 26, 2016 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) 1 Link to comment
koragg Posted December 26, 2016 Author Share Posted December 26, 2016 (edited) 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 --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 December 26, 2016 by koragg Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now