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 4.87 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 table.insert(attribs, v.attrib) end
  13. end
  14. table.insert(kaiUI.itemsByType[v.attrib], v)
  15. end
  16. items = {}
  17. for _,v in ipairs(attribs) do
  18. for k,v in pairs(kaiUI.itemsByType[v]) do
  19. if v.attrib ~= "mdt" then
  20. if (v.attrib:match("%w?m%w?")) then
  21. table.insert(mobs,v)
  22. else
  23. table.insert(items,v)
  24. end
  25. end
  26. end
  27. end
  28. kaiUI.gmcp.mobs = table.deepcopy(mobs)
  29. kaiUI.gmcp.items = table.deepcopy(items)
  30. end
  31.  
  32. function kaiUI.updateInfoHere()
  33. local echoString = "<LightYellow>["
  34. local color = ""
  35. local divColor = "<" .. kaiUI.CSS.base:get("border-color") .. ">"
  36. local divColor2 = kaiUI.infoHereColors.none
  37. local divString = ""
  38. local capString = divColor .. "------------------------------------------"
  39. local targetsHere = 0
  40. kaiUI.sortGMCPItems()
  41. kaiUI.mobsInRoom = {}
  42. kaiUI.denizenListConsole:clear()
  43. if table.size(kaiUI.gmcp.infoHere) == 0 then
  44. kaiUI.denizenListConsole:cecho("\n" .. capString)
  45. kaiUI.denizenListConsole:cecho("\n<LightYellow> Nothing here.")
  46. kaiUI.denizenListConsole:cecho("\n" .. capString)
  47. return
  48. else
  49. if table.size(kaiUI.gmcp.items) ~= 0 then
  50. divString = divColor .. "--" .. divColor2 .. " Objects " .. divColor .. "----------------------------------"
  51. kaiUI.denizenListConsole:cecho("\n" .. divString)
  52. for k, v in pairs(kaiUI.gmcp.items) do
  53. color = kaiUI.infoHereColors[v.attrib]
  54. if not color then color = kaiUI.infoHereColors["none"] end -- futureproofing
  55. echoString = string.rep(" ",6-#v.id) .. echoString .. color .. v.id .. "<LightYellow>] " .. color .. v.name
  56. if v.attrib ~= "mdt" then
  57. kaiUI.denizenListConsole:cecho("\n" .. echoString)
  58. end
  59. echoString = "<LightYellow>["
  60. end
  61. end
  62. if table.size(kaiUI.gmcp.mobs) ~= 0 then
  63. divString = divColor .. "--" .. divColor2 .. " Mobs " .. divColor .. "----------------------------------"
  64. kaiUI.denizenListConsole:cecho("\n" .. divString)
  65. for k,v in pairs(kaiUI.gmcp.mobs) do
  66. color = kaiUI.infoHereColors[v.attrib] or kaiUI.infoHereColors["m"]
  67. if v.attrib:match("%w?m%w?") and v.name:upper():find(kaiUI.targetName:upper()) then
  68. color = "<OrangeRed>"
  69. targetsHere = targetsHere + 1
  70. end
  71. if v.attrib == "m" or v.attrib == "mh" then
  72. kaiUI.mobsInRoom[v.id] = v.name
  73. end
  74. echoString = string.rep(" ",6-#v.id) .. echoString .. color .. v.id .. "<LightYellow>] " .. color .. v.name
  75. if v.attrib ~= "mdt" then
  76. kaiUI.denizenListConsole:cecho("\n" .. echoString)
  77. end
  78. echoString = "<LightYellow>["
  79. end
  80. end
  81. kaiUI.denizenListConsole:cecho("\n" .. capString)
  82. end
  83. kaiUI.mobCounterLabel:echo([[
  84. <p style="font-size:12px;"><font color="DarkSlateBlue"><b>|[<font color="LightYellow">Mobs: <font color="chartreuse">]]
  85. .. table.size(kaiUI.gmcp.mobs) ..
  86. [[<font color="DarkSlateBlue">]|[<font color="LightYellow">Targets: <font color="OrangeRed">]]
  87. .. targetsHere .. [[<font color="DarkSlateBlue">]|
  88. ]])
  89. kaiUI.denizenListConsole:hide()
  90. kaiUI.denizenListConsole:show()
  91. end
  92.  
  93. function kaiUI.onItemsList()
  94. if gmcp.Char.Items.List.location ~= "room" then
  95. return
  96. else
  97. kaiUI.gmcp.infoHere = table.deepcopy(gmcp.Char.Items.List.items)
  98. end
  99. kaiUI.updateInfoHere()
  100. end
  101.  
  102. function kaiUI.onItemsAdd()
  103. if gmcp.Char.Items.Add.location ~= "room" or gmcp.Char.Items.Add.item.attrib == "mdt" then
  104. return
  105. else
  106. table.insert(kaiUI.gmcp.infoHere, gmcp.Char.Items.Add.item)
  107. if gmcp.Char.Items.Add.item.attrib == "m" or gmcp.Char.Items.Add.item.attrib == "mh" then
  108. kaiUI.mobsInRoom[gmcp.Char.Items.Add.item.id] = gmcp.Char.Items.Add.item.name
  109. end
  110. end
  111. if kaiUI.addItemTimer then killTimer(kaiUI.addItemTimer) end
  112. kaiUI.addItemTimer = tempTimer(0.25, function() kaiUI.updateInfoHere() end)
  113. end
  114.  
  115. function kaiUI.onItemsRemove()
  116. if gmcp.Char.Items.Remove.location ~= "room" then
  117. return
  118. else
  119. for k, v in pairs(kaiUI.mobsInRoom) do
  120. if k == gmcp.Char.Items.Remove.item.id then
  121. kaiUI.mobsInRoom[gmcp.Char.Items.Remove.item.id] = nil
  122. end
  123. end
  124. for k, v in pairs(kaiUI.gmcp.infoHere) do
  125. if gmcp.Char.Items.Remove.item.id == v.id or kaiUI.gmcp.infoHere[k].attrib == "mdt" then
  126. kaiUI.gmcp.infoHere[k] = nil
  127. end
  128. end
  129. end
  130. kaiUI.updateInfoHere()
  131. end
  132.  
  133. registerAnonymousEventHandler("gmcp.Char.Items.Add", "kaiUI.onItemsAdd")
  134. registerAnonymousEventHandler("gmcp.Char.Items.Remove", "kaiUI.onItemsRemove")
  135. registerAnonymousEventHandler("gmcp.Char.Items.List", "kaiUI.onItemsList")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement