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
|
2022-11-12 13:51:43 +01:00
|
|
|
local castParameters = {}
|
|
|
|
castParameters.direction = { 0, 1, 0 }
|
|
|
|
castParameters.type = 3
|
|
|
|
castParameters.max_distance = 0
|
2022-11-12 11:27:59 +01:00
|
|
|
|
|
|
|
local zone = getObjectFromGUID("a2f932")
|
|
|
|
local doom_url = "https://i.imgur.com/EoL7yaZ.png"
|
|
|
|
local IGNORE_TAG = "DoomCounter_ignore"
|
|
|
|
|
|
|
|
-- playermats 1 to 4
|
|
|
|
local originAndSize = {
|
2022-11-12 13:51:43 +01:00
|
|
|
{ origin = { -55, 1.6, 16.5 }, size = { 12, 1, 25 } },
|
|
|
|
{ origin = { -55, 1.6, -16.5 }, size = { 12, 1, 25 } },
|
|
|
|
{ origin = { -25, 1.6, 27 }, size = { 25, 1, 12 } },
|
|
|
|
{ origin = { -25, 1.6, -27 }, size = { 25, 1, 12 } }
|
2022-11-12 11:27:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
-- create button, context menu and start loop
|
|
|
|
function onLoad()
|
2021-10-06 20:37:31 -07:00
|
|
|
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()
|
|
|
|
Wait.stop(loopID)
|
2022-11-12 13:51:43 +01:00
|
|
|
removeDoom = true
|
2022-11-12 11:27:59 +01:00
|
|
|
countDoom()
|
|
|
|
Wait.time(function()
|
|
|
|
removeDoom = false
|
|
|
|
loopID = Wait.time(countDoom, 2, -1)
|
|
|
|
end, 2)
|
|
|
|
end)
|
|
|
|
|
|
|
|
loopID = Wait.time(countDoom, 2, -1)
|
2021-10-06 20:37:31 -07:00
|
|
|
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")
|
2021-10-06 20:37:31 -07:00
|
|
|
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) })
|
2021-10-06 20:37:31 -07:00
|
|
|
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
|
2022-11-12 13:51:43 +01:00
|
|
|
val = val + isDoom(obj)
|
2022-11-12 11:27:59 +01:00
|
|
|
end
|
|
|
|
else
|
2022-11-12 13:51:43 +01:00
|
|
|
castParameters.origin = originAndSize[num].origin
|
|
|
|
castParameters.size = originAndSize[num].size
|
2021-10-06 20:37:31 -07:00
|
|
|
|
2022-11-12 13:51:43 +01:00
|
|
|
for _, obj in ipairs(Physics.cast(castParameters)) do
|
|
|
|
val = val + isDoom(obj.hit_object)
|
2022-11-12 11:27:59 +01:00
|
|
|
end
|
2022-10-25 00:36:45 -07:00
|
|
|
end
|
2022-11-12 11:27:59 +01:00
|
|
|
return val
|
2022-10-25 00:36:45 -07:00
|
|
|
end
|
|
|
|
|
2022-11-12 11:27:59 +01:00
|
|
|
-- checks an object for the doom image and gets quantity (for stacks)
|
2022-11-12 13:51:43 +01:00
|
|
|
function isDoom(obj)
|
2022-11-12 11:27:59 +01:00
|
|
|
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
|
2021-10-06 20:37:31 -07:00
|
|
|
end
|