Jump to content

[HELP] Nametag nicks with colors and without colors


@RUSH

Recommended Posts

Hello everyone, i need help in script nametag - nickname with colors and without.

Prints: 

WITHOUT COLORS IN NICK

eHl5jXR.png

 

WITH COLORS IN NICK

7SR263p.png

 

Code: 

dxDrawBorderedText(getPlayerName(player), x - w / 2 + 35, y - h + 6, w, h, tocolor(255,255,255,255), scale, font, "left", "top", false, false, false, true, false)

 

Warning: I already used " :gsub("#%x%x%x%x%x%x", "")"  it and it did not work, I already changed the "left" and "top" to "center", "center", and also did not work, help, please

Edited by @RUSH
Link to comment
7 minutes ago, NeXuS™ said:

Can you give us your dxDrawBorderedText function?

function dxDrawBorderedText( text, x, y, w, h, color, scale, font, alignX, alignY, clip, wordBreak, postGUI )
	dxDrawText ( text:gsub('#%x%x%x%x%x%x', ''), x, y + 1, w + 1 , h , tocolor ( 0, 0, 0, 220 ), scale, font, alignX, alignY, clip, wordBreak, false )
	dxDrawText ( text, x, y, w, h, color, scale, font, alignX, alignY, clip, wordBreak, postGUI, true )
end

 

Link to comment

You can use Hexameter colorcodes in the string, for example:

dxDrawBorderedText("#F44242@#FFFFFF"..getPlayerName(player), x - w / 2 + 35, y - h + 6, w, h, tocolor(255,255,255,255), scale, font, "left", "top", false, false, false, true, false)

For the automatically change you can use a string variable to store the actually color code for the changing part:

local colorcode = "#F44242"
dxDrawBorderedText(colorcode.."@#FFFFFF"..getPlayerName(player), x - w / 2 + 35, y - h + 6, w, h, tocolor(255,255,255,255), scale, font, "left", "top", false, false, false, true, false)

And by change the value of 'colorcode' variable, you can do, want you want...

  • Thanks 1
Link to comment
10 minutes ago, Awang said:

Você pode usar os códigos de cores Hexameter na string, por exemplo:


            

Para a mudança automática, você pode usar uma variável de string para armazenar o código de cor realmente para a parte em mudança:


 
            

E pela mudança do valor do ' ColorCode ' variável, você pode fazer, o que quer ...

Yes, but as a nametag, the intention is to always leave the nicks on top of the player, with or without colors in the nicks

 

OBS: @RUSH is my nickname, no code :C

Edited by @RUSH
Link to comment

I see... Then you need to split the characters which you want to be colored and go ahead with hexameter colors.
For the nametag, you should do a trick with the getScreenFromWorldPosition() wich can help you to calculate screen position from World postion and make a feel that is in the 3D world, but actually, its not....

Edited by Awang
  • Thanks 1
Link to comment
39 minutes ago, Awang said:

I see... Then you need to split the characters which you want to be colored and go ahead with hexameter colors.
For the nametag, you should do a trick with the getScreenFromWorldPosition() wich can help you to calculate screen position from World postion and make a feel that is in the 3D world, but actually, its not....

A year ago I had this same problem and I solved it with a gsub, but now, 1 year later, I no longer have the old resource and with gsub I can not solve it, am I doing it right or has the MTA updated and disabled this option? Does not the problem have a simpler solution?

 

Would you like me to disable in the nametag the colors and show only the nick of the white player even if he has the colors and so leave the code centralized?

Edited by @RUSH
Link to comment

You can split the string with the basic Lua function, call string.sub().

Quote

string.sub (s, i [, j])

Returns the substring of s that starts at i and continues until j; i and j can be negative. If j is absent, then it is assumed to be equal to -1 (which is the same as the string length). In particular, the call string.sub(s,1,j) returns a prefix of s with length j, and string.sub(s, -i) returns a suffix of s with length i.


If I were you, I store the colored name in an elementData, and if the localPlayer set able to see the colors, I used the strings from the elementData, otherway the strings from getPlayerName() function.

And if there is a colorcoded nickname, you can use this:

function removeHex( s ) 
    return s:gsub( '#%x%x%x%x%x%x', '' ) or s 
end 
Edited by Awang
  • Thanks 1
Link to comment
10 minutes ago, Awang said:

You can split the string with the basic Lua function, call string.sub().


If I were you, I store the colored name in an elementData, and if the localPlayer set able to see the colors, I used the strings from the elementData, otherway the strings from getPlayerName() function.

And if there is a colorcoded nickname, you can use this:


function removeHex( s ) 
    return s:gsub( '#%x%x%x%x%x%x', '' ) or s 
end 

the result was the same, but this time only white, but the wrong positions
 view; 

XrlMLsg.png

qNs3F9C.png

Link to comment
1 minute ago, NeXuS™ said:

Você está tentando alcançar que as cores não são mostradas na marca de nome enquanto está acima da cabeça do jogador?

Yes, if there is no color and no color solution the nick stays in the center and only white stays in the center, it can be.

Link to comment
function dxDrawBorderedText( text, x, y, w, h, color, scale, font, alignX, alignY, clip, wordBreak, postGUI )
	dxDrawText ( text:gsub('#%x%x%x%x%x%x', ''), x, y + 1, w + 1 , h , tocolor ( 0, 0, 0, 220 ), scale, font, alignX, alignY, clip, wordBreak, false )
	dxDrawText ( text, x, y, w, h, color, scale, font, alignX, alignY, clip, wordBreak, postGUI, true )
end

function renderName()
	local pX, pY, pZ = getElementPosition(localPlayer)
	local wX, wY = getScreenFromWorldPosition(pX, pY, pZ+1)
	local playerNick = getPlayerName(localPlayer):gsub("#%x%x%x%x%x%x", "")
	dxDrawBorderedText(playerNick, wX, wY, wX, wY, tocolor(255, 255, 255, 255), 1, "default", "center", "top", false, false, false, true, false)
end
addEventHandler("onClientRender", root, renderName)

This works totally fine for me.

Edited by NeXuS™
  • Thanks 1
Link to comment
8 minutes ago, NeXuS™ said:

function dxDrawBorderedText( text, x, y, w, h, color, scale, font, alignX, alignY, clip, wordBreak, postGUI )
	dxDrawText ( text:gsub('#%x%x%x%x%x%x', ''), x, y + 1, w + 1 , h , tocolor ( 0, 0, 0, 220 ), scale, font, alignX, alignY, clip, wordBreak, false )
	dxDrawText ( text, x, y, w, h, color, scale, font, alignX, alignY, clip, wordBreak, postGUI, true )
end

function renderName()
	local pX, pY, pZ = getElementPosition(localPlayer)
	local wX, wY = getScreenFromWorldPosition(pX, pY, pZ+1)
	local playerNick = getPlayerName(localPlayer):gsub("#%x%x%x%x%x%x%x", "")
	dxDrawBorderedText(playerNick, wX, wY, wX, wY, tocolor(255, 255, 255, 255), 1, "default", "center", "top", false, false, false, true, false)
end
addEventHandler("onClientRender", root, renderName)

This works totally fine for me.

Its work :D:D:D

Thankyou soo much bro, ;)

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...