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 .
×
Create a free account

[Script] TokenNumberName - reset numbering?

I just stumbled across this script and am very excited to try this out.  I think I got everything updated on my tokens, but had a question on the numbering. Is there any way to "reset" the numbering based on different rooms?  I have a pretty large dungeon map for Tyranny of Dragons with multiple rooms.  There are three different rooms on the map each with a handful of kobolds.  Can I reset the numbering back to 1 somehow for each room?  Otherwise, room 3 has Kobold 19, Kobold 20, etc.  
1622355512

Edited 1622355581
vÍnce
Pro
Sheet Author
I think TokenNameNumber is page-based (meaning it's going to compare all token names found on a given page)... I don't think there's a reset option. Might be a cool feature. You might try changing the names of kobolds in a given room to include the room number.  ie "Kobold_20 %%NUMBERED%%" for room 20.  or "Kobold_29 %%NUMBERED%%" for room 29. etc. If I recall, there are a couple options for the script that can assign random numbers or colored dots as well.  I liked the random seed so players never had an idea how many enemy were actually in the encounter. ;-)
1622479272
The Aaron
Roll20 Production Team
API Scripter
Give this a whirl, it will renumber any selected tokens.  Tokens that represent a character will get the character name + a monotonically increasing integer value appended.  Tokens that don't represent a character will get their current name with any trailing number removed and a monotonically increasing integer value appended.  You can set a starting number by adding it as an argument.  Each subset will start number with that number: Calling it: !renumber-selected Calling with a different base number: !renumber-selected 100 Code: on('ready',()=>{ on('chat:message',msg=>{ if('api'===msg.type && /^!renumber-selected(\b\s|$)/i.test(msg.content) && playerIsGM(msg.playerid)){ let args = msg.content.split(/\s+/); let numBase = (parseInt(args[1])||1)-1; let tcmap = (msg.selected || []) .map(o=>getObj('graphic',o._id)) .filter(g=>undefined !== g) .reduce((m,t)=>{ const rep=t.get('represents')||'%%NOCHAR%%'; m[rep]=m[rep]||[]; m[rep].push(t); return m; },{}); Object.keys(tcmap).forEach( c => { let ts = tcmap[c]; let n = numBase; let numer = (t) => { let baseName = t.get('name').replace(/\s+\d*$/,''); t.set('name', `${baseName} ${++n}`); }; if('%%NOCHAR%%' !== c){ // number character tokens let character = getObj('character',c); if(c) { numer = (t) => { t.set('name', `${character.get('name')} ${++n}`); }; } } ts.forEach(numer); }); } }); });
1622492232
vÍnce
Pro
Sheet Author
Nice!
Brilliant!  This works perfectly.  Awesome.  Thanks The Aaron! The Aaron said: Give this a whirl, it will renumber any selected tokens.  Tokens that represent a character will get the character name + a monotonically increasing integer value appended.  Tokens that don't represent a character will get their current name with any trailing number removed and a monotonically increasing integer value appended.  You can set a starting number by adding it as an argument.  Each subset will start number with that number:
1622572212
The Aaron
Roll20 Production Team
API Scripter
No problem! =D