Admigo Posted February 7, 2012 Posted February 7, 2012 Dear scripters, I want to make a colored deathlist but i dont know how i need to make it. I need to make it with dxtext but i cant figure it out how. Can someone help me pls? Thanks Admigo
Kenix Posted February 7, 2012 Posted February 7, 2012 Use function dxDrawColoredText function dxDrawColoredText(str, ax, ay, bx, by, color, scale, font,left,top) left = "left" if not top then top = "top" end 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,left,top,true) 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,true) end end ( found in forum )
Castillo Posted February 7, 2012 Posted February 7, 2012 Default race death list uses GUI-labels, to use that function you need to convert it to DX drawing.
Admigo Posted February 7, 2012 Author Posted February 7, 2012 This will be a hard task. I need to change the rankingboard client?
Admigo Posted February 7, 2012 Author Posted February 7, 2012 Now i have this: function createShadowedLabelFromSpare(x, y, width, height, text, align) if #spareElems < 2 then if not donePrecreate then outputDebug( 'OPTIMIZATION', 'createShadowedLabel' ) end return createShadowedLabel(x, y, width, height, text, align) else local shadow = table.popLast( spareElems ) guiSetSize(shadow, width, height, false) guiSetText(shadow, text) --guiLabelSetColor(shadow, 0, 0, 0) dxDrawText ( text, x, y, width, height, tocolor ( 255, 255, 0, 255 ), 1.02, "pricedown" ) guiSetPosition(shadow, x + 1, y + 1, false) guiSetVisible(shadow, true) local label = table.popLast( spareElems ) guiSetSize(label, width, height, false) guiSetText(label, text) --guiLabelSetColor(label, 255, 255, 255) dxDrawText ( text, x, y, width, height, tocolor ( 255, 255, 0, 255 ), 1.02, "pricedown" ) guiSetPosition(label, x, y, false) guiSetVisible(label, true) if align then guiLabelSetHorizontalAlign(shadow, align) guiLabelSetHorizontalAlign(label, align) else guiLabelSetHorizontalAlign(shadow, 'left') guiLabelSetHorizontalAlign(label, 'left') end return label, shadow end end When i press enter the yellow text appears for a sec. How can i fix this?
TwiX! Posted February 7, 2012 Posted February 7, 2012 Now i have this: function createShadowedLabelFromSpare(x, y, width, height, text, align) if #spareElems < 2 then if not donePrecreate then outputDebug( 'OPTIMIZATION', 'createShadowedLabel' ) end return createShadowedLabel(x, y, width, height, text, align) else local shadow = table.popLast( spareElems ) guiSetSize(shadow, width, height, false) guiSetText(shadow, text) --guiLabelSetColor(shadow, 0, 0, 0) dxDrawText ( text, x, y, width, height, tocolor ( 255, 255, 0, 255 ), 1.02, "pricedown" ) guiSetPosition(shadow, x + 1, y + 1, false) guiSetVisible(shadow, true) local label = table.popLast( spareElems ) guiSetSize(label, width, height, false) guiSetText(label, text) --guiLabelSetColor(label, 255, 255, 255) dxDrawText ( text, x, y, width, height, tocolor ( 255, 255, 0, 255 ), 1.02, "pricedown" ) guiSetPosition(label, x, y, false) guiSetVisible(label, true) if align then guiLabelSetHorizontalAlign(shadow, align) guiLabelSetHorizontalAlign(label, align) else guiLabelSetHorizontalAlign(shadow, 'left') guiLabelSetHorizontalAlign(label, 'left') end return label, shadow end end When i press enter the yellow text appears for a sec. How can i fix this? u not use dxDrawColorText here Example: dxDrawColoredText( text, x, y, width, height, tocolor ( 255, 255, 0, 255 ), 1.02, "pricedown" )
Castillo Posted February 7, 2012 Posted February 7, 2012 DX Drawing functions requires [url=https://wiki.multitheftauto.com/wiki/OnClientRender]https://wiki.multitheftauto.com/wiki/OnClientRender[/url] to work.
Admigo Posted February 7, 2012 Author Posted February 7, 2012 Made This: function HandleTheRendering ( ) addEventHandler ( "onClientRender", root, createShadowedLabelFromSpare ) -- keep the text visible with onClientRender. end addEventHandler ( "onClientResourceStart", resourceRoot, HandleTheRendering ) Debugscript 3: Util_client:attempt to perform arithmetic on local x(a nil valua)
GTX Posted February 8, 2012 Posted February 8, 2012 Try to use addEventHandler ( "onClientRender", root, createShadowedLabelFromSpare ) on the end of your file.
Admigo Posted February 8, 2012 Author Posted February 8, 2012 Still same error: Util_client:attempt to perform arithmetic on local x(a nil valua) Error line: local shadow = guiCreateLabel(x + 1, y + 1, width, height, text, false) My full code: function createShadowedLabelFromSpare(x, y, width, height, text, align) if #spareElems < 2 then if not donePrecreate then outputDebug( 'OPTIMIZATION', 'createShadowedLabel' ) end return createShadowedLabel(x, y, width, height, text, align) else local shadow = table.popLast( spareElems ) guiSetSize(shadow, width, height, false) guiSetText(shadow, text) --guiLabelSetColor(shadow, 0, 0, 0) dxDrawText ( text, x, y, width, height, tocolor ( 255, 255, 0, 255 ), 1.02, "pricedown" ) guiSetPosition(shadow, x + 1, y + 1, false) guiSetVisible(shadow, true) local label = table.popLast( spareElems ) guiSetSize(label, width, height, false) guiSetText(label, text) --guiLabelSetColor(label, 255, 255, 255) dxDrawText ( text, x, y, width, height, tocolor ( 255, 255, 0, 255 ), 1.02, "pricedown" ) guiSetPosition(label, x, y, false) guiSetVisible(label, true) if align then guiLabelSetHorizontalAlign(shadow, align) guiLabelSetHorizontalAlign(label, align) else guiLabelSetHorizontalAlign(shadow, 'left') guiLabelSetHorizontalAlign(label, 'left') end return label, shadow end end addEventHandler ( "onClientRender", root, createShadowedLabelFromSpare ) How can i fix this pls?
Castillo Posted February 8, 2012 Posted February 8, 2012 What you don't understand is that you need Lua knowledge before converting it, is not that easy for a newbie (no offense).
BinSlayer1 Posted February 8, 2012 Posted February 8, 2012 I just dont get it:P there's nothing to get.. you either know how to adapt an existent GUI script to use DX Text or you don't, in which case you're left with 2 choices: -learn lua and do it yourself -sit back, relax, enjoy life and have someone else do it for you in exchange for money (unless there's someone willing to do it for free)
Admigo Posted February 8, 2012 Author Posted February 8, 2012 I got the client render from wiki and i placed it at rankingboard_client and i get error at util_client,
BinSlayer1 Posted February 8, 2012 Posted February 8, 2012 Then don't put a random event handler without thinking.. You need to rewrite the script almost entirely
drk Posted February 21, 2012 Posted February 21, 2012 Off-topic: I've edited dxDrawColorText and added alignX,alignY,clip,wordbreak and postGUI parameters like dxDrawText. Here: function dxDrawColoredText(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 Example: dxDrawColoredText('#ff0000My #00ff00text',posX,posY,width,height,tocolor(r,g,b,a),1.0,"pricedown","left","top",false,false,true) I don't know if someone has done this
Paper Posted February 21, 2012 Posted February 21, 2012 You can use the textlib, it will be easyer ^^
drk Posted February 21, 2012 Posted February 21, 2012 I can use textlibs, but it's more easy for me for big scripts. Then, I made it public. If you don't want to use then don't use
Paper Posted February 21, 2012 Posted February 21, 2012 Will be easyer for this script because you will not add any event handler, you will have to modify just the gui functions
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