Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. registerAnonymousEventHandler("gmcp.Char.Items.Add", "kaiUI.onItemsAdd")
  2. registerAnonymousEventHandler("gmcp.Char.Items.Remove", "kaiUI.onItemsRemove")
  3. registerAnonymousEventHandler("gmcp.Char.Items.List", "kaiUI.onItemsList")
  4. registerAnonymousEventHandler("gmcp.Char.Items.Update", "kaiUI.onItemsUpdate")
  5. local maxSize = 30
  6. kaiUI.itemsHere = kaiUI.itemsHere or {}
  7. kaiUI.itemsSorted = kaiUI.itemsSorted
  8. local infoColors =
  9. {
  10. t = "<DarkGoldenrod>",
  11. m = "<chartreuse>",
  12. mh = "<OrangeRed>",
  13. c = "<LightSkyBlue>",
  14. none = "<LightGoldenrod>",
  15. et = "<DarkGoldenrod>",
  16. mt = "<DarkGoldenrod>",
  17. cm = "<LightSkyBlue>",
  18. }
  19. local sortOrder = {"c", "none", "mh", "m", "mt", "cm", "t", "et", "ct", "md", "mdt"}
  20.  
  21. local function printLine(number, name, attrib, spacing)
  22. local color = infoColors[attrib] or "<LightGoldenrod>"
  23. local echoString =
  24. string.rep(" ", spacing - #("" .. number)) ..
  25. "<LightYellow>[" ..
  26. color ..
  27. number ..
  28. color ..
  29. "<LightYellow>] " ..
  30. color ..
  31. name
  32. kaiUI.denizenListConsole:cecho("\n" .. echoString)
  33. end
  34.  
  35. local function sortItems()
  36. kaiUI.itemsSorted = {}
  37. for _, attrib in pairs(sortOrder) do
  38. kaiUI.itemsSorted[attrib] = {}
  39. end
  40. for k, item in pairs(kaiUI.itemsHere) do
  41. local attrib = item.attrib or "none"
  42. if not table.contains(sortOrder, attrib) then
  43. display(attrib)
  44. else
  45. kaiUI.itemsSorted[attrib][item.name] = (kaiUI.itemsSorted[attrib][item.name] or 0) + 1
  46. end
  47. end
  48. end
  49.  
  50. local timerRunning, writeTimer = false
  51.  
  52. function kaiUI.writeItemsHere()
  53. -- display(writeTimer)
  54. if not timerRunning then
  55. timerRunning = true
  56. if writeTimer then
  57. killTimer(writeTimer)
  58. end
  59. writeTimer =
  60. tempTimer(
  61. 0,
  62. function()
  63. timerRunning = false
  64. kaiUI.writeItems2()
  65. end
  66. )
  67. end
  68. end
  69.  
  70. function kaiUI.writeItems2()
  71. kaiUI.denizenListConsole:clear()
  72. if #kaiUI.itemsHere > maxSize then
  73. for _, attrib in ipairs(sortOrder) do
  74. for name, number in pairs(kaiUI.itemsSorted[attrib]) do
  75. printLine(number,name,attrib,3)
  76. end
  77. end
  78. else
  79. for _, item in pairs(kaiUI.itemsHere) do
  80. printLine(item.id, item.name, item.attrib, 6)
  81. end
  82. end
  83. end
  84.  
  85. function kaiUI.onItemsList()
  86. if gmcp.Char.Items.List.location ~= "room" then
  87. return
  88. end
  89. kaiUI.itemsHere = table.deepcopy(gmcp.Char.Items.List.items)
  90. if #kaiUI.itemsHere > maxSize then
  91. sortItems()
  92. else
  93. kaiUI.itemsSorted = nil
  94. end
  95. kaiUI.writeItemsHere()
  96. end
  97.  
  98. function kaiUI.onItemsUpdate()
  99. if gmcp.Char.Items.Update.location ~= "room" then
  100. return
  101. end
  102. for index, item in pairs(kaiUI.itemsHere) do
  103. if item.id == gmcp.Char.Items.Update.item.id then
  104. kaiUI[index] = gmcp.Char.Items.Update.item
  105. kaiUI.writeItemsHere()
  106. if #kaiUI.itemsHere > maxSize then
  107. sortItems()
  108. end
  109. return
  110. end
  111. end
  112. end
  113.  
  114. function kaiUI.onItemsAdd()
  115. if gmcp.Char.Items.Add.location ~= "room" then
  116. return
  117. end
  118. local item = gmcp.Char.Items.Add.item
  119. table.insert(kaiUI.itemsHere, item)
  120. if #kaiUI.itemsHere > maxSize then
  121. kaiUI.itemsSorted[item.attrib][item.name] = (kaiUI.itemsSorted[item.attrib][item.name] or 0) + 1
  122. kaiUI.writeItemsHere()
  123. else
  124. printLine(item.id, item.name, item.attrib, 6)
  125. end
  126. end
  127.  
  128. function kaiUI.onItemsRemove()
  129. if gmcp.Char.Items.Remove.location ~= "room" then
  130. return
  131. end
  132. local item = gmcp.Char.Items.Remove.item
  133. for index, item2 in pairs(kaiUI.itemsHere) do
  134. if item2.id == item.id then
  135. table.remove(kaiUI.itemsHere, index)
  136. kaiUI.writeItemsHere()
  137. if kaiUI.itemsSorted then
  138. kaiUI.itemsSorted[item.attrib][item.name] =
  139. (kaiUI.itemsSorted[item.attrib][item.name] or 0) - 1
  140. if kaiUI.itemsSorted[item.attrib][item.name] <= 0 then
  141. kaiUI.itemsSorted[item.attrib][item.name] = nil
  142. end
  143. end
  144. return
  145. end
  146. end
  147. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement