local guidReferenceApi = require("core/GUIDReferenceApi") local playmatApi = require("playermat/PlaymatApi") local searchLib = require("util/SearchLib") exposedValue = 0 local playmat local searchParam = {} function onLoad() self.createButton({ label = "", click_function = "countItems", function_owner = self, position = { 0, 0.1, 0 }, height = 0, width = 0, font_color = { 0, 0, 0 }, font_size = 2000 }) -- get closest playmat local matColor = playmatApi.getMatColorByPosition(self.getPosition()) playmat = guidReferenceApi.getObjectByOwnerAndType(matColor, "Playermat") -- get search parameters (threat area excluded) local localPos = playmat.positionToLocal(playmat.getPosition()) searchParam.pos = playmat.positionToWorld(localPos + Vector(0, 0, 0.4)) searchParam.rot = playmat.getRotation() + Vector(0, 90, 0) searchParam.size = Vector(8, 1, 27) searchParam.filter = "isClue" -- start loop Wait.time(countItems, 1.5, -1) end -- activated once per second, counts clues on the playmat function countItems() local totalValue = 0 for _, item in ipairs(getClues()) do totalValue = totalValue + math.abs(item.getQuantity()) end exposedValue = totalValue self.editButton({ index = 0, label = totalValue }) end function removeAllClues(trash) for _, obj in ipairs(getClues()) do trash.putObject(obj) end end function getClues() return searchLib.inArea(searchParam.pos, searchParam.rot, searchParam.size, searchParam.filter) end