Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 KB | None | 0 0
  1. function kaiUI.sortGMCPItems()
  2. local items = table.deepcopy(kaiUI.gmcp.infoHere)
  3. local mobs = {}
  4. local attribs = {}
  5. kaiUI.itemsByType = {}
  6. for k, v in pairs(items) do
  7. if not v.attrib then
  8. items[k].attrib = "none"
  9. end
  10. if not kaiUI.itemsByType[v.attrib] then
  11. kaiUI.itemsByType[v.attrib] = {}
  12. if not attribs[v.attrib] then
  13. table.insert(attribs, v.attrib)
  14. end
  15. end
  16. table.insert(kaiUI.itemsByType[v.attrib], v)
  17. end
  18. items = {}
  19. for _, v in ipairs(attribs) do
  20. for k, v in pairs(kaiUI.itemsByType[v]) do
  21. if v.attrib ~= "mdt" then
  22. if (v.attrib:match("%w?m%w?")) then
  23. table.insert(mobs, v)
  24. else
  25. table.insert(items, v)
  26. end
  27. end
  28. end
  29. end
  30. kaiUI.gmcp.mobs = table.deepcopy(mobs)
  31. kaiUI.gmcp.items = table.deepcopy(items)
  32. end
  33.  
  34. function kaiUI.updateInfoHere()
  35. local echoString = "<LightYellow>["
  36. local color = ""
  37. local divColor = "<" .. kaiUI.CSS.base:get("border-color") .. ">"
  38. local divColor2 = kaiUI.infoHereColors.none
  39. local divString = ""
  40. local capString = divColor .. "------------------------------------------"
  41. local targetsHere = 0
  42. kaiUI.sortGMCPItems()
  43. kaiUI.mobsInRoom = {}
  44. kaiUI.denizenListConsole:clear()
  45. if table.size(kaiUI.gmcp.infoHere) == 0 then
  46. kaiUI.denizenListConsole:cecho("\n" .. capString)
  47. kaiUI.denizenListConsole:cecho("\n<LightYellow> Nothing here.")
  48. kaiUI.denizenListConsole:cecho("\n" .. capString)
  49. return
  50. else
  51. if table.size(kaiUI.gmcp.items) ~= 0 then
  52. divString =
  53. divColor ..
  54. "--" ..
  55. divColor2 ..
  56. " Objects " ..
  57. divColor ..
  58. "----------------------------------"
  59. kaiUI.denizenListConsole:cecho("\n" .. divString)
  60. for k, v in pairs(kaiUI.gmcp.items) do
  61. color = kaiUI.infoHereColors[v.attrib]
  62. if not color then
  63. color = kaiUI.infoHereColors["none"]
  64. end
  65. -- futureproofing
  66. echoString =
  67. string.rep(" ", 6 - #v.id) ..
  68. echoString ..
  69. color ..
  70. v.id ..
  71. "<LightYellow>] " ..
  72. color ..
  73. v.name
  74. if v.attrib ~= "mdt" then
  75. kaiUI.denizenListConsole:cecho("\n" .. echoString)
  76. end
  77. echoString = "<LightYellow>["
  78. end
  79. end
  80. if table.size(kaiUI.gmcp.mobs) ~= 0 then
  81. divString =
  82. divColor ..
  83. "--" ..
  84. divColor2 ..
  85. " Mobs " ..
  86. divColor ..
  87. "----------------------------------"
  88. kaiUI.denizenListConsole:cecho("\n" .. divString)
  89. for k, v in pairs(kaiUI.gmcp.mobs) do
  90. color = kaiUI.infoHereColors[v.attrib] or kaiUI.infoHereColors["m"]
  91. if v.attrib:match("%w?m%w?") and v.name:upper():find(kaiUI.targetName:upper()) then
  92. color = "<OrangeRed>"
  93. targetsHere = targetsHere + 1
  94. end
  95. kaiUI.mobsInRoom[v.id] = v.name
  96. echoString =
  97. string.rep(" ", 6 - #v.id) ..
  98. echoString ..
  99. color ..
  100. v.id ..
  101. "<LightYellow>] " ..
  102. color ..
  103. v.name
  104. if v.attrib ~= "mdt" then
  105. kaiUI.denizenListConsole:cecho("\n" .. echoString)
  106. end
  107. echoString = "<LightYellow>["
  108. end
  109. end
  110. kaiUI.denizenListConsole:cecho("\n" .. capString)
  111. end
  112. kaiUI.mobCounterLabel:echo(
  113. [[
  114. <p style="font-size:12px;"><font color="DarkSlateBlue"><b>|[<font color="LightYellow">Mobs: <font color="chartreuse">]] ..
  115. table.size(kaiUI.gmcp.mobs) ..
  116. [[<font color="DarkSlateBlue">]|[<font color="LightYellow">Targets: <font color="OrangeRed">]] ..
  117. targetsHere ..
  118. [[<font color="DarkSlateBlue">]|
  119. ]]
  120. )
  121. kaiUI.denizenListConsole:hide()
  122. kaiUI.denizenListConsole:show()
  123. end
  124.  
  125. function kaiUI.onItemsList()
  126. if gmcp.Char.Items.List.location ~= "room" then
  127. return
  128. else
  129. kaiUI.gmcp.infoHere = table.deepcopy(gmcp.Char.Items.List.items)
  130. end
  131. kaiUI.updateInfoHere()
  132. end
  133.  
  134. function kaiUI.onItemsAdd()
  135. if gmcp.Char.Items.Add.location ~= "room" or gmcp.Char.Items.Add.item.attrib == "mdt" then
  136. return
  137. else
  138. table.insert(kaiUI.gmcp.infoHere, gmcp.Char.Items.Add.item)
  139. if gmcp.Char.Items.Add.item.attrib == "m" or gmcp.Char.Items.Add.item.attrib == "mh" then
  140. kaiUI.mobsInRoom[gmcp.Char.Items.Add.item.id] = gmcp.Char.Items.Add.item.name
  141. end
  142. end
  143. if kaiUI.addItemTimer then
  144. killTimer(kaiUI.addItemTimer)
  145. end
  146. kaiUI.addItemTimer =
  147. tempTimer(
  148. 0.25,
  149. function()
  150. kaiUI.updateInfoHere()
  151. end
  152. )
  153. end
  154.  
  155. function kaiUI.onItemsRemove()
  156. if gmcp.Char.Items.Remove.location ~= "room" then
  157. return
  158. else
  159. for k, v in pairs(kaiUI.mobsInRoom) do
  160. if k == gmcp.Char.Items.Remove.item.id then
  161. kaiUI.mobsInRoom[gmcp.Char.Items.Remove.item.id] = nil
  162. end
  163. end
  164. for k, v in pairs(kaiUI.gmcp.infoHere) do
  165. if gmcp.Char.Items.Remove.item.id == v.id or kaiUI.gmcp.infoHere[k].attrib == "mdt" then
  166. kaiUI.gmcp.infoHere[k] = nil
  167. end
  168. end
  169. end
  170. kaiUI.updateInfoHere()
  171. end
  172.  
  173. registerAnonymousEventHandler("gmcp.Char.Items.Add", "kaiUI.onItemsAdd")
  174. registerAnonymousEventHandler("gmcp.Char.Items.Remove", "kaiUI.onItemsRemove")
  175. registerAnonymousEventHandler("gmcp.Char.Items.List", "kaiUI.onItemsList")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement