Msypon Posted February 22, 2012 Posted February 22, 2012 I'm trying to do a dxDrawText with color codes but I didn't get it plz help me local text = "" local drawState = false function drawText() local sWidth,sHeight = guiGetScreenSize() if not drawState then return end dxDrawText(text, sWidth-695-1,sHeight-395,sWidth-615-1,sHeight-366,tocolor(0,0,0,255),1.0,"bankgothic","center","top",false,false,false) dxDrawText(text, sWidth-695+1,sHeight-395,sWidth-615+1,sHeight-366,tocolor(0,0,0,255),1.0,"bankgothic","center","top",false,false,false) dxDrawText(text, sWidth-695,sHeight-395-1,sWidth-615,sHeight-366-1,tocolor(0,0,0,255),1.0,"bankgothic","center","top",false,false,false) dxDrawText(text, sWidth-695,sHeight-395+1,sWidth-615,sHeight-366+1,tocolor(0,0,0,255),1.0,"bankgothic","center","top",false,false,false) dxDrawText(text, sWidth-695,sHeight-395,sWidth-615,sHeight-366,tocolor(255,255,255,255),1.0,"bankgothic","center","top",false,false,false) end addEventHandler("onClientRender", root, drawText) addEvent("showText",true) addEventHandler("showText",root, function (cmd, theText) if cmd then drawState = true text = tostring(theText) else drawState = false end end )
Kenix Posted February 22, 2012 Posted February 22, 2012 (edited) Not understand you. Edited February 22, 2012 by Guest
drk Posted February 22, 2012 Posted February 22, 2012 Color codes? #ff0000, #00ff00 in text argument ? Use my edited dxDrawColorText: function dxDrawColorText(str, ax, ay, bx, by, color, scale, font, left, top, clip, wordbreak, postGUI) local pat = "(.-)#(%x%x%x%x%x%x)" local s, e, cap, col = str:find(pat, 1) local last = 1 while s do if cap == "" and col then color = tocolor( tonumber( "0x"..col:sub( 1, 2 ) ), tonumber( "0x"..col:sub( 3, 4 ) ), tonumber( "0x"..col:sub( 5, 6 ) ), 255 ) end if s ~= 1 or cap ~= "" then local w = dxGetTextWidth(cap, scale, font) dxDrawText( cap, ax, ay, ax + w, by, color, scale, font ) ax = ax + w color = tocolor( tonumber( "0x"..col:sub( 1, 2 ) ), tonumber( "0x"..col:sub( 3, 4 ) ), tonumber( "0x"..col:sub( 5, 6 ) ), 255 ) end last = e + 1 s, e, cap, col = str:find( pat, last ) end if last <= #str then cap = str:sub( last ) local w = dxGetTextWidth( cap, scale, font ) dxDrawText( cap, ax, ay, ax + w, by, color, scale, font, left, top, clip, wordbreak, postGUI ) end end
Msypon Posted February 22, 2012 Author Posted February 22, 2012 Color codes? #ff0000, #00ff00 in text argument ?Use my edited dxDrawColorText: function dxDrawColorText(str, ax, ay, bx, by, color, scale, font, left, top, clip, wordbreak, postGUI) local pat = "(.-)#(%x%x%x%x%x%x)" local s, e, cap, col = str:find(pat, 1) local last = 1 while s do if cap == "" and col then color = tocolor( tonumber( "0x"..col:sub( 1, 2 ) ), tonumber( "0x"..col:sub( 3, 4 ) ), tonumber( "0x"..col:sub( 5, 6 ) ), 255 ) end if s ~= 1 or cap ~= "" then local w = dxGetTextWidth(cap, scale, font) dxDrawText( cap, ax, ay, ax + w, by, color, scale, font ) ax = ax + w color = tocolor( tonumber( "0x"..col:sub( 1, 2 ) ), tonumber( "0x"..col:sub( 3, 4 ) ), tonumber( "0x"..col:sub( 5, 6 ) ), 255 ) end last = e + 1 s, e, cap, col = str:find( pat, last ) end if last <= #str then cap = str:sub( last ) local w = dxGetTextWidth( cap, scale, font ) dxDrawText( cap, ax, ay, ax + w, by, color, scale, font, left, top, clip, wordbreak, postGUI ) end end Okay working thank you alot
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