Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. function essenceSort(t)
  2. local nt = {}
  3.  
  4. for name, essence in pairs(t) do
  5. table.insert(nt, {
  6. name = name,
  7. essence = tonumber(essence)
  8. })
  9. end
  10.  
  11. table.sort(nt, function(a, b)
  12. if a.essence > b.essence then
  13. return true
  14. elseif a.essence < b.essence then
  15. return false
  16. elseif a.name < b.name then
  17. return true
  18. else
  19. return false
  20. end
  21. end)
  22.  
  23. return nt
  24. end
  25.  
  26. -- To display:
  27. for _, v in ipairs(essenceSort(yourtable)) do
  28. echo(v.name .. ": " .. v.essence .. "\n")
  29. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement