W4LK1NG Posted November 3, 2017 Share Posted November 3, 2017 Excuse me if my English is wrong I need to create a Rank but I do not get what I want, I managed to create a table and insert values in it, and with a command leaves them from the largest to the smallest, the problem is that I want to enter the name of the player beyond the values and do not know how to get the values and the name together List = {} function ShowRank (source) setElementData (source,"WalkinG",15) setElementData (source,"WG",10) setElementData (source,"AL-KinG",5) for _,player in ipairs (getElementsByType ("player")) do Value = getElementData (player,"WalkinG") Value2 = getElementData (player,"WG") Value3 = getElementData (player,"AL-KinG") table.insert (List,Value) table.insert (List,Value2) table.insert (List,Value3) end end addCommandHandler ("renk",ShowRank) function ShowList () for i=1,3 do ordenaLista (List) outputChatBox (List[i]) end end addCommandHandler ("rank",ShowList) function ordenaLista (lista) for rodada=1,#lista do for i,valor in ipairs (lista) do if lista[i]<lista[rodada] then local seguravalorantigo = lista[rodada] lista[rodada] = lista[i] lista[i] = seguravalorantigo end end end end Link to comment
Moderators IIYAMA Posted November 4, 2017 Moderators Share Posted November 4, 2017 Insert it in `List` like this. The variable `player` is used as key, which leads to the data(another table). Saving List[player] = {Value, Value2, Value3} Loading local data = List[player] local value1 = data[1] local value2 = data[2] local value3 = data[3] Looping for player, data in pairs(List) do local value1 = data[1] local value2 = data[2] local value3 = data[3] end Please do not abuse using the predefined variable `source` inside of an addCommandHandler. Just simple: function ShowRank (player) Since you already know that it is a player (or false if it is activated by script.) Link to comment
W4LK1NG Posted November 5, 2017 Author Share Posted November 5, 2017 9 hours ago, IIYAMA said: Insert it in `List` like this. The variable `player` is used as key, which leads to the data(another table). Saving List[player] = {Value, Value2, Value3} Loading local data = List[player] local value1 = data[1] local value2 = data[2] local value3 = data[3] Looping for player, data in pairs(List) do local value1 = data[1] local value2 = data[2] local value3 = data[3] end Please do not abuse using the predefined variable `source` inside of an addCommandHandler. Just simple: function ShowRank (player) Since you already know that it is a player (or false if it is activated by script.) Thank you, it worked, and thanks for the tip of source Link to comment
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