Deck Creation Macro

I created a macro to fill out a 52-card deck, you set the ID of the deck and the base URL of the folder where your card images are stored, and then run it.
/* --------------- Settings --------------- */

let deckId = "nHMEqy7N7gna2X3w";
let baseUrl = "cards/dark-gold/";

/* --------------- Script --------------- */

let deck = game.cards.get(deckId);

let suits = ["Spades", "Clubs", "Hearts", "Diamonds"];
let names = ["Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"];

for (let suit of suits) {
let value = 1;

for (let name of names) {
let cName = "";
let sName = suit.toLowerCase();

if (value > 1 && value < 11) cName = value.toString().padStart(2, "0");
else cName = name.toLowerCase();

let fileName = `${baseUrl}${sName}-${cName}.webp`;
let cardName = `${name} of ${suit}`;

console.log(value, cardName, fileName);

await Card.create({
name: cardName, suit: suit, type: "base", origin: deck.id, value,
faces: [{
img: fileName,
name: cardName
}]
}, { parent: deck }
);

value++;
}
}
/* --------------- Settings --------------- */

let deckId = "nHMEqy7N7gna2X3w";
let baseUrl = "cards/dark-gold/";

/* --------------- Script --------------- */

let deck = game.cards.get(deckId);

let suits = ["Spades", "Clubs", "Hearts", "Diamonds"];
let names = ["Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"];

for (let suit of suits) {
let value = 1;

for (let name of names) {
let cName = "";
let sName = suit.toLowerCase();

if (value > 1 && value < 11) cName = value.toString().padStart(2, "0");
else cName = name.toLowerCase();

let fileName = `${baseUrl}${sName}-${cName}.webp`;
let cardName = `${name} of ${suit}`;

console.log(value, cardName, fileName);

await Card.create({
name: cardName, suit: suit, type: "base", origin: deck.id, value,
faces: [{
img: fileName,
name: cardName
}]
}, { parent: deck }
);

value++;
}
}
Note: You should set the background image and name of the deck before running this so that the card backs will be correct.
1 Reply
zeel
zeelOP4y ago
Pro Tip: Don't have the deck application open when you do this, and it will happen much faster.
Want results from more Discord servers?
Add your server