WebSocket Example for Carl Davis's Dice Rollers

Sample Scripts!

This script zooms in on the selected token. Change the zoom value to also zoom out if that is the desired affect. Great for rapidly jumping around the field of play!

const zoomLevel = 1.5; // Change this value to set the zoom level // Center on the currently selected token, or center of the scene if no token is selected const selectedToken = canvas.tokens.controlled[0]; const { x, y } = selectedToken ? selectedToken.center : canvas.scene.center; canvas.animatePan({ x, y, scale: zoomLevel, duration: 500 }); // Zoom in with smooth animation ui.notifications.info(`Zoomed in to ${zoomLevel * 100}%`);

This macro moves a token to a new location. I do not like deleting small support monster's tokens on the map because they might be the one defining turn order... so I just move them to the corner of the screen.

// Check if a token is selected const selectedToken = canvas.tokens.controlled[0]; if (!selectedToken) { ui.notifications.warn("Please select a token first."); } else { // Get the canvas height and calculate the target position const canvasHeight = canvas.dimensions.height; const canvasWidth = canvas.dimensions.width; const tokenHeight = selectedToken.document.height * canvas.grid.size; // Calculate new y-coordinate to move the token to the top of the screen const newY = tokenHeight / 2; const newX = tokenHeight / 2; // Update token position selectedToken.document.update({ y: newY, x: newX }); ui.notifications.info("Token moved to the top of the screen."); }

Finally, this one brings up the charcter sheet for the selected token.

// Check if a token is selected const selectedToken = canvas.tokens.controlled[0]; if (!selectedToken) { ui.notifications.warn("Please select a token first."); } else { // Get the actor associated with the selected token const actor = selectedToken.actor; if (actor) { // Render the actor's sheet actor.sheet.render(true); ui.notifications.info(`Opening ${actor.name}'s character sheet.`); } else { ui.notifications.warn("Selected token has no associated actor."); } }
About This Page

This page contains some sample scripts that might be useful to use with the FoundryVTT Macro Runner for the Stream Deck. Anything you can do in a script you can execute and here are a few samples that show the power!