Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function dxDrawTextColorCoded ( text, left, top, alpha, scale, font, clip, postGUI )
- if text and tostring(text) and left and tonumber(left) and top and tonumber(top) then
- if not scale or not tonumber(scale) then scale = 1 end
- if not font or not tostring(font) then font = "default" end
- local textX, textY = left, top
- local textH = dxGetFontHeight ( scale, font )
- local textClear = string.gsub ( text, "#%x%x%x%x%x%x", "" )
- local textTable = {}
- local splitTable = split ( text, 35 )
- if #splitTable == 1 then
- local codeStart, codeStop = string.find ( text, "#%x%x%x%x%x%x" )
- if codeStart and codeStop then
- local r, g, b = hexToRGB ( string.sub ( text, codeStart, codeStop ) )
- table.insert ( textTable, { textClear, r, g, b } )
- else
- table.insert ( textTable, { textClear, 255, 255, 255 } )
- end
- else
- for i, string in pairs ( splitTable ) do
- if i == 1 then
- local codeStart, codeStop = string.find ( text, "#%x%x%x%x%x%x" )
- if codeStart and codeStop and codeStop < #string+1 then
- local r, g, b = hexToRGB ( string.sub ( text, codeStart, codeStop ) )
- table.insert ( textTable, { string.gsub ( "#"..string, "#%x%x%x%x%x%x", "" ), r, g, b } )
- else
- table.insert ( textTable, { string, 255, 255, 255 } )
- end
- else
- local newString = "#"..string
- local r, g, b = hexToRGB ( string.sub ( newString, 1, 7 ) )
- table.insert ( textTable, { string.gsub ( newString, "#%x%x%x%x%x%x", "" ), r, g, b } )
- end
- end
- end
- local startX = 0
- for i, stringData in pairs ( textTable ) do
- local string, r, g, b = stringData[1], stringData[2], stringData[3], stringData[4]
- if #string > 0 then
- local stringWidth = dxGetTextWidth ( string, scale, font )
- dxDrawText ( string, textX+startX, textY, textX+startX+stringWidth, textY+textH, tocolor ( r, g, b, alpha ), scale, font, "left", "top", clip, false, postGUI )
- startX = startX + stringWidth
- end
- end
- else
- return false
- end
- end
- function hexToRGB ( hex )
- hex = hex:gsub("#","")
- return tonumber("0x"..hex:sub(1,2)), tonumber("0x"..hex:sub(3,4)), tonumber("0x"..hex:sub(5,6))
- end
Advertisement
Add Comment
Please, Sign In to add comment