BriGhtx3 Posted January 19, 2012 Posted January 19, 2012 I know there is no way to use color codes in labels. But i want to set colors for different texts. I know I can use dxtext but is there no other way? Like creating a display or something like this for a GUI? Ill freak out when someone says you cant use color codes in labels -.- Currently working on gamemodes : Reallife Script 70% Breakout Script 10%
Xeno Posted January 19, 2012 Posted January 19, 2012 You can't use colour codes in labels.... (LOL) On topic: Do you mean like: Label text:"wwqdqwd(< this part is red) 438348234829394 ( < this part is green)" ??
BriGhtx3 Posted January 19, 2012 Author Posted January 19, 2012 yes Currently working on gamemodes : Reallife Script 70% Breakout Script 10%
Xeno Posted January 19, 2012 Posted January 19, 2012 Create two labels, and move it next to the other label.
BriGhtx3 Posted January 19, 2012 Author Posted January 19, 2012 Lol I knew that but it is very difficult to create 100 labels -.- And the users add the texts via color codes. Currently working on gamemodes : Reallife Script 70% Breakout Script 10%
Blaawee Posted January 20, 2012 Posted January 20, 2012 i don't know mybe this will work : https://wiki.multitheftauto.com/wiki/GuiSetProperty guiSetProperty(label, "labelTextColour", "FFA0A0A0")
50p Posted January 20, 2012 Posted January 20, 2012 i don't know mybe this will work :https://wiki.multitheftauto.com/wiki/GuiSetProperty guiSetProperty(label, "labelTextColour", "FFA0A0A0") That would change the label colour, same as guiLabelSetColor. Lol I knew that but it is very difficult to create 100 labels -.- And the users add the texts via color codes. Just create a function which will create as many labels as many colours you have in the string. There is a similar function for DX text on the forum somewhere, just search the forum, I'm sure you'll find it easily. Then just modify the function to work GUI labels instead of DX text. - MTA Script Editor - Ask your scripting questions properly, please. - 50p's public resources - Meta.xml - what is it for? How is it possible LOL
UAEpro Posted January 20, 2012 Posted January 20, 2012 easy the original code was for dxdrawcolortext and i made this for colored label --- by UAEpro function guiCreateColorLabel(ax, ay, bx, by,str, parent, bool) 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 r,g,b = tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)) end if s ~= 1 or cap ~= "" then local w = dxGetTextWidth(cap) avc321 = guiCreateLabel(ax, ay, ax + w, by,cap,parent, bool) if r == nil then r = 255 end if g == nil then g = 255 end if b == nil then b = 255 end guiLabelSetColor(avc321,r,g,b) ax = ax + w r,g,b = tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)) 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) avc123 = guiCreateLabel(ax, ay, ax + w, by,cap,parent, bool) guiLabelSetColor(avc123,r,g,b) end end تيم سبيك بروجيمر ts3server://ts.pg.sa
BriGhtx3 Posted January 21, 2012 Author Posted January 21, 2012 UAepro very nice Code. But you can't use guiSetText with it oO Currently working on gamemodes : Reallife Script 70% Breakout Script 10%
Kenix Posted January 21, 2012 Posted January 21, 2012 Yes,because he not returned gui element in function. http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
BriGhtx3 Posted January 21, 2012 Author Posted January 21, 2012 How do you mean this? Currently working on gamemodes : Reallife Script 70% Breakout Script 10%
Kenix Posted January 21, 2012 Posted January 21, 2012 We can't use return value in function guiCreateColorLabel because is returned value nil. http://lua-users.org/wiki/FunctionsTutorial Understand? http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
BriGhtx3 Posted January 21, 2012 Author Posted January 21, 2012 Oh now I understand this. So I have to destroy it and create it again? Currently working on gamemodes : Reallife Script 70% Breakout Script 10%
Kenix Posted January 21, 2012 Posted January 21, 2012 Not understand So I have to destroy it and create it again? http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
UAEpro Posted January 22, 2012 Posted January 22, 2012 Oh now I understand this. So I have to destroy it and create it again? yes .. that what i do ^.^ تيم سبيك بروجيمر ts3server://ts.pg.sa
drk Posted February 25, 2012 Posted February 25, 2012 function guiCreateColorLabel(ax, ay, bx, by,str, bool, parent) 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 r,g,b = tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)) end if s ~= 1 or cap ~= "" then local w = dxGetTextWidth(cap) avc321 = guiCreateLabel(ax, ay, ax + w, by,cap,bool,parent) if r == nil then r = 255 end if g == nil then g = 255 end if b == nil then b = 255 end guiLabelSetColor(avc321,r,g,b) ax = ax + w r,g,b = tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)) 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) avc123 = guiCreateLabel(ax, ay, ax + w, by,cap,bool,parent) guiLabelSetColor(avc123,r,g,b) return avc123 end end Can anyone help with this EPT Team Server Development: 0% Learning C++ | C++ is amazing
drk Posted February 25, 2012 Posted February 25, 2012 Sorry for 2 posts but no one want to help? EPT Team Server Development: 0% Learning C++ | C++ is amazing
Kenix Posted February 25, 2012 Posted February 25, 2012 What the problem? http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
drk Posted February 25, 2012 Posted February 25, 2012 function guiCreateColorLabel(ax, ay, bx, by,str, bool, parent) 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 r,g,b = tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)) end if s ~= 1 or cap ~= "" then local w = dxGetTextWidth(cap) avc321 = guiCreateLabel(ax, ay, ax + w, by,cap,bool,parent) if r == nil then r = 255 end if g == nil then g = 255 end if b == nil then b = 255 end guiLabelSetColor(avc321,r,g,b) ax = ax + w r,g,b = tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)) 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) avc123 = guiCreateLabel(ax, ay, ax + w, by,cap,bool,parent) guiLabelSetColor(avc123,r,g,b) return avc123 end end I get error on guiLabelSetColor(avc123,r,g,b) I know that its because r,g,b is not defined but I don't remember nothing how to solve this '-' EPT Team Server Development: 0% Learning C++ | C++ is amazing
Kenix Posted February 25, 2012 Posted February 25, 2012 function guiCreateColorLabel( ax, ay, bx, by,str, bool, parent ) local pat = "(.-)#(%x%x%x%x%x%x)" local s, e, cap, col = str:find( pat, 1 ) local last = 1 local r,g,b while s do if cap == "" and col then r,g,b = tonumber( "0x"..col:sub( 1, 2 ) ), tonumber( "0x"..col:sub( 3, 4 ) ), tonumber( "0x"..col:sub( 5, 6 ) ) end if s ~= 1 or cap ~= "" then local w = dxGetTextWidth( cap ) avc321 = guiCreateLabel( ax, ay, ax + w, by,cap,bool,parent ) if not r then r = 255 end if not g then g = 255 end if not b then b = 255 end guiLabelSetColor( avc321,r,g,b ) ax = ax + w r,g,b = tonumber( "0x"..col:sub( 1, 2 ) ), tonumber( "0x"..col:sub( 3, 4 ) ), tonumber( "0x"..col:sub( 5, 6 ) ) end last = e + 1 s, e, cap, col = str:find( pat, last ) end if last <= #str then local cap = str:sub( last ) local w = dxGetTextWidth( cap ) local avc123 = guiCreateLabel( ax, ay, ax + w, by,cap,bool,parent ) guiLabelSetColor( avc123,r or 255,g or 255,b or 255 ) return avc123 end end http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
drk Posted February 25, 2012 Posted February 25, 2012 Ok. Thanks. I will try. EPT Team Server Development: 0% Learning C++ | C++ is amazing
drk Posted March 3, 2012 Posted March 3, 2012 I get no error but It don't work... It appear with color codes. And no colors I tried with: function guiCreateColorLabel ( ax, ay, bx, by, str, relative, parent ) 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 r, g, b = tonumber( "0x"..col:sub( 1, 2 ) ), tonumber( "0x"..col:sub( 3, 4 ) ), tonumber( "0x"..col:sub( 5, 6 ) ) end last = e + 1 s, e, cap, col = str:find( pat, last ) end if r == nil then r = 255 end if g == nil then g = 255 end if b == nil then b = 255 end if last <= #str then cap = str:sub( last ) label = guiCreateLabel ( ax, ay, bx, by, cap, relative, parent ) guiLabelSetColor ( label, r, g, b ) return label end end But I get error on guiLabelSetColor. I don't know why I get expected number, colors don't have to be numbers? oO EPT Team Server Development: 0% Learning C++ | C++ is amazing
Kenix Posted March 4, 2012 Posted March 4, 2012 Show line error. http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
Cadu12 Posted March 4, 2012 Posted March 4, 2012 Line: 18 guiLabelSetColor (label, r or 255, g or 255, b or 255) Is that hard? Ingame nick: Cadu12
Kenix Posted March 4, 2012 Posted March 4, 2012 Draken,Why you not use my code http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
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