SCED/src/playermat/ClueCounter.ttslua

56 lines
1.5 KiB
Plaintext
Raw Normal View History

2024-02-13 12:04:29 +01:00
local guidReferenceApi = require("core/GUIDReferenceApi")
local playmatApi = require("playermat/PlaymatApi")
2023-12-11 18:11:04 +01:00
local searchLib = require("util/SearchLib")
2024-02-13 12:04:29 +01:00
2022-12-08 12:46:22 +01:00
exposedValue = 0
2024-02-13 12:04:29 +01:00
local playmat
2024-02-17 01:31:08 +01:00
local searchParam = {}
2024-02-13 12:04:29 +01:00
function onLoad()
2022-12-08 12:46:22 +01:00
self.createButton({
label = "",
2023-10-02 13:51:10 +02:00
click_function = "countItems",
2022-12-08 12:46:22 +01:00
function_owner = self,
position = { 0, 0.1, 0 },
height = 0,
width = 0,
font_color = { 0, 0, 0 },
font_size = 2000
})
2024-02-13 12:04:29 +01:00
-- get closest playmat
local matColor = playmatApi.getMatColorByPosition(self.getPosition())
playmat = guidReferenceApi.getObjectByOwnerAndType(matColor, "Playermat")
2024-02-17 01:31:08 +01:00
-- 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"
2024-02-13 12:04:29 +01:00
-- start loop
Wait.time(countItems, 1.5, -1)
end
2024-02-13 12:04:29 +01:00
-- activated once per second, counts clues on the playmat
function countItems()
local totalValue = 0
2023-12-11 18:11:04 +01:00
for _, item in ipairs(getClues()) do
totalValue = totalValue + math.abs(item.getQuantity())
2022-12-08 12:46:22 +01:00
end
exposedValue = totalValue
self.editButton({ index = 0, label = totalValue })
end
2023-10-02 13:51:10 +02:00
function removeAllClues(trash)
2023-12-11 18:11:04 +01:00
for _, obj in ipairs(getClues()) do
2023-10-02 13:51:10 +02:00
trash.putObject(obj)
end
2023-12-11 18:11:04 +01:00
end
function getClues()
2024-02-17 01:31:08 +01:00
return searchLib.inArea(searchParam.pos, searchParam.rot, searchParam.size, searchParam.filter)
2023-12-11 18:11:04 +01:00
end