• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Help to return player ranking

atakashi

New Member
Joined
Jan 20, 2009
Messages
15
Reaction score
0
Good night, I need help in a basic system but I don't know how to do kk.
I have a function to see the ranking of an event system
I'm wondering how do I get the player by placing

Example:
Miguel is in first with 100 points
Josue in second with 90 points

I want to be able to return Josue's ID

My Function:

Code:
function getRankArenaSurviver()                                                                      --alterado v1.9 \/
local query = db.getResult("SELECT `id`, `arenasurviver` FROM `players` ORDER BY `arenasurviver` DESC;")
local str = {}
table.insert(str, "Rank of the Surviver Arena:\n\n")

if query:getID() ~= -1 then
   for i = 1, 10 do
      if not(query:next()) or query:getDataInt("arenasurviver") == 0 then
         table.insert(str, i.."* None - 0 level.\n")
      else
         local s = tonumber(query:getDataInt("arenasurviver")) > 1 and "s" or ""
         table.insert(str, i.."* "..getPlayerNameByGUID(query:getDataString("id")).." - "..query:getDataInt("arenasurviver").." level"..s..".\n")
      end
   end
query:free()
end
return table.concat(str)
end
 
Lua:
local players = {}

table.insert(players, {['id'] = 100, ['score']= 100})
table.insert(players, {['id'] = 200, ['score']= 90})

for i, v in ipairs(players) do
  print(i.."-  ID: "..  v['id'] .." : Score: "..  v['score'])
end
From what i understand this is what you are requiring.
This code will create an array where you can can get the requested data from.
Obviously its only a template and you will need to convert as needed but it'll allow you to iterate the list and pull whatever data you insert.
 
Lua:
local players = {}

table.insert(players, {['id'] = 100, ['score']= 100})
table.insert(players, {['id'] = 200, ['score']= 90})

for i, v in ipairs(players) do
  print(i.."-  ID: "..  v['id'] .." : Score: "..  v['score'])
end
From what i understand this is what you are requiring.
This code will create an array where you can can get the requested data from.
Obviously its only a template and you will need to convert as needed but it'll allow you to iterate the list and pull whatever data you insert.

I just gave an example of the value of the players I don't mean that they will have this value
I want him to check the rank and become the second place
 
I just gave an example of the value of the players I don't mean that they will have this value
I want him to check the rank and become the second place
Yes, i know, I gave you an example piece of code for you to modify for your function.
If use that table in your function. You can get rank, id and score using the example piece of code I gave you, and can include anything else that you want in array.

You will just need to update your function and any other piece of code that uses that function.
 
Back
Top