Advertisement
dunc001

Sorting JArray by a specific key in the JMap objects

Oct 3rd, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. function sortAmmoQueueByQuantity(int ammoQ)
  2. debug.trace("iEquip_AmmoScript sortAmmoQueueByQuantity() called")
  3. int queueLength = jArray.count(ammoQ)
  4. int tempAmmoQ = jArray.objectWithSize(queueLength)
  5. int tempAmmoQReversed = jArray.objectWithSize(queueLength)
  6. int i = 0
  7. int ammoCount
  8. while i < queueLength
  9. ammoCount = jMap.getInt(jArray.getObj(ammoQ, i), "Count")
  10. jArray.setInt(tempAmmoQ, i, ammoCount)
  11. i += 1
  12. endWhile
  13. jArray.sort(tempAmmoQ)
  14. i = 0
  15. int iIndex = queueLength - 1
  16. while i < queueLength
  17. jArray.setInt(tempAmmoQReversed, i, iIndex)
  18. i += 1
  19. iIndex -= 1
  20. endWhile
  21. i = 0
  22. bool found
  23. while i < queueLength
  24. ammoCount = jArray.getInt(tempAmmoQReversed, i)
  25. iIndex = 0
  26. found = false
  27. while iIndex < queueLength && !found
  28. if ammoCount != jMap.getInt(jArray.getObj(ammoQ, iIndex), "Count")
  29. iIndex += 1
  30. else
  31. found = true
  32. endIf
  33. endWhile
  34. if i != iIndex
  35. jArray.swapItems(ammoQ, i, iIndex)
  36. endIf
  37. i += 1
  38. endWhile
  39. WC.selectBestAmmo()
  40. i = 0
  41. while i < queueLength
  42. debug.trace("iEquip_AmmoScript - sortAmmoQueueByQuantity(), sorted ammo array - i: " + i + ", " + jMap.getStr(jArray.getObj(ammoQ, i), "Name") + ", Count: " + jMap.getInt(jArray.getObj(ammoQ, i), "Count"))
  43. i += 1
  44. endWhile
  45. endFunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement