Advertisement
gribbleshnibit8

Sort a form list by name of the items

Sep 15th, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. ; ALPHABETIZE WEAPON LISTS
  2.  
  3. ; loop vars
  4. int iIdx
  5. int iCnt
  6. ref rItm
  7.  
  8. ; sort vars
  9. int iIdx1
  10. int iCnt1
  11. int iIdx2
  12. int iCnt2
  13.  
  14. int iFlg
  15. int iTmp
  16. ref rLst
  17. ref rItm1
  18. ref rItm2
  19. ref rTemp
  20.  
  21. set iIdx to 0
  22. set iCnt to ListGetCount VMMWeaponListsOrderedList
  23. ; printc "%g lists to sort" iCnt
  24. Label 5
  25. if (iIdx < iCnt)
  26. set rLst to ListGetNthForm VMMWeaponListsOrderedList iIdx
  27. ; printc "Sorting %i" rLst
  28.  
  29. set iIdx1 to 0
  30. set iCnt1 to ListGetCount rLst
  31.  
  32. Label 10
  33. if (iIdx1 < iCnt1)
  34.  
  35. set iIdx2 to iIdx1
  36.  
  37. Label 20
  38. if (iIdx2 > 0)
  39. set iTmp to iIdx2 - 1
  40. set rItm1 to ListGetNthForm rLst iTmp
  41. set rItm2 to ListGetNthForm rLst iIdx2
  42. if (IsFormValid rItm1) && (IsFormValid rItm2)
  43. if (CompareNames rItm1 rItm2 == -1)
  44. set rTemp to ListGetNthForm rLst iTmp
  45. ListReplaceNthForm rLst rItm1 iIdx2
  46. ListReplaceNthForm rLst rItm2 iTmp
  47. endif
  48. set iIdx2 to iIdx2 - 1
  49. Goto 20
  50. endif
  51. endif
  52. set iIdx1 to iIdx1 + 1
  53. Goto 10
  54. endif
  55.  
  56. ; Output the contents of the sorted list to console for testing
  57. ; printc "Sorted %i" rLst
  58. ; set iIdx1 to 0
  59. ; set iCnt1 to ListGetCount NVAllWeapons
  60. ; Label 1
  61. ; if iIdx1 < iCnt1
  62. ; set rItm1 to ListGetNthForm NVAllWeapons iIdx1
  63. ; printc "%n" rItm1
  64. ; set iIdx1 to iIdx1 + 1
  65. ; Goto 1
  66. ; endif
  67. ; printc "End sorted %i" rLst
  68.  
  69. set iIdx to iIdx + 1
  70. Goto 5
  71. endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement