@RUSH Posted January 30, 2018 Share Posted January 30, 2018 (edited) Hello everyone, i need help in script nametag - nickname with colors and without. Prints: WITHOUT COLORS IN NICK WITH COLORS IN NICK 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 January 30, 2018 by @RUSH Link to comment
NeXuS™ Posted January 30, 2018 Share Posted January 30, 2018 Can you give us your dxDrawBorderedText function? 1 Link to comment
@RUSH Posted January 30, 2018 Author Share Posted January 30, 2018 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
@RUSH Posted January 30, 2018 Author Share Posted January 30, 2018 Up - help-me please Link to comment
Awang Posted January 30, 2018 Share Posted January 30, 2018 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... 1 Link to comment
@RUSH Posted January 30, 2018 Author Share Posted January 30, 2018 (edited) 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 January 30, 2018 by @RUSH Link to comment
Awang Posted January 30, 2018 Share Posted January 30, 2018 (edited) 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 January 30, 2018 by Awang 1 Link to comment
@RUSH Posted January 30, 2018 Author Share Posted January 30, 2018 (edited) 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 January 30, 2018 by @RUSH Link to comment
Awang Posted January 30, 2018 Share Posted January 30, 2018 (edited) 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 January 30, 2018 by Awang 1 Link to comment
@RUSH Posted January 30, 2018 Author Share Posted January 30, 2018 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; Link to comment
NeXuS™ Posted January 30, 2018 Share Posted January 30, 2018 Are you trying to achieve that colors are not shown in the nametag while it is above the player's head? 1 Link to comment
@RUSH Posted January 30, 2018 Author Share Posted January 30, 2018 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
NeXuS™ Posted January 30, 2018 Share Posted January 30, 2018 (edited) 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 January 30, 2018 by NeXuS™ 1 Link to comment
@RUSH Posted January 30, 2018 Author Share Posted January 30, 2018 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 Thankyou soo much bro, Link to comment
Slim Posted January 31, 2018 Share Posted January 31, 2018 If I'm not mistaken, the part I made bold and highlighted is how you control if colors are enabled in DX or not.tocolor(255, 255, 255, 255), 1, "default", "center", "top", false, false, false, true, false) 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