Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- registerAnonymousEventHandler("gmcp.Char.Items.Add", "kaiUI.onItemsAdd")
- registerAnonymousEventHandler("gmcp.Char.Items.Remove", "kaiUI.onItemsRemove")
- registerAnonymousEventHandler("gmcp.Char.Items.List", "kaiUI.onItemsList")
- registerAnonymousEventHandler("gmcp.Char.Items.Update", "kaiUI.onItemsUpdate")
- local maxSize = 30
- kaiUI.itemsHere = kaiUI.itemsHere or {}
- kaiUI.itemsSorted = kaiUI.itemsSorted
- local infoColors =
- {
- t = "<DarkGoldenrod>",
- m = "<chartreuse>",
- mh = "<OrangeRed>",
- c = "<LightSkyBlue>",
- none = "<LightGoldenrod>",
- et = "<DarkGoldenrod>",
- mt = "<DarkGoldenrod>",
- cm = "<LightSkyBlue>",
- }
- local sortOrder = {"c", "none", "mh", "m", "mt", "cm", "t", "et", "ct", "md", "mdt"}
- local function printLine(number, name, attrib, spacing)
- local color = infoColors[attrib] or "<LightGoldenrod>"
- local echoString =
- string.rep(" ", spacing - #("" .. number)) ..
- "<LightYellow>[" ..
- color ..
- number ..
- color ..
- "<LightYellow>] " ..
- color ..
- name
- kaiUI.denizenListConsole:cecho("\n" .. echoString)
- end
- local function sortItems()
- kaiUI.itemsSorted = {}
- for _, attrib in pairs(sortOrder) do
- kaiUI.itemsSorted[attrib] = {}
- end
- for k, item in pairs(kaiUI.itemsHere) do
- local attrib = item.attrib or "none"
- if not table.contains(sortOrder, attrib) then
- display(attrib)
- else
- kaiUI.itemsSorted[attrib][item.name] = (kaiUI.itemsSorted[attrib][item.name] or 0) + 1
- end
- end
- end
- local timerRunning, writeTimer = false
- function kaiUI.writeItemsHere()
- -- display(writeTimer)
- if not timerRunning then
- timerRunning = true
- if writeTimer then
- killTimer(writeTimer)
- end
- writeTimer =
- tempTimer(
- 0,
- function()
- timerRunning = false
- kaiUI.writeItems2()
- end
- )
- end
- end
- function kaiUI.writeItems2()
- kaiUI.denizenListConsole:clear()
- if #kaiUI.itemsHere > maxSize then
- for _, attrib in ipairs(sortOrder) do
- for name, number in pairs(kaiUI.itemsSorted[attrib]) do
- printLine(number,name,attrib,3)
- end
- end
- else
- for _, item in pairs(kaiUI.itemsHere) do
- printLine(item.id, item.name, item.attrib, 6)
- end
- end
- end
- function kaiUI.onItemsList()
- if gmcp.Char.Items.List.location ~= "room" then
- return
- end
- kaiUI.itemsHere = table.deepcopy(gmcp.Char.Items.List.items)
- if #kaiUI.itemsHere > maxSize then
- sortItems()
- else
- kaiUI.itemsSorted = nil
- end
- kaiUI.writeItemsHere()
- end
- function kaiUI.onItemsUpdate()
- if gmcp.Char.Items.Update.location ~= "room" then
- return
- end
- for index, item in pairs(kaiUI.itemsHere) do
- if item.id == gmcp.Char.Items.Update.item.id then
- kaiUI[index] = gmcp.Char.Items.Update.item
- kaiUI.writeItemsHere()
- if #kaiUI.itemsHere > maxSize then
- sortItems()
- end
- return
- end
- end
- end
- function kaiUI.onItemsAdd()
- if gmcp.Char.Items.Add.location ~= "room" then
- return
- end
- local item = gmcp.Char.Items.Add.item
- table.insert(kaiUI.itemsHere, item)
- if #kaiUI.itemsHere > maxSize then
- kaiUI.itemsSorted[item.attrib][item.name] = (kaiUI.itemsSorted[item.attrib][item.name] or 0) + 1
- kaiUI.writeItemsHere()
- else
- printLine(item.id, item.name, item.attrib, 6)
- end
- end
- function kaiUI.onItemsRemove()
- if gmcp.Char.Items.Remove.location ~= "room" then
- return
- end
- local item = gmcp.Char.Items.Remove.item
- for index, item2 in pairs(kaiUI.itemsHere) do
- if item2.id == item.id then
- table.remove(kaiUI.itemsHere, index)
- kaiUI.writeItemsHere()
- if kaiUI.itemsSorted then
- kaiUI.itemsSorted[item.attrib][item.name] =
- (kaiUI.itemsSorted[item.attrib][item.name] or 0) - 1
- if kaiUI.itemsSorted[item.attrib][item.name] <= 0 then
- kaiUI.itemsSorted[item.attrib][item.name] = nil
- end
- end
- return
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement