Puma Posted October 20, 2011 Share Posted October 20, 2011 I wanted the player nametags to display the colorcodes they got in their names, so I did a script for that. Thought it'd be nice to share it, I'm sure this script comes in very handy, as there is no colorcode support in the current dx-function to draw text. Made a util function of it. ___________________________________ Here it is: http://pastebin.com/iFVC9dLT Raw script (if you want to copy it, use this link!): http://pastebin.com/raw.php?i=iFVC9dLT NOTE: Be sure to include the 'hexToRGB'-function, the script won't work without it! ___________________________________ Syntax: dxDrawTextColorCoded ( string text, int left, int top, [ int alpha = 255, float scale = 1, mixed font = "default", bool clip = false, bool postGUI = false ] ) Required arguments: Text: Your text Left: Left textbox limit Top: Top textbox limit Optional: Alpha: Alpha (0-255) Scale: Text scale Font: Built in dx-font (string) or a dx font-element Clip: Cut text off if it sticks out of the box PostGUI: Set to true if text should be rendered after GUI NOTE: Aligning text is not supported! You only supply an argument for the top left starting position and the script does the rest, according to the text scale and font. ___________________________________ Short example: function render () dxDrawTextColorCoded ( "Test no color yet #ffaa00yaay orange #00ff00and now friggin' green #0101ffand some blue stuff", 500, 500 ) dxDrawTextColorCoded ( "B#ff0000L#00ff00A#0000ffH", 500, 500, 150, 4, "bankgothic" ) end addEventHandler ( "onClientRender", getRootElement(), render ) Result: ___________________________________ Have fun with it, I hope it's useful ! (maybe something for "Useful functions" page on wiki?) Link to comment
Aibo Posted October 20, 2011 Share Posted October 20, 2011 add alignment support, shouldn't be too hard ps: viewtopic.php?f=91&t=30227&p=347694#p347694 Link to comment
Puma Posted October 20, 2011 Author Share Posted October 20, 2011 Oh lol. Well I'm not that such a sophisticated scripter . Just did this myself and thought that maybe people could use it too. Link to comment
Aibo Posted October 20, 2011 Share Posted October 20, 2011 well alignment is quite simple, you just need box size (meaning it'll require more than just starting x/y) and just calculate top/left offset using box size and textline size. now word wrapping support — that's sophisticated 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