Tabletop Simulator – Lua Script (2023)

Introduction

Developed by the ingenious mind behind Dimension Beyond, this script introduces groundbreaking features to objects tagged with the mystical “Thoughtform.”

Delving into the Enchantment

Automatic Scaling – Unveiling Visibility

One of the script’s enchanting features is automatic scaling. When objects adorned with the “Thoughtform” tag grace your tabletop, they undergo a transformation, scaling up for enhanced visibility. The magic behind this lies in the following snippet:

-- Inside onObjectEnterZone(zone, obj)
if obj.tag == "Deck" or obj.tag == "Card" or obj.tag == "Token" and hasTag(zone.getTags(), "Table") then
    originalScales[obj] = obj.getScale()
    local scale = { x = scalingFactor, y = 1, z = scalingFactor }
    obj.setScale(scale)
end

Here, as an object enters a specific zone, its original scale is stored, and a new scale is applied based on the defined scalingFactor.

Health Points Management – The Pulse of the Game

Thoughtform Summoner simplifies health points management with intuitive buttons. The following snippets handle the logic behind adjusting and displaying health points:

-- Inside onPlusButtonClick(obj)
local currentHP = obj.getVar("currentHP") or 0
obj.setVar("currentHP", currentHP + 1)
onUpdateCounterDisplay(obj)
-- Inside onMinusButtonClick(obj)
local currentHP = obj.getVar("currentHP") or 0
obj.setVar("currentHP", currentHP - 1)
onUpdateCounterDisplay(obj)
-- Inside onUpdateCounterDisplay(obj)
local currentHP = obj.getVar("currentHP")
if currentHP then
    local buttonIndex = 2
    local button = obj.getButtons()[buttonIndex]

    if button then
        button.label = "HP: " .. currentHP
        obj.editButton({
            index = buttonIndex,
            label = button.label,
        })
    end
end

These snippets showcase the logic for increasing, decreasing, and updating the health points display.

Stall and Equip Controls – Ready or Not

Thoughtform Summoner introduces buttons for toggling between “Ready” and “Stall” states and managing equipment. The snippet below handles the toggle logic:

-- Inside onChangeStall(obj)
local stall = obj.getVar("stall") or false

if stall then
    obj.editButton({
        index = 3,
        label = "S T A L L",
        color = {252/255, 215/255, 3/255},
    })
    obj.setVar("stall", false)
else
    obj.editButton({
        index = 3,
        label = "R E A D Y",
        color = {90/255, 252/255, 3/255},
    })
    obj.setVar("stall", true)
end

This snippet showcases the toggle logic between “Stall” and “Ready” states.

Duplicate Placement – Crafting Clones

The script introduces a fascinating feature where picking up objects creates duplicates arranged in a grid. Dropping the object gracefully disposes of these duplicates. The magic happens in the following snippet:

-- Inside onObjectPickUp(player_color, picked_up_object)
-- ... (previous code)
for i = 1, numRows do
    for j = 1, numCols do
        if cellSelection[i][j] then
            local offsetX = (j - math.ceil(numCols / 2)) * spacing * 0.78
            local offsetZ = (i - math.ceil(numRows / 2)) * spacing * 1.15

            local duplicate, offset = createDuplicate(picked_up_object, pos.x + offsetX, pos.y + yOffset, pos.z + offsetZ, spacing)
            table.insert(duplicatesTable, { duplicate = duplicate, offset = offset, originalObject = picked_up_object })
        end
    end
end

This snippet captures the creation of duplicates, each intelligently positioned in a grid around the original object.

createDuplicate(originalObject, x, y, z, scaleFactor)

This function is the architect behind the creation of duplicates. Let’s break down its key components:

  • originalObject: The object from which duplicates will be created.
  • x, y, z: The specified position for the new duplicate.
  • scaleFactor: The factor by which the duplicate is scaled in comparison to the original.

Inside this function, a clone of the original object is created with the specified position and scaling. The clone is named appropriately and marked as a duplicate.

function createDuplicate(originalObject, x, y, z, scaleFactor)
    local rangeind = getObjectFromGUID("193593")
    local duplicate = rangeind.clone({ position = { x, y, z} })
    duplicate.setName(rangeind.getName() .. "_duplicate")
    duplicate.setLock(true)
    duplicate.setVar("isDuplicate", true)

    local originalPos = originalObject.getPosition()

    local offset = {
        x = (x - originalPos.x) * scaleFactor,
        y = (y - originalPos.y) * scaleFactor,
        z = (z - originalPos.z) * scaleFactor
    }

    return duplicate, offset
end

Here, the clone is intelligently named, locked to prevent unintended interactions, and marked as a duplicate. The offset is calculated based on the original and duplicate positions, facilitating precise positioning.

Unveiling the Source

For a deeper understanding and to harness the full power of Thoughtform Summoner, explore the complete Lua script on the GitHub repository. Feel free to contribute, provide feedback, or weave your own magic into the script.

Enhance your Tabletop Simulator adventures with the enchanting Thoughtform Summoner Lua script!


Feel free to adapt and customize the content further based on your preferences and specific details you want to highlight.