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

Possible to set a characters avatar image same as default token with API?

I have no players for a few weeks and my OCD decided to let itself run wild.  I'm on a quest to remove as many steps as possible from creating DND 5e OGL mooks. So I can assign a token to a character using the DefaultToken script.  I want to take the image used in that token and assign it to be the characters avatar.  My reading tells me that the avatar property of the character object should be API assignable.  My partially informed analysis of the DefaultToken script hasn't given me an aparent  way of extracting the image URL.  The wiki says the _defaulttoken property is accessible and I can get a JSON that presumably contains the URL I'm looking for. I wanted to ask before charging any windmills.  Thanks in advance.
1486157620
The Aaron
Pro
API Scripter
You can, with the caveat that the image must be in a User Library, rather than the Marketplace.  If you're assigning them with the DefaultToken script, then that should already be the case. Here: on('ready',function(){     'use strict';     var getCleanImgsrc = function (imgsrc) {        var parts = imgsrc.match(/(.*\/images\/.*)(thumb|med|original|max)(.*)$/);        if(parts) {           return parts[1]+'thumb'+parts[3];        }        return;     };     _.chain(findObjs({type:'character'}))         .filter( c=>''===c.get('avatar'))         .each( c=>{             c.get('defaulttoken',(dt)=>{                 let deftoken=JSON.parse(dt);                 if(deftoken && _.has(deftoken,'imgsrc')){                     let imgsrc=getCleanImgsrc(deftoken.imgsrc);                     if(imgsrc){                         c.set('avatar',imgsrc);                         sendChat('',`/w gm <div><img src="${imgsrc}" style="max-width: 3em;max-height: 3em;border:1px solid #333; background-color: #999; border-radius: .2em;"><code>Updated ${c.get('name')}</code></div>`);                     }                 }             });         }); }); That will do it at startup and whisper to the GM each character that gets updated.