GTX Posted February 14, 2012 Posted February 14, 2012 Hello, I got this addEvent( 'onAccountsSend',true ) local labels = { } addEventHandler( 'onAccountsSend',root, function( t ) for index, data in ipairs( t ) do if labels[ index ] == nil or labels[ index ] == false then labels[ index ] = guiCreateColorLabel(13,20 * index + 39,500,276,'#ffffff#'..tostring( index )..": "..tostring( data.account ),false,tab_leaderboard ) else guiSetText(labels[ index ], '#ffffff#'..tostring( index )..": "..tostring( data.account )) end if index == 10 then break end end end ) Everytime when I click on button, script creates new label. Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
Kenix Posted February 14, 2012 Posted February 14, 2012 addEvent( 'onAccountsSend',true ) local labels = { } addEventHandler( 'onAccountsSend',root, function( t ) for index, data in ipairs( t ) do if isElement( labels[ index ] ) then destroyElement( labels[ index ] ) end labels[ index ] = guiCreateColorLabel( 13,20 * index + 39,500,276,'#ffffff#'..tostring( index )..": "..tostring( data.account ),false,tab_leaderboard ) if index == 10 then break end end end ) http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
GTX Posted February 14, 2012 Author Posted February 14, 2012 Still the same problem, when I click on the button twice it creates two labels Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
Kenix Posted February 14, 2012 Posted February 14, 2012 Can you give me full code? I test it and fix. via pm. http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
GTX Posted February 14, 2012 Author Posted February 14, 2012 Code is top secret I'll send you via PM Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
Kenix Posted February 14, 2012 Posted February 14, 2012 You have syntax problem with 'end'. Your code function theButtons() if source == btn_show_points then triggerServerEvent("recievePrefix", localPlayer, "Points") end addEventHandler ( "onClientGUIClick", btn_show_points, theButtons ) Correct function theButtons() if source == btn_show_points then triggerServerEvent("recievePrefix", localPlayer, "Points") end end addEventHandler ( "onClientGUIClick", btn_show_points, theButtons ) Tabulate code and you can see where you forgot 'end'. http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
Kenix Posted February 14, 2012 Posted February 14, 2012 (edited) addEvent( 'onAccountsSend',true ) local labels = { } addEventHandler( 'onAccountsSend',root, function( t ) if #labels == 0 then for index, data in ipairs( t ) do guiCreateColorLabel( 13,20 * index + 39,500,276,'#ffffff#'..tostring( index )..": "..tostring( data.account ),false,tab_leaderboard ) if index == 10 then break end end labels[ 1 ] = true end end ) I tested your resource. It working. Edited February 14, 2012 by Guest http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
Castillo Posted February 14, 2012 Posted February 14, 2012 You have syntax problem with 'end'.Your code function theButtons() if source == btn_show_points then triggerServerEvent("recievePrefix", localPlayer, "Points") end addEventHandler ( "onClientGUIClick", btn_show_points, theButtons ) Correct function theButtons() if source == btn_show_points then triggerServerEvent("recievePrefix", localPlayer, "Points") end end addEventHandler ( "onClientGUIClick", btn_show_points, theButtons ) Tabulate code and you can see where you forgot 'end'. I don't know why you need the 'if' check. function theButtons() triggerServerEvent("recievePrefix", localPlayer, "Points") end addEventHandler ( "onClientGUIClick", btn_show_points, theButtons, false ) San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Kenix Posted February 14, 2012 Posted February 14, 2012 My bad not see it. But anyway it should work. Tested. http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
GTX Posted February 14, 2012 Author Posted February 14, 2012 Wow, it works! Thanks! Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
Kenix Posted February 14, 2012 Posted February 14, 2012 No problem. http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
GTX Posted February 14, 2012 Author Posted February 14, 2012 Okay, now I got another problem. I created more buttons and I don't know how to change text... Maybe I need to destroy and create it again. Client: btn_show_points = guiCreateButton(349,47,114,36,"Points",false) btn_show_cash = guiCreateButton(474,47,114,36,"Cash",false) btn_show_wins = guiCreateButton(349,97,114,36,"Wins",false) btn_show_ttset = guiCreateButton(474,97,114,36,"Top times set",false) btn_show_played = guiCreateButton(349,47,114,36,"Maps played",false) btn_show_deaths = guiCreateButton(474,47,114,36,"Deaths",false) function theButtons () if source == btn_show_points then triggerServerEvent("recievePrefix", localPlayer, "points") end if source == btn_show_cash then triggerServerEvent("recievePrefix", localPlayer, "money_q") end if source == btn_show_ttset then triggerServerEvent("recievePrefix", localPlayer, "ttset") end if source == btn_show_played then triggerServerEvent("recievePrefix", localPlayer, "mapsplayed") end if source == btn_show_deaths then triggerServerEvent("recievePrefix", localPlayer, "deaths") end end addEventHandler ( "onClientGUIClick", btn_show_points, theButtons ) addEventHandler ( "onClientGUIClick", btn_show_cash, theButtons ) addEventHandler ( "onClientGUIClick", btn_show_ttset, theButtons ) addEventHandler ( "onClientGUIClick", btn_show_played, theButtons ) addEventHandler ( "onClientGUIClick", btn_show_deaths, theButtons ) addEvent( 'onAccountsSend',true ) local labels = { } addEventHandler( 'onAccountsSend',root, function( t ) if #labels == 0 then for index, data in ipairs( t ) do guiCreateColorLabel( 13,20 * index + 39,500,276,'#ffffff#'..tostring( index )..": "..tostring( data.account ),false ) if index == 10 then break end end labels[ 1 ] = true end end ) Server: function sortAccounts(prefix) local rowdata = { } for _, account in pairs( getAccounts( ) ) do rowdata[ #rowdata + 1 ] = { account = getAccountData( account, "playername" ), points = getAccountData( account, tostring(prefix) ) } end table.sort( rowdata, function ( a, b ) return ( tonumber( a.points ) or 0 ) > ( tonumber( b.points ) or 0 ) end ) return rowdata end function tables(prefix) for index, data in ipairs( sortAccounts( ) ) do if index == 3 then break end end triggerClientEvent( 'onAccountsSend',root,sortAccounts(prefix) ) end addEvent("recievePrefix", true) addEventHandler("recievePrefix", root, tables) Now I think this is already impossible lol... Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
Castillo Posted February 14, 2012 Posted February 14, 2012 Try this: btn_show_points = guiCreateButton(349,47,114,36,"Points",false) btn_show_cash = guiCreateButton(474,47,114,36,"Cash",false) btn_show_wins = guiCreateButton(349,97,114,36,"Wins",false) btn_show_ttset = guiCreateButton(474,97,114,36,"Top times set",false) btn_show_played = guiCreateButton(349,47,114,36,"Maps played",false) btn_show_deaths = guiCreateButton(474,47,114,36,"Deaths",false) function theButtons () if source == btn_show_points then triggerServerEvent("recievePrefix", localPlayer, "points") end if source == btn_show_cash then triggerServerEvent("recievePrefix", localPlayer, "money_q") end if source == btn_show_ttset then triggerServerEvent("recievePrefix", localPlayer, "ttset") end if source == btn_show_played then triggerServerEvent("recievePrefix", localPlayer, "mapsplayed") end if source == btn_show_deaths then triggerServerEvent("recievePrefix", localPlayer, "deaths") end end addEventHandler ( "onClientGUIClick", btn_show_points, theButtons ) addEventHandler ( "onClientGUIClick", btn_show_cash, theButtons ) addEventHandler ( "onClientGUIClick", btn_show_ttset, theButtons ) addEventHandler ( "onClientGUIClick", btn_show_played, theButtons ) addEventHandler ( "onClientGUIClick", btn_show_deaths, theButtons ) addEvent( 'onAccountsSend',true ) local labels = { } addEventHandler( 'onAccountsSend',root, function( t ) for index, label in pairs(labels) do if isElement(label) then destroyElement(label) end end if #labels == 0 then for index, data in ipairs( t ) do labels[index] = guiCreateColorLabel( 13,20 * index + 39,500,276,'#ffffff#'..tostring( index )..": "..tostring( data.account ),false ) if index == 10 then break end end end end ) San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Kenix Posted February 14, 2012 Posted February 14, 2012 guiCreateColorLabel,is return element in your script? http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
GTX Posted February 14, 2012 Author Posted February 14, 2012 This code doesn't work. I think guiCreateColorLabel doesn't return element. 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) lbl = 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(lbl,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) lbl2 = guiCreateLabel(ax, ay, ax + w, by,cap,parent, bool) guiLabelSetColor(lbl2,r,g,b) end end Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
Castillo Posted February 14, 2012 Posted February 14, 2012 It wouldn't return just one element, as it's creating many labels, try this: btn_show_points = guiCreateButton(349,47,114,36,"Points",false) btn_show_cash = guiCreateButton(474,47,114,36,"Cash",false) btn_show_wins = guiCreateButton(349,97,114,36,"Wins",false) btn_show_ttset = guiCreateButton(474,97,114,36,"Top times set",false) btn_show_played = guiCreateButton(349,47,114,36,"Maps played",false) btn_show_deaths = guiCreateButton(474,47,114,36,"Deaths",false) function theButtons () if source == btn_show_points then triggerServerEvent("recievePrefix", localPlayer, "points") end if source == btn_show_cash then triggerServerEvent("recievePrefix", localPlayer, "money_q") end if source == btn_show_ttset then triggerServerEvent("recievePrefix", localPlayer, "ttset") end if source == btn_show_played then triggerServerEvent("recievePrefix", localPlayer, "mapsplayed") end if source == btn_show_deaths then triggerServerEvent("recievePrefix", localPlayer, "deaths") end end addEventHandler ( "onClientGUIClick", btn_show_points, theButtons ) addEventHandler ( "onClientGUIClick", btn_show_cash, theButtons ) addEventHandler ( "onClientGUIClick", btn_show_ttset, theButtons ) addEventHandler ( "onClientGUIClick", btn_show_played, theButtons ) addEventHandler ( "onClientGUIClick", btn_show_deaths, theButtons ) addEvent( 'onAccountsSend',true ) local labels = { } addEventHandler( 'onAccountsSend',root, function( t ) for index, lbls in pairs(labels) do for index, label in ipairs(lbls) do if isElement(label) then destroyElement(label) end end end labels = { } if #labels == 0 then for index, data in ipairs( t ) do labels[index] = guiCreateColorLabel( 13,20 * index + 39,500,276,'#ffffff#'..tostring( index )..": "..tostring( data.account ),false ) if index == 10 then break end end end end ) 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 local labels = {} 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) lbl = guiCreateLabel(ax, ay, ax + w, by,cap,parent, bool) table.insert(labels, lbl) if (r == nil) then r = 255 end if (g == nil) then g = 255 end if (b == nil) then b = 255 end guiLabelSetColor(lbl,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) lbl2 = guiCreateLabel(ax, ay, ax + w, by,cap,parent, bool) table.insert(labels, lbl2) guiLabelSetColor(lbl2,r,g,b) end return labels end San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
GTX Posted February 14, 2012 Author Posted February 14, 2012 When I press the first button works fine, but when I press any other button the label destroys Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
Castillo Posted February 14, 2012 Posted February 14, 2012 I don't understand what do you mean, it should destroy the labels when you click another button, and create them again with the new information. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
GTX Posted February 14, 2012 Author Posted February 14, 2012 I don't understand what do you mean, it should destroy the labels when you click another button, and create them again with the new information. Yes, but it doesn't create them, that's the problem Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
Castillo Posted February 14, 2012 Posted February 14, 2012 Copy the script again and tell me if it creates them now. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
GTX Posted February 14, 2012 Author Posted February 14, 2012 Yes, it does! Thank you very much! Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
Castillo Posted February 14, 2012 Posted February 14, 2012 You're welcome. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
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