SCED/src/playermat/ClueCounter.ttslua
2024-06-23 19:49:56 +02:00

56 lines
1.5 KiB
Plaintext

local guidReferenceApi = require("core/GUIDReferenceApi")
local playermatApi = require("playermat/PlayermatApi")
local searchLib = require("util/SearchLib")
exposedValue = 0
local playermat
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 playermat
local matColor = playermatApi.getMatColorByPosition(self.getPosition())
playermat = guidReferenceApi.getObjectByOwnerAndType(matColor, "Playermat")
-- get search parameters (threat area excluded)
local localPos = playermat.positionToLocal(playermat.getPosition())
searchParam.pos = playermat.positionToWorld(localPos + Vector(0, 0, 0.4))
searchParam.rot = playermat.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 playermat
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