#Layout Zone Script for creating deck when card added but only for specific tagged cards

1 messages · Page 1 of 1 (latest)

muted garnet
#
-- Table to hold the cards with the "Pokemon" tag
local pokemonCards = {}

-- This function is called when an object is added to the Layout Zone
function onObjectAddedToZone(zone, object)
    -- Check if the object has the "Pokemon" tag
    if object.has Tag("Pokemon") then
        -- Add the card to the pokemonCards table
        table.insert(pokemonCards, object)
        print("Evolved Pokemon card to deck: " .. object.getName())
    end
end

-- create a deck from the Pokemon cards
function createDeck()
    if #pokemonCards == 0 then
        print("No 'Pokemon' cards in the zone.")
        return
    end

    -- Prepare deck data
    local deckData = {}
    for _, card in ipairs(pokemonCards) do
        table.insert(deckData, {guid = card.getGUID()})
    end

    -- Spawn a new deck with the cards
    spawnObject({
        type = "Deck",
        position = {x = 0, y = 1, z = 0},  --  adjust the position
        rotation = {x = 0, y = 0, z = 0},  -- Adjust rotation
        scale = {x = 1, y = 1, z = 1},     -- Adjust scale
        deck = deckData,
        callback_function = function(deck)
            print("Pokemon Deck Created Successfully!")
        end
    })
end

-- This function checks if the Layout Zone has been set up and starts monitoring for new objects
function onLoad()
    print("Script loaded: Waiting for Pokemon cards to be added to the Layout Zone.")
end```
tepid narwhal
#

check the pinned comment for how to format code in Discord correctly

muted garnet
tepid narwhal
#

you still haven't, the code will change colour when you have it correctly

tepid narwhal
#

there are few things I do not give advice on in TTS because they are more trouble than they are worth. One of these things are layout zones. I wish you luck finding a reliable solution.

muted garnet
tepid narwhal
#

they are unreliable, often unpredictable, and I refuse to use them because of this

upper barn
#

I'd recommend a combination of tryObjectEnterContainer and using .takeObject() inside of onObjectSpawn to control what is allowed to stack into a deck and where "unstacked" cards should be placed.

upper barn
#

This is a bit more advanced, but instead of physically layering the cards like that, you could also look into letting them stack and creating XML 'icons' to track attached Energy.

Would be pretty trivial scripting to make non-Pokémon automatically move to the "bottom" of the deck as well.