SCED/src/core/DoomInPlayCounter.ttslua

106 lines
3.2 KiB
Plaintext
Raw Normal View History

2022-11-12 11:27:59 +01:00
-- Doom-in-Play Counter
-- made by: Chr1Z
-- description: counts the doom tokens in play periodically (excluding the agenda), ignores objects with specified tag
information = {
version = "1.1",
last_updated = "12.11.2022"
}
-- common parameters
local CAST_PARAMETERS = {}
CAST_PARAMETERS.direction = { 0, 1, 0 }
CAST_PARAMETERS.type = 3
CAST_PARAMETERS.max_distance = 0
local ypos = 1.6
local zone = getObjectFromGUID("a2f932")
local doom_url = "https://i.imgur.com/EoL7yaZ.png"
local IGNORE_TAG = "DoomCounter_ignore"
-- playermats 1 to 4
local originAndSize = {
{ origin = { -55, ypos, 16.5 }, size = { 12, 1, 25 } },
{ origin = { -55, ypos, -16.5 }, size = { 12, 1, 25 } },
{ origin = { -25, ypos, 27 }, size = { 25, 1, 12 } },
{ origin = { -25, ypos, -27 }, size = { 25, 1, 12 } }
}
-- create button, context menu and start loop
function onLoad()
self.createButton({
2022-11-12 11:27:59 +01:00
label = tostring(0),
click_function = "moreInformation",
function_owner = self,
position = { 0, 0.06, 0 },
height = 600,
width = 1000,
scale = { 1.5, 1.5, 1.5 },
font_size = 600,
font_color = { 1, 1, 1, 100 },
color = { 0, 0, 0, 0 }
})
-- context menu
self.addContextMenuItem("More Information", moreInformation)
self.addContextMenuItem("Remove Doom", function()
removeDoom = true
Wait.stop(loopID)
countDoom()
Wait.time(function()
removeDoom = false
loopID = Wait.time(countDoom, 2, -1)
end, 2)
end)
loopID = Wait.time(countDoom, 2, -1)
end
2022-11-12 11:27:59 +01:00
function moreInformation()
printToAll("------------------------------", "White")
printToAll("Doom-in-Play Counter v" .. information["version"] .. " by Chr1Z", "Orange")
printToAll("last updated: " .. information["last_updated"], "White")
printToAll("Automatically counts the doom in play (exluding the agenda and objects with the ignore tag).", "Green")
printToAll("ignore tag: " .. IGNORE_TAG, "White")
end
2022-11-12 11:27:59 +01:00
-- main function
function countDoom()
local doom = 0
for i = 1, 5 do doom = doom + search(i) end
self.editButton({ index = 0, label = tostring(doom) })
end
2022-11-12 11:27:59 +01:00
-- searches playermats (num = 1-4) or the scripting zone (num = 5)
function search(num)
local val = 0
if num == 5 then
for _, obj in ipairs(zone.getObjects()) do
val = val + getResult(obj)
end
else
CAST_PARAMETERS.origin = originAndSize[num].origin
CAST_PARAMETERS.size = originAndSize[num].size
2022-11-12 11:27:59 +01:00
for _, obj in ipairs(Physics.cast(CAST_PARAMETERS)) do
val = val + getResult(obj.hit_object)
end
end
2022-11-12 11:27:59 +01:00
return val
end
2022-11-12 11:27:59 +01:00
-- checks an object for the doom image and gets quantity (for stacks)
function getResult(obj)
if (obj.is_face_down and obj.getCustomObject().image_bottom == doom_url) or
(obj.name == "Custom_Token" and obj.getCustomObject().image == doom_url) then
if not obj.hasTag(IGNORE_TAG) then
if removeDoom then
obj.destruct()
return 0
else
return math.abs(obj.getQuantity())
end
end
end
return 0
end