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-mod Question: Duplicating Tokens

Is it possible to duplicate a token using existing functionality in Token-Mod or would I have to write a new API script just to do this? I have an NPC who has an ability to make a duplicate of themselves and I'm trying to figure out how to handle it in a macro that a duplicate token just appears in an adjacent square.
1532363095
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Look for the [Summon] Script. Caveat: It's a little quirky, but maybe you've got the chops to fix it. It allows you to summon a token to the VTT by name, but it creates the token, instead of pulling it, so some of the settings don't come in properly. I had problems with it before I realized what was going on. It's definitely got potential.
1532369216
The Aaron
Pro
API Scripter
I usually just copy/paste the token. =D
1532373575
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Can a player do that?
1532373741
The Aaron
Pro
API Scripter
No, but they can drag their token out of the Journal again.  Using King's Summon Script is probably a good place to start, though it doesn't work on MarketPlace assets. =( (API Limitation)
The Aaron said: No, but they can drag their token out of the Journal again.  Using King's Summon Script is probably a good place to start, though it doesn't work on MarketPlace assets. =( (API Limitation) That's fine. I already make extensive use of !token-mod to change imgsrc of tokens (lots of polymorphing and werecreatures in my game) and the tokens I want to duplicate are all the ones I already added to my library. I know it's a simple matter to just copy paste it but I want to automate it (just like I want to automate everything =P) and use VFX/SFX alongside the duplicate spawning Either of you have a link to that Summon script?
1532375594
The Aaron
Pro
API Scripter
try this...&nbsp;<a href="https://app.roll20.net/forum/post/1609859/slug%7D" rel="nofollow">https://app.roll20.net/forum/post/1609859/slug%7D</a>
The Aaron said: try this...&nbsp; <a href="https://app.roll20.net/forum/post/1609859/slug%7D" rel="nofollow">https://app.roll20.net/forum/post/1609859/slug%7D</a> Thanks!
I put something together quick and simple. You just run the command passing it a Token ID and it will make a duplicate of the token in all respects (pretty sure I didn't miss anything) Optionally you can tag "--rep" to the end of the command to make both tokens represent the same sheet. By default the copy doesn't represent a sheet at all. Example: !duplicate @{selected|token_id} !duplicate @{selected|token_id} --rep Here it is: /* duplicateToken v0.2.8 By: Kastion Profile: <a href="https://app.roll20.net/users/3173313/kastion" rel="nofollow">https://app.roll20.net/users/3173313/kastion</a> Syntax: !duplicate [TokenID] [...optional: --rep] */ on('ready', function() { log("-=&gt; Duplicate Script Loaded - (v0.2.8 - Last Edited by Kastion [July 23rd 2018]) &lt;=-"); on('chat:message', function(msg) { if (msg.type == "api" &amp;&amp; msg.content.indexOf("!duplicate") !== -1) { var token_id = msg.content.split(' ')[1]; var c = getObj('graphic',token_id); if(c) { var reps = ""; if (msg.content.indexOf("--rep") !== -1) reps = c.get('represents'); var characterImage = c.get('imgsrc'); characterImage = characterImage.replace("med","thumb"); characterImage = characterImage.replace("max","thumb"); var obj = createObj("graphic", { _pageid: c.get('_pageid'), layer: "objects", represents: reps, imgsrc: characterImage, width: 70, height: 70, top: c.get('top'), left: c.get('left')+70, bar1_value: c.get('bar1_value'), bar1_max: c.get('bar1_max'), bar2_value: c.get('bar2_value'), bar2_max: c.get('bar2_max'), bar3_value: c.get('bar3_value'), bar3_max: c.get('bar3_max'), showname: c.get('showname'), showplayers_name: c.get('showplayers_name'), showplayers_bar1: c.get('showplayers_bar1'), showplayers_bar2: c.get('showplayers_bar2'), showplayers_bar3: c.get('showplayers_bar3'), name: c.get('name') }); if (obj) toFront(obj); } else { sendChat('Duplicate', '/w gm No token found with the specific ID.'); } } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; }) }); When I have more time I'll run through King's Summon script again. If it has been abandoned (is that the case?) I might take it over and refine it. Being able to use a command to summon a group of tokens that all represent journal entries seems like something worthwhile - especially when rolling and running random encounters.
1532378820
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I used to use it for summoning the party. Easier that dragging out 4-5 tokens.
1532379363

Edited 1532379414
The Aaron
Pro
API Scripter
You can simplify this with a little trick to assure that you get all the properties: /* duplicateToken v0.2.8 By: Kastion Profile: <a href="https://app.roll20.net/users/3173313/kastion" rel="nofollow">https://app.roll20.net/users/3173313/kastion</a> Syntax: !duplicate [TokenID] [...optional: --rep] */ on('ready', function() { log("-=&gt; Duplicate Script Loaded - (v0.2.8 - Last Edited by Kastion [July 23rd 2018]) &lt;=-"); on('chat:message', function(msg) { if (msg.type == "api" &amp;&amp; msg.content.indexOf("!duplicate") !== -1) { const c = getObj('graphic',msg.content.split(/\s+/)[1]); if(c) { let props = JSON.parse(JSON.stringify(c)); props.left += props.width; props.represents = (/\s+--rep\b/.test(msg.content) ? props.represents : ''); props.imgsrc = props.imgsrc.replace(/med|max/,'thumb'); const obj = createObj("graphic", props); if (obj) toFront(obj); } else { sendChat('Duplicate', '/w gm No token found with the specific ID.'); } } }); });
The Aaron said: You can simplify this with a little trick to assure that you get all the properties: Thanks The Aaron! Javascript isn't my strong point so I tend to brute force a lot of stuff =P
1532381948
The Aaron
Pro
API Scripter
No worries.&nbsp; Even knowing javascript, that's not an obvious leap.&nbsp; It takes advantage of some implementation details of Roll20 Objects that are not easily apparent. =D