Fury Posted July 4, 2012 Posted July 4, 2012 hello guys, i have made a stats system for race with getAccountData and setAccountData. i want to make a top list for it. i have "nick" data and i want make it top "wins", "points", "second", "third" list like that. top 5 wins 1. F*ckN|V - 18 2. F*ckN|Deiter - 12 3. F*ckN|Vendetta - 10 4. F*ckN|Deitas - 8 5. F*ckN|Vienetta - 2 i know i have to use table.sort. but i dont know to use account database thing. local amountOfTopsToDisplay = 5 addCommandHandler("top", function(player, command, value) if value == "wins" or value == "points" or value == "second" or value == "third" then local tableOrder = {} local subTable = {} for i,v do subTable.name = getAccountData( v, "nick" ) subTable.data = getAccountData( v, vaule ) table.insert(tableOrder, subTable) subTable = {} end table.sort(tableOrder, function(a,b) return tonumber(a.data)>tonumber(b.data) end) outputChatBox("#c0c0c0* Top 5 #abcdef"..value, player, 255,255,255,true) for i,v in ipairs(tableOrder) do outputChatBox("#c0c0c0* #abcdef"..i.."#c0c0c0. #abcdef"..v.name.." #c0c0c0- #abcdef"..v.data, player, 255,255,255,true) if i == amountOfTopsToDisplay then break end end else outputChatBox("#c0c0c0* Syntax : #abcdef/top #c0c0c0[#abcdefwins #c0c0c0| #abcdefpoints#c0c0c0]", player, 255,255,255,true) end end) is this code right? thanks for now
TAPL Posted July 4, 2012 Posted July 4, 2012 what is this? for i,v do i think you want to get all accounts for i,v in ipairs(getAccounts()) do
Fury Posted July 4, 2012 Author Posted July 4, 2012 what is this? for i,v do i think you want to get all accounts for i,v in ipairs(getAccounts()) do when i try that it gives me bad argument in subTable.name = getAccountData( v, "nick" ) subTable.data = getAccountData( v, vaule )
TAPL Posted July 4, 2012 Posted July 4, 2012 local amountOfTopsToDisplay = 5 addCommandHandler("top", function(player, command, value) if value == "wins" or value == "points" or value == "second" or value == "third" then local tableOrder = {} for i,v in ipairs(getAccounts()) do table.insert(tableOrder,{name = getAccountData(v, "nick"),data = getAccountData(v, vaule)}) end table.sort(tableOrder, function(a,b) return tonumber(a.data)>tonumber(b.data) end) outputChatBox("#c0c0c0* Top 5 #abcdef"..value, player, 255,255,255,true) for i,v in ipairs(tableOrder) do outputChatBox("#c0c0c0* #abcdef"..i.."#c0c0c0. #abcdef"..v.name.." #c0c0c0- #abcdef"..v.data, player, 255,255,255,true) if i == amountOfTopsToDisplay then break end end else outputChatBox("#c0c0c0* Syntax : #abcdef/top #c0c0c0[#abcdefwins #c0c0c0| #abcdefpoints#c0c0c0]", player, 255,255,255,true) end end)
DNL291 Posted July 4, 2012 Posted July 4, 2012 (edited) I think there's a spelling error in getAccountData() function ('vaule'). Also, the second argument of the getAccountData() function is a string ('The Key'). Edited March 30, 2013 by Guest
MTA Team qaisjp Posted July 4, 2012 MTA Team Posted July 4, 2012 I think there's a orthographic error in getAccountData() function ('vaule')? Moreover, the second argument of getAccountData() function is string (The Key). What?!
Guest Guest4401 Posted July 4, 2012 Posted July 4, 2012 There is actually a spelling mistake. You've mispelled value as vaule and yes, value is a string.
Fury Posted July 4, 2012 Author Posted July 4, 2012 local amountOfTopsToDisplay = 5 addCommandHandler("top", function(player, command, value) if value == "wins" or value == "points" or value == "second" or value == "third" then local tableOrder = {} for i,v in ipairs(getAccounts()) do table.insert(tableOrder,{name = getAccountData(v, "nick"),data = getAccountData(v, vaule)}) end table.sort(tableOrder, function(a,b) return tonumber(a.data)>tonumber(b.data) end) outputChatBox("#c0c0c0* Top 5 #abcdef"..value, player, 255,255,255,true) for i,v in ipairs(tableOrder) do outputChatBox("#c0c0c0* #abcdef"..i.."#c0c0c0. #abcdef"..v.name.." #c0c0c0- #abcdef"..v.data, player, 255,255,255,true) if i == amountOfTopsToDisplay then break end end else outputChatBox("#c0c0c0* Syntax : #abcdef/top #c0c0c0[#abcdefwins #c0c0c0| #abcdefpoints#c0c0c0]", player, 255,255,255,true) end end) bad argument in table.insert(tableOrder,{name = getAccountData(v, "nick"),data = getAccountData(v, vaule)})
Guest Guest4401 Posted July 4, 2012 Posted July 4, 2012 bad argument in table.insert(tableOrder,{name = getAccountData(v, "nick"),data = getAccountData(v, vaule)}) Do you mind reading what I wrote once again?There is actually a spelling mistake. You've misspelled value as vaule and yes, value is a string.
Fury Posted July 4, 2012 Author Posted July 4, 2012 (edited) ah i didnt see your post now i have got this problem.. local amountOfTopsToDisplay = 5 addCommandHandler("top", function(player, command, value) if value == "wins" or value == "points" then local tableOrder = {} for i,v in ipairs(getAccounts()) do table.insert(tableOrder,{name = getAccountData(v, "nick"),data = getAccountData(v, value)}) end table.sort(tableOrder, function(a,b) return ( tonumber(a.data) or 0 ) > ( tonumber(b.data) or 0 ) end) outputChatBox("#c0c0c0* Top 5 #abcdef"..value, player, 255,255,255,true) for i,v in ipairs(tableOrder) do outputChatBox("#c0c0c0* #abcdef"..i.."#c0c0c0. #abcdef"..v.name.." #c0c0c0- #abcdef"..v.data, player, 255,255,255,true) if i == amountOfTopsToDisplay then break end end else outputChatBox("#c0c0c0* Syntax : #abcdef/top #c0c0c0[#abcdefwins #c0c0c0| #abcdefpoints#c0c0c0]", player, 255,255,255,true) end end) on line of 12 Edited July 4, 2012 by Guest
TAPL Posted July 4, 2012 Posted July 4, 2012 ah i didnt see your post now i have got this problem.. local amountOfTopsToDisplay = 5 addCommandHandler("top", function(player, command, value) if value == "wins" or value == "points" then local tableOrder = {} for i,v in ipairs(getAccounts()) do table.insert(tableOrder,{nick = getAccountData(v, "nick"),data = getAccountData(v, value)}) end table.sort(tableOrder, function(a,b) return ( tonumber(a.data) or 0 ) > ( tonumber(b.data) or 0 ) end) outputChatBox("#c0c0c0* Top 5 #abcdef"..value, player, 255,255,255,true) for i,v in ipairs(tableOrder) do outputChatBox("#c0c0c0* #abcdef"..i.."#c0c0c0. #abcdef"..v.nick.." #c0c0c0- #abcdef"..v.data, player, 255,255,255,true) if i == amountOfTopsToDisplay then break end end else outputChatBox("#c0c0c0* Syntax : #abcdef/top #c0c0c0[#abcdefwins #c0c0c0| #abcdefpoints#c0c0c0]", player, 255,255,255,true) end end) on line of 12 i can't find 'name' in your code, it's nick check your code again.
Fury Posted July 4, 2012 Author Posted July 4, 2012 local amountOfTopsToDisplay = 5 addCommandHandler("top", function(player, command, value) if value == "wins" or value == "points" then local tableOrder = {} for i,v in ipairs(getAccounts()) do table.insert(tableOrder,{name = getAccountData(v, "nick"),data = getAccountData(v, value)}) end table.sort(tableOrder, function(a,b) return ( tonumber(a.data) or 0 ) > ( tonumber(b.data) or 0 ) end) outputChatBox("#c0c0c0* Top 5 #abcdef"..value, player, 255,255,255,true) for i,v in ipairs(tableOrder) do outputChatBox("#c0c0c0* #abcdef"..i.."#c0c0c0. #abcdef"..v.name.." #c0c0c0- #abcdef"..v.data, player, 255,255,255,true) if i == amountOfTopsToDisplay then break end end else outputChatBox("#c0c0c0* Syntax : #abcdef/top #c0c0c0[#abcdefwins #c0c0c0| #abcdefpoints#c0c0c0]", player, 255,255,255,true) end end) on line of 12
Castillo Posted July 4, 2012 Posted July 4, 2012 local amountOfTopsToDisplay = 5 addCommandHandler ( "top", function ( player, command, value ) if ( value == "wins" or value == "points" ) then local tableOrder = { } for i, v in ipairs ( getAccounts ( ) ) do table.insert ( tableOrder, { name = getAccountData ( v, "nick" ), data = getAccountData ( v, value ) } ) end table.sort ( tableOrder, function ( a, b ) return ( tonumber ( a.data ) or 0 ) > ( tonumber ( b.data ) or 0 ) end ) outputChatBox ( "#c0c0c0* Top 5 #abcdef".. value, player, 255, 255, 255, true ) for i = 1, amountOfTopsToDisplay do outputChatBox ( "#c0c0c0* #abcdef".. i .."#c0c0c0. #abcdef".. tostring ( tableOrder [ i ].name ) .." #c0c0c0- #abcdef".. tostring ( tableOrder [ i ].data ), player, 255, 255, 255, true ) end else outputChatBox ( "#c0c0c0* Syntax : #abcdef/top #c0c0c0[#abcdefwins #c0c0c0| #abcdefpoints#c0c0c0]", player, 255, 255, 255, true ) end end )
Fury Posted July 4, 2012 Author Posted July 4, 2012 local amountOfTopsToDisplay = 5 addCommandHandler ( "top", function ( player, command, value ) if ( value == "wins" or value == "points" ) then local tableOrder = { } for i, v in ipairs ( getAccounts ( ) ) do table.insert ( tableOrder, { name = getAccountData ( v, "nick" ), data = getAccountData ( v, value ) } ) end table.sort ( tableOrder, function ( a, b ) return ( tonumber ( a.data ) or 0 ) > ( tonumber ( b.data ) or 0 ) end ) outputChatBox ( "#c0c0c0* Top 5 #abcdef".. value, player, 255, 255, 255, true ) for i = 1, amountOfTopsToDisplay do outputChatBox ( "#c0c0c0* #abcdef".. i .."#c0c0c0. #abcdef".. tostring ( tableOrder [ i ].name ) .." #c0c0c0- #abcdef".. tostring ( tableOrder [ i ].data ), player, 255, 255, 255, true ) end else outputChatBox ( "#c0c0c0* Syntax : #abcdef/top #c0c0c0[#abcdefwins #c0c0c0| #abcdefpoints#c0c0c0]", player, 255, 255, 255, true ) end end ) thanks you okay its done but i have this now. if player is not in the server it shows "false" ...
Castillo Posted July 4, 2012 Posted July 4, 2012 local amountOfTopsToDisplay = 5 addCommandHandler ( "top", function ( player, command, value ) if ( value == "wins" or value == "points" ) then local tableOrder = { } for i, v in ipairs ( getAccounts ( ) ) do table.insert ( tableOrder, { name = getAccountData ( v, "nick" ) or getAccountName ( v ), data = getAccountData ( v, value ) } ) end table.sort ( tableOrder, function ( a, b ) return ( tonumber ( a.data ) or 0 ) > ( tonumber ( b.data ) or 0 ) end ) outputChatBox ( "#c0c0c0* Top 5 #abcdef".. value, player, 255, 255, 255, true ) for i = 1, amountOfTopsToDisplay do outputChatBox ( "#c0c0c0* #abcdef".. i .."#c0c0c0. #abcdef".. tostring ( tableOrder [ i ].name ) .." #c0c0c0- #abcdef".. tostring ( tableOrder [ i ].data ), player, 255, 255, 255, true ) end else outputChatBox ( "#c0c0c0* Syntax : #abcdef/top #c0c0c0[#abcdefwins #c0c0c0| #abcdefpoints#c0c0c0]", player, 255, 255, 255, true ) end end ) You can do that, so if the account doesn't has 'nick' data, it'll set name as account name.
Fury Posted July 4, 2012 Author Posted July 4, 2012 local amountOfTopsToDisplay = 5 addCommandHandler ( "top", function ( player, command, value ) if ( value == "wins" or value == "points" ) then local tableOrder = { } for i, v in ipairs ( getAccounts ( ) ) do table.insert ( tableOrder, { name = getAccountData ( v, "nick" ) or getAccountName ( v ), data = getAccountData ( v, value ) } ) end table.sort ( tableOrder, function ( a, b ) return ( tonumber ( a.data ) or 0 ) > ( tonumber ( b.data ) or 0 ) end ) outputChatBox ( "#c0c0c0* Top 5 #abcdef".. value, player, 255, 255, 255, true ) for i = 1, amountOfTopsToDisplay do outputChatBox ( "#c0c0c0* #abcdef".. i .."#c0c0c0. #abcdef".. tostring ( tableOrder [ i ].name ) .." #c0c0c0- #abcdef".. tostring ( tableOrder [ i ].data ), player, 255, 255, 255, true ) end else outputChatBox ( "#c0c0c0* Syntax : #abcdef/top #c0c0c0[#abcdefwins #c0c0c0| #abcdefpoints#c0c0c0]", player, 255, 255, 255, true ) end end ) You can do that, so if the account doesn't has 'nick' data, it'll set name as account name. thank you so much
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