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

Token Rename and Renumber Script

1462032002

Edited 1462035639
Token Rename and Renumber Script This script renames and renumbers all the tokens you have selected when it is executed. I made this script because I got fed up of having to rename large numbers of identical tokens at once, which can get very tedious. To use the script select a load of tokens that you want to have a series name and type "!RN Goblin" for example into the chat window. The tokens will be renamed as Goblin 1, Goblin 2, etc. To start from a specific index type "!RN Goblin 6" for example. The tokens will be renamed as Goblin 6, Goblin 7, etc. The numbering is ordered from the top of the page to bottom, and if the top positions of two tokens tie, then the left properties of the token is used to decide the numbering order. You can only run the renumbering script as GM for safety reasons.  See updated script below
1. You have a command in there !sr that doesn't have anything to do with renumbering tokens. It might conflict with some other script. 2. There is a built-in function to check for GM status now that does not rely on using their display name (which players can totally add (GM) to their name to get around your script restriction. I linked to the wiki for the playerIsGM() function: <a href="https://wiki.roll20.net/API:Utility_Functions#Play" rel="nofollow">https://wiki.roll20.net/API:Utility_Functions#Play</a>...
I have removed the ref to !sr, sorry this got left in as I copied the on chat function from an onchat template function code. I will look at the playerIsGM function. Thanks.
1462035588

Edited 1462047588
UPDATED SCRIPT //QUICKLY RENAME AND RENUMBER SELECTED TOKENS //WRITTEN BY JACK TAYLOR 30/4/2016 FOR ROLL20 SCRIPT ENGINE function rename_ordered(f,sl) { &nbsp; &nbsp; var i,c,r,k,l,lp,rp; &nbsp; &nbsp; var k = 1; &nbsp; &nbsp; var token,ref,ta,nn; &nbsp; &nbsp; if(sl) &nbsp; &nbsp; { &nbsp; &nbsp; var dex = 1; &nbsp; &nbsp; lp=f; &nbsp; &nbsp; f = f.trim(); &nbsp; &nbsp; g= f.lastIndexOf(" "); &nbsp; &nbsp; l= f.length; &nbsp; &nbsp; if(g&gt;0) &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; z=l-g-1; &nbsp; &nbsp; &nbsp; &nbsp; rp = f.substr(g+1,z); &nbsp; &nbsp; &nbsp; &nbsp; dex = parseInt(rp); &nbsp; &nbsp; &nbsp; &nbsp; if(!isNaN(dex)) &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lp=f.substr(0,g); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; } &nbsp; &nbsp; c = sl.length; &nbsp; &nbsp; &nbsp;if(c&gt;0) &nbsp; &nbsp; { &nbsp; &nbsp; for(i=0;i&lt;c;i++) &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; ref = sl[i]; &nbsp; &nbsp; &nbsp; &nbsp; if(ref["_type"]=="graphic") &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//if(ref["subtype"]=="token") &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;token = getObj("graphic",ref["_id"]); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(token) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(ta) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;d = ta.length; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var tt = token.get("top"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var flag = false; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for(j=0;j&lt;d;j++) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var tat = ta[j].get("top"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(tt&lt;=tat) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(tt!=tat) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ta.splice(j,0,token); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;flag=true; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}else{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tl = token.get("left"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tal = ta[j].get("left"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(tl&lt;tal) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ta.splice(j,0,token); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; flag = true; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(!flag) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ta.push(token); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ta=[token]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp; &nbsp; } &nbsp; &nbsp; //RENAME TOKEN IN CORRECT ORDER &nbsp; &nbsp; &nbsp;for(i=0;i&lt;c;i++) &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;k=i+dex; &nbsp; &nbsp; &nbsp; &nbsp; nn = lp + " " + k; &nbsp; &nbsp; &nbsp; &nbsp; token=ta[i]; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("renaming script","/w gm " + token.get("name") + " to " + nn); &nbsp; &nbsp; &nbsp; &nbsp; token.set("name",nn); &nbsp; &nbsp; } &nbsp; &nbsp; } &nbsp; &nbsp; }else{ &nbsp; &nbsp; &nbsp; &nbsp; sendChat("DM","Nothing Selected"); &nbsp; &nbsp; } }; &nbsp;on("chat:message", function(msg) { &nbsp; &nbsp; &nbsp; &nbsp;try &nbsp; &nbsp; &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; if(msg.type == "api") &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var S = ""; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if( msg.content.indexOf("!RN ") != -1) &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; if(playerIsGM(msg.playerid)) &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; S = msg.content.replace("!RN ", ""); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rename_ordered(S,msg.selected); &nbsp; &nbsp; &nbsp; &nbsp; }else{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("RENAMING SCRIPT","ONLY THE GM IS ALLOWED TO USE !RN") &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp;catch(err) &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("RENAMING SCRIPT EXCEPTION",err.message); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });
okay ..
Saluut
This is a good script. &nbsp;You may not get much praise for it, though. &nbsp;Another script called&nbsp;TokenNameNumber already exists. &nbsp;It's in the one-click option of the API so most API users with this need already use it instead. &nbsp;It does most of what this does automatically. If you don't feel like supporting your own script, you might want to check it out. &nbsp;When set up properly, you don't even have to use any API commands. &nbsp;It automatically numbers tokens for you when you place them, whether by copy/paste or dragging from the journal. But if&nbsp;TokenNameNumber didn't exist already, I'd be all over this script!
TokenNameNumber doesn't do exactly the same thing that my script does. It numbers the tokens as you drag them on to the board if you remember to put a special key string into the token name.&nbsp; TokenMod is &nbsp;a good script, but it also doesn't do exactly what this script does. &nbsp; The reason why my script is useful is because you can use it quickly rename and renumber a large number of monster tokens at once. There are sometimes situations that occur where a player will use a summon creature spell to create 16 giant spiders for example. I might not have giant spiders set up on a character sheet, so I have to set up the monster on the fly. To do this I will create a new character sheet and a master token, and set all the token properties through the gui. I will then copy and paste the master token &nbsp;four times. I will then copy and paste the group of four a further four times giving me a total of 16 spiders. I can then select the lot and rename and renumber them using my script. I guess if I had messed up setting up the master token properties I could use TokenMod to fix the problem. I could also take sixteen spiders off another page and paste them onto my new page an renumber them. There are also situations where you have identical groups of monsters in different rooms or areas and all you want to do is to copy and paste them and then relabel them.
1462115052
The Aaron
Pro
API Scripter
Certainly, there is a place for both scripts. &nbsp;The fluidity with which you can rename groups of tokens is very nice. &nbsp;I can see circumstances where you might want to rename and renumber a set of pieces across character sheet boundaries, which this could certainly do. &nbsp;=D Besides, competition is good for the consumer! &nbsp;=D