Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×

[Script] Link Selected Tokens Link multiple tokens to one character sheet

1794862671
Surok
Pro
API Scripter
Link Selected Token Link multiple tokens to one character sheet This small script lets you link multiple selected tokens to the same character sheet in your journal with a single command. It’s especially useful when the tokens use different artwork but share the same stat block . For example, you might want a town square full of commoners with different appearances. Instead of opening every token individually and setting Represents Character to your Commoner sheet, you can select them all and link them at once. What it does The script sets each selected token’s Represents Character field to the sheet you specify. It only changes that association. It does not modify the character sheet, copy default-token settings, change artwork, rename tokens, or configure their bars. Installation Add the script to your game’s Mod/API script editor. Save the script. Create a macro named Link-Sheet with this command: !link-sheet ?{Character sheet name} Check Show as Token Action for convenient access when tokens are selected. How to use it Place your tokens on the map. Select all the tokens you want to link. Click Link-Sheet . Enter the name of the character sheet in your journal. Click Submit . For the commoner example, enter Commoner . All selected tokens will now represent that sheet while keeping their individual artwork. You can also skip the prompt and type a name directly into chat: !link-sheet Commoner Names containing spaces work without quotation marks: !link-sheet Veteran Guard Matching and safeguards Use the full character sheet name, not a journal folder name or token name. Matching ignores capitalization and spaces at the beginning or end. If no matching sheet exists, the script reports the problem and changes nothing. If multiple sheets have the same matching name, give the intended sheet a unique name and try again. Tokens already linked to the requested sheet are left alone. Only GMs can run the command. This is useful for crowds, guards, bandits, nobles, or any group where you want visual variety without assigning the same sheet to each token individually. /* LinkSelectedTokens v1.1 — GM only * Only sets Represents Character. * Does not modify sheets, bars, or other token settings. */ (function () { 'use strict'; function escapeHTML(value) { return String(value).replace(/[&<>"']/g, function (c) { return { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]; }); } function report(text) { sendChat( 'Link Selected Tokens', '/w gm ' + escapeHTML(text), null, {noarchive: true} ); } on('chat:message', function (msg) { if (msg.type !== 'api' || !/^!link-sheet(?:\s|$)/i.test(msg.content)) return; if (!playerIsGM(msg.playerid)) return; var name = msg.content.replace(/^!link-sheet\s*/i, '').trim(); if (!name) { report( 'Use this macro to open the name prompt: ' + '!link-sheet ?{Character sheet name|Noble}' ); return; } var seen = {}; var tokens = (msg.selected || []).filter(function (s) { if (s._type !== 'graphic' || seen[s._id]) return false; seen[s._id] = true; return true; }).map(function (s) { return getObj('graphic', s._id); }).filter(function (t) { return t && t.get('_subtype') === 'token' && !t.get('isdrawing'); }); if (!tokens.length) { report('Select one or more tokens first.'); return; } var matches = findObjs({_type: 'character'}).filter(function (c) { return String(c.get('name') || '').trim().toLowerCase() === name.toLowerCase(); }); if (!matches.length) { report( 'No character sheet named "' + name + '". No tokens changed.' ); return; } if (matches.length > 1) { report( 'Multiple sheets named "' + name + '". Give the intended sheet a unique name and retry. ' + 'No tokens changed.' ); return; } var character = matches[0]; var changed = 0; tokens.forEach(function (token) { if (token.get('represents') === character.id) return; token.set('represents', character.id); changed += 1; }); report( 'Linked ' + changed + ' token(s) to "' + character.get('name') + '".' + (tokens.length > changed ? ' ' + (tokens.length - changed) + ' already linked.' : '') ); }); }());
Nice, testing it in game to see if it conflicts with anything else I am using.
If you're already running the token-mod script, I believe !token-mod --set represents|Commoner should work as well, and save having to have another script in place.    
Very true, while writing a Token-Mod script to link and then unlink bars I noticed that after it was right in my face.