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 to set character avatar from RTT token's current face

    Hi, I have a rollable table token with many possible faces.  I would like to create a new character in the journal, assign the RTT token as the default token on the selected face, and then have a script that will get the token's current face image and assign that URL to the character journal's avatar.  I see how I can get the token's image source using Fetch ( @(selected.imgsrc_short) ) but I haven't found a script that will let me set the token's character's avatar image.  Does a script for that exist yet? Thanks, Jim
1677250226

Edited 1677250295
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Hi Jim! Here's what I use. This will run on all selected tokens. The command is !avatarfromtoken on("ready", function () {     on("chat:message", function (msg) {         if (msg.type == "api" && msg.content.indexOf("!avatarfromtoken") == 0) { let selected=(msg.selected);             if (selected){                 _.each(selected, function(token){                     tok = getObj("graphic", token._id)                     img = tok.get("imgsrc");                     log(tok.get("represents"));                     log(tok.get("imgsrc"));                     if (tok.get("represents") == ""){                         sendChat("token from Avatar","There is no Represented field for one or more tokens");                         return;                     }                     parent = tok.get("represents");                     par = getObj("character", parent)                     par.set("avatar", img);                 })             }                     }     }); });
Thank you!