Fury Posted April 10, 2012 Posted April 10, 2012 hello guys, i made a xml stats system worked like this; users.xml <users> <SERIAL_6218AAAD464C476132E8FC18695D2844 wins="6" points="200" second="2" third="0" nick="[Evo]Flooderne"></SERIAL_6218AAAD464C476132E8FC18695D2844> <SERIAL_B4760ED9F491634C91ACEAF3DB31FCB2 wins="2" points="120" second="6" third="0" nick="[Evo]joshter50"></SERIAL_B4760ED9F491634C91ACEAF3DB31FCB2> .. .. ..</users> is there any way to make a top wins/points/second/third list with nickname? thanks for reading ps: my gang is not it is F u c k N. fix that please
X-SHADOW Posted April 10, 2012 Posted April 10, 2012 you can Use table.sort http://www.lua.org/manual/5.1/manual.ht ... table.sort
Fury Posted April 11, 2012 Author Posted April 11, 2012 you can Use table.sorthttp://www.lua.org/manual/5.1/manual.ht ... table.sort can you give me a example?
Guest Guest4401 Posted April 11, 2012 Posted April 11, 2012 (edited) --xml > wins="6" points="200" second="2" third="0" nick="[Evo]Flooderne">> wins="2" points="160" second="6" third="0" nick="[Evo]joshter51">> wins="7" points="120" second="3" third="0" nick="[Evo]joshter52">> wins="1" points="140" second="9" third="0" nick="[Evo]joshter53">> wins="9" points="150" second="7" third="0" nick="[Evo]joshter54">>> --server side local amountOfTopsToDisplay = 3 -- how many tops you need addCommandHandler("top", function(player, command, value) local file = xmlLoadFile("users.xml") -- load file if file then -- if file exists if value == "wins" or value == "points" or value == "second" or value == "third" then -- if syntax is right local tableOrder = {} -- make a table local subTable = {} -- make a sub table for i,v in ipairs(xmlNodeGetChildren(file)) do -- get children from file subTable.name = xmlNodeGetAttribute(v, "nick") -- name goes in subTable subTable.data = xmlNodeGetAttribute(v, value) -- data goes in subTable table.insert(tableOrder, subTable) -- subTable is inserted in bigger table subTable = {} -- empty subTable for next loop end table.sort(tableOrder, function(a,b) return tonumber(a.data) > tonumber(b.data) end) -- put data in order outputChatBox("Displaying top "..value, player, 255,255,255,true) for i,v in ipairs(tableOrder) do -- loop the sorted table outputChatBox(i..": "..v.name.." - "..v.data, player, 255,255,255,true) -- display in order if i == amountOfTopsToDisplay then break end -- when enough tops has been shown, break it end else outputChatBox("Syntax : /top [wins|points|second|third]", player, 255,255,255,true) -- show the correct syntax if he got it wrong end xmlUnloadFile(file) -- unload the file from memory end end ) Tested, works =) Edited April 13, 2012 by Guest4401
Castillo Posted April 11, 2012 Posted April 11, 2012 @karthik184: It would be nice if you would add comments, you know, what does each line, I guess it would be helpful for him.
Guest Guest4401 Posted April 11, 2012 Posted April 11, 2012 @karthik184: It would be nice if you would add comments, you know, what does each line, I guess it would be helpful for him. Okay, done.
Fury Posted April 11, 2012 Author Posted April 11, 2012 --server side local amountOfTopsToDisplay = 3 -- how many tops you need addCommandHandler("top", function(player, command, value) local file = xmlLoadFile("users.xml") -- load file if file then -- if file exists if value == "wins" or value == "points" or value == "second" or value == "third" then -- if syntax is right local tableOrder = {} -- make a table local subTable = {} -- make a sub table for i,v in ipairs(xmlNodeGetChildren(file)) do -- get children from file subTable.name = xmlNodeGetAttribute(v, "nick") -- name goes in subTable subTable.data = xmlNodeGetAttribute(v, value) -- data goes in subTable table.insert(tableOrder, subTable) -- subTable is inserted in bigger table subTable = {} -- empty subTable for next loop end table.sort(tableOrder, function(a,b) return a.data>b.data end) -- put data in order outputChatBox("Displaying top "..value, player, 255,255,255,true) for i,v in ipairs(tableOrder) do -- loop the sorted table outputChatBox(i..": "..v.name.." - "..v.data, player, 255,255,255,true) -- display in order if i == amountOfTopsToDisplay then break end -- when enough tops has been shown, break it end else outputChatBox("Syntax : /top [wins|points|second|third]", player, 255,255,255,true) -- show the correct syntax if he got it wrong end xmlUnloadFile(file) -- unload the file from memory end end ) Tested, works =) thank you so much i understand how table.sort works! but in this code i have got this error; top.lua:19: atempt to concantenate field 'data' (a boolean value) i dont know why i got this error
Kenix Posted April 11, 2012 Posted April 11, 2012 Your field 'data' in table is boolean value. If you know lua you can understand this. So this line (12) return boolean value subTable.data = xmlNodeGetAttribute(v, value)
Fury Posted April 11, 2012 Author Posted April 11, 2012 @karthik184 You are a so good man that helping to people. Thanks for your all helps. ps: topic can be closed
Castillo Posted April 11, 2012 Posted April 11, 2012 I'll leave the topic open, someone else may have the same problem.
Fury Posted April 11, 2012 Author Posted April 11, 2012 I'll leave the topic open, someone else may have the same problem. oki doki
Memory Posted December 15, 2012 Posted December 15, 2012 Hello, please, fix error in 19 line. And if add this code to client, for send values to GUI, he will work? Or I must use this through triggerServerEvent?
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