Skip to content

Instantly share code, notes, and snippets.

@mythmon
Last active May 20, 2020 12:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mythmon/52950a9c9c75788a88d909d40082aef9 to your computer and use it in GitHub Desktop.
Save mythmon/52950a9c9c75788a88d909d40082aef9 to your computer and use it in GitHub Desktop.
Scripting for Azul in Table Top Simulator
drawBag = nil
discardBags = nil
recallButton = nil
factories = nil
setupButtons = nil
function loadObjects()
allTableZone = getObjectFromGUID("ee6f5f")
recallButton = getObjectFromGUID("49aa6a")
drawBag = getObjectFromGUID("d101ec")
discardBags = {}
factories = {}
setupButtons = {
twoPlayers = getObjectFromGUID("164a47"),
threePlayers = getObjectFromGUID("248097"),
fourPlayers = getObjectFromGUID("10eb79"),
}
for _, obj in pairs(getAllObjects()) do
if (obj.getName() == "Factory") then table.insert(factories, obj) end
if (obj.getName() == "Discard") then table.insert(discardBags, obj) end
end
end
function onLoad()
loadObjects()
-- Setup recall button to move all tiles from discard bags to draw bag
recallButton.createButton({
click_function = 'recallAllTiles',
label = "Recall",
function_owner = self,
position = {0, 0.14, 0},
rotation = {0, 0, 0},
width = 1400,
height = 900,
font_size = 500,
})
-- Setup factories
for i, factory in pairs(factories) do
-- snap all factories to the same location, because i'm too lazy to do it in-game
factory.setPosition({-12, factory.getPosition().y, 24})
factory.setSnapPoints(
{ position = {2.3, 0.0, 0}, rotation = {0,0,0}, rotation_snap = true },
{ position = {-2.3, 0.0, 0}, rotation = {0,0,0}, rotation_snap = true },
{ position = {0, 0.0, 2.3}, rotation = {0,0,0}, rotation_snap = true },
{ position = {0, 0.0, -2.3}, rotation = {0,0,0}, rotation_snap = true }
)
end
-- Setup gameSetup buttons to trigger game start for N players
setupButtons.twoPlayers.createButton({
click_function = 'setupGameTwoPlayers',
label = "2 Players",
function_owner = self,
position = {0, 0.14, 0},
rotation = {0, 0, 0},
width = 3500,
height = 1200,
font_size = 800,
})
setupButtons.threePlayers.createButton({
click_function = 'setupGameThreePlayers',
label = "3 Players",
function_owner = self,
position = {0, 0.14, 0},
rotation = {0, 0, 0},
width = 3500,
height = 1200,
font_size = 800,
})
setupButtons.fourPlayers.createButton({
click_function = 'setupGameFourPlayers',
label = "4 Players",
function_owner = self,
position = {0, 0.14, 0},
rotation = {0, 0, 0},
width = 3500,
height = 1200,
font_size = 800,
})
end
function recallAllTiles()
local delayDelta = 0.1
for _, bag in pairs(discardBags) do
local delay = 0
for _, tile in pairs(bag.getObjects()) do
Wait.time(function()
local drawBagPosition = drawBag.getPosition()
local spread = 2
local target_position = {
x = drawBagPosition.x + math.random(-spread, spread),
y = drawBagPosition.y + 5,
z = drawBagPosition.z + math.random(-spread, spread),
}
local target_rotation = {
x = math.random(0, 360),
y = math.random(0, 360),
z = math.random(0, 360),
}
bag.takeObject({
position = target_position,
rotation = target_rotation,
guid = tile.guid,
callback_function = function(tile2) drawBag.putObject(tile2) end
})
end, delay)
delay = delay + delayDelta
end
end
end
function setupGameTwoPlayers()
setupGame({ players = 2 })
end
function setupGameThreePlayers()
setupGame({ players = 3 })
end
function setupGameFourPlayers()
setupGame({ players = 4 })
end
function setupGame(opts)
local numFactories = 1 + opts.players * 2
local delay = 0
local delayDelta = 0.1
local radius = 15
for i = numFactories, 1, -1 do
local theta = (i - 1) / numFactories * math.pi * 2 + 0.34
local position = {
x=math.cos(theta) * radius,
y = 7,
z = math.sin(theta) * radius - 10,
}
Wait.time(|| factories[i].setPositionSmooth(position), delay)
delay = delay + delayDelta
end
delay = 0
if numFactories < 9 then
for i = (numFactories + 1), 9 do
Wait.time(|| factories[i].setPositionSmooth({-12, 4 + (i - numFactories) * 0.6, 24}), delay)
delay = delay + delayDelta
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment