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

Newbie help with API script to show players the pictures of a creature from the monster manual using the image that is hosted on aws

Hello  I freely admit I am not a strong coder or an API expert, and this was done with the help of our new buddy, ChatGPT.  I was looking to be able to show the image of monsters to players by using the already embedded images in the monster manual.  I asked CHatGPT about this and it produced code that I tried , but it always returns monster could not be found in the monster manual - Any tips or ideas how to correct/improve/extend to other compendiums would be greatly appreciated (along with your patience :  on("chat:message", function(msg) {   if(msg.type === "api" && msg.content.indexOf("!showmonster") !== -1) {     var parts = msg.content.split(" ");     var monster = parts.slice(1).join(" ");     var compendium = findObjs({_type: "compendium", title: "Monster Manual"})[0];     if(compendium) {       var monsterPage = findObjs({_type: "page", name: monster, _parentID: compendium.id})[0];       if(monsterPage) {         var imgSrc = monsterPage.get("imgsrc");         if(imgSrc) {           sendChat("", "&{template:default} {{name=" + monster + "}} {{image=" + imgSrc + "}}");         } else {           sendChat("", "/w gm The image source for " + monster + " could not be found.");         }       } else {         sendChat("", "/w gm The monster " + monster + " could not be found in the Monster Manual Compendium.");       }     } else {       sendChat("", "/w gm The Monster Manual Compendium could not be found.");     }   } });
1675283197
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
ChatGPT is pretty much useless when coding for Roll20. It has no concept of how the R20 backend works. Unfortunately, what you are attempting is not possible with the API as the API has no access to the compendium.
Thanks Scott, that clears that up - have a good one
1675301065

Edited 1675301111
The Aaron
Roll20 Production Team
API Scripter
ChatGPT can answer Javascript language questions really well, like "explain what a closure is in javascript and provide and example showing a counter".  There's a huge amount of pure javascript that ChatGPT has been trained on. By contrast, there isn't that large of a body of Roll20 scripts, so it can't generate accurate responses, just ones that look valid. For what you want to do, I'd suggest finding the monster in your journal and showing its avatar from there.  You can start with something like this and expand further as needed: on('ready',()=>{ const keyFormat = (text) => (text && text.toLowerCase().replace(/\s+/g,'')) || undefined; const matchKey = (keys,subject) => subject && !_.isUndefined(_.find(keys,(o)=>(-1 !== subject.indexOf(o)))); on('chat:message',msg=>{ if('api'===msg.type && /^!show-monster(\b\s|$)/i.test(msg.content) && playerIsGM(msg.playerid)){ let who = (getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname'); let k = keyFormat(msg.content.replace(/^![^\s]*\s*/,'')); findObjs({type:'character'}) .filter(c=>matchKey([k],keyFormat(c.get('name')))) .forEach(c=>sendChat('',`&{template:default}{{name=${c.get('name')}}}{{[x](${c.get('avatar')}#.png)}}`)); } }); }); Call: !show-monster imperial dragon
You might take a look at the API/MOD script SuperNotes, written by Keith Curtis, one of the API jocks on Roll20. &nbsp;It has this functionality and more. Here is a link to its Forum:&nbsp; <a href="https://app.roll20.net/forum/post/8293909/script-supernotes" rel="nofollow">https://app.roll20.net/forum/post/8293909/script-supernotes</a>
I've been using this for a little bit:&nbsp; <a href="https://app.roll20.net/forum/post/11218764/api-for-art-showcase-in-chat" rel="nofollow">https://app.roll20.net/forum/post/11218764/api-for-art-showcase-in-chat</a> Simple and effective
1675312401
timmaugh
Forum Champion
API Scripter
If you are learning to code, follow Aaron's lead and start expanding on what he provided. If you just want to show the image from a monster character (you have to drag the monster out in order to create a character sheet that scripts can access), you can also do that with Fetch + ZeroFrame: !@(Husk.char_img){&amp;simple} You can see I whispered the results... but you don't have to, obviously.