Here's a script that will do it. Just run: !number-npcs It will append a number to the end of each NPC on a page where there are more than one representing a given character. NPC is determined as: A Token Represents a Character The Character is not controlled by anyone. Code: on('ready',() => {
const getPageForPlayer = (playerid) => {
let player = getObj('player',playerid);
if(playerIsGM(playerid)){
return player.get('lastpage');
}
let psp = Campaign().get('playerspecificpages');
if(psp[playerid]){
return psp[playerid];
}
return Campaign().get('playerpageid');
};
on('chat:message', msg=>{
if('api'===msg.type && /^!number-npcs(\b\s|$)/i.test(msg.content) && playerIsGM(msg.playerid)){
let who = (getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname');
sendChat('',`/w "${who}" Renumbering all NPCs...`);
let count = 0;
let args = msg.content.split(/\s+--/).map(s=>s.toLowerCase());
let props = {
type:'graphic'
};
if(args.includes('current-page')){
props.pageid = getPageForPlayer(msg.playerid);
}
let tokenData = findObjs(props)
.map((o)=>({
token:o,
character:getObj('character',o.get('represents'))
}))
.filter(o=>undefined!==o.character)
.filter(o=>''===o.character.get('controlledby'))
.reduce((m,o)=>{
let pageid=o.token.get('pageid');
m[pageid]=m[pageid]||{};
m[pageid][o.character.id]=m[pageid][o.character.id]||[];
m[pageid][o.character.id].push(o);
return m;
},{})
;
let pageIDs = Object.keys(tokenData);
const burndown1 = () =>{
let pid = pageIDs.shift();
if(pid){
let pageData = tokenData[pid];
let charIDs = Object.keys(pageData);
const burndown2 = ()=>{
let charID = charIDs.shift();
if(charID){
let n = 0;
let charData = pageData[charID];
if(charData.length>1){
charData.forEach(o=>o.token.set({ name: `${o.character.get('name')} ${++n}`}));
count += charData.length;
}
setTimeout(burndown2,0);
} else {
setTimeout(burndown1,0);
}
};
setTimeout(burndown2,0);
} else {
sendChat('',`/w "${who}" Renumbered <code>${count}</code> NPCs.`);
}
};
setTimeout(burndown1,0);
}
});
});
Edit: Updated with an option to only renumber the current page: !number-npcs --current-page