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

Looking for simple script to show Images

1621859774
Chris Jones
Pro
Sheet Author
Hello all i've been looking through the API scripts for a simple script, but can't quite find what i'm looking for. What i need is a script that rolls a d10, and then displays a web hosted image depending on the result, as well as listing who rolled it. It's sort of similar to the table roller, but i want an image displayed, as well as detail as to who rolled it. Are there any examples i can customise? Cheers Chris
1621860072
The Aaron
Roll20 Production Team
API Scripter
I believe you can do that without the API if you use a link shortened that lets you pick the url ending: [x](<a href="https://some.link.shortener/some_preface_[[1d10]]#.png" rel="nofollow">https://some.link.shortener/some_preface_[[1d10]]#.png</a>) You could also set up a Rollable Table and use RecursiveTable to make the result look nice.&nbsp; If those don't work? It would take a custom script with the URLs in it, which I can probably help with.&nbsp;
1621860460
Chris Jones
Pro
Sheet Author
As it's got to be random, i'm not sure the first option would be suitable. Modifying the Rollable table was my first thought, but i know enough to be dangerous, and frankly i'm not good enough to know how to insert the name of the roller, nor to have it reference a able not listed in the game. Hosting images is easy enough of course, and i've been looking over other scripts to see how they do it - most are too tied in with other concepts for me to separate out however
1621860769
The Aaron
Roll20 Production Team
API Scripter
The person who rolls it will be listed with the chat message.&nbsp; In the first case, the [[1d10]] will get expanded to a number, so you just need to have 10 urls with <a href="https://blah.blah.bla/some_preface_1" rel="nofollow">https://blah.blah.bla/some_preface_1</a>, &nbsp;etc.&nbsp; If neither of those is satisfactory, I can probably help you make a script for it.
1621864294
Chris Jones
Pro
Sheet Author
I'd want whatever it is to be simple, so that my players can just type the simplest of commands and we get a result ideally. How complex is making a script for this?
1621864821
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
You can put Aaron's code above into a macro and make it usable by all players. They can then just push a button on the macro bar or type #nameOfMacro in chat.
1621865432

Edited 1621874259
The Aaron
Roll20 Production Team
API Scripter
Not hard: on('ready',()=&gt;{ const imageList=[ "<a href="https://static.onecms.io/wp-content/uploads/sites/34/2018/05/12170411/cat-kitten-138468381.jpg" rel="nofollow">https://static.onecms.io/wp-content/uploads/sites/34/2018/05/12170411/cat-kitten-138468381.jpg</a>", "<a href="https://globalnews.ca/wp-content/uploads/2016/09/kittens.jpg?quality=85&amp;strip=all" rel="nofollow">https://globalnews.ca/wp-content/uploads/2016/09/kittens.jpg?quality=85&amp;strip=all</a>", "<a href="https://mk0nationaltodayijln.kinstacdn.com/wp-content/uploads/2020/07/kitten-day-640x514.jpg" rel="nofollow">https://mk0nationaltodayijln.kinstacdn.com/wp-content/uploads/2020/07/kitten-day-640x514.jpg</a>", "<a href="https://media.wired.com/photos/5ed06ca9fbf7b2147038a8a9/16:9/w_2400,h_1350,c_limit/Gear-New-Pet-1168772154.jpg" rel="nofollow">https://media.wired.com/photos/5ed06ca9fbf7b2147038a8a9/16:9/w_2400,h_1350,c_limit/Gear-New-Pet-1168772154.jpg</a>", "<a href="https://www.pethealthnetwork.com/sites/default/files/styles/large/public/kittens-in-basket.jpg?itok=7mZDIHOZ" rel="nofollow">https://www.pethealthnetwork.com/sites/default/files/styles/large/public/kittens-in-basket.jpg?itok=7mZDIHOZ</a>" ]; on('chat:message',msg=&gt;{ if('api'===msg.type &amp;&amp; /^!random-image(\b\s|$)/i.test(msg.content)){ let who = (getObj('player',msg.playerid)||{get:()=&gt;'API'}).get('_displayname'); sendChat('',`&lt;div&gt;&lt;h3&gt;${who}&lt;/h3&gt;&lt;img src="${imageList[randomInteger(imageList.length)-1]}" /&gt;&lt;/div&gt;`); } }); }); Run: !random-image You get: I pre-loaded it with 5 pictures of kittens because this is the internet, but you can adjust with whatever URLs you want.&nbsp; It will pick randomly from the number that are there.
1621866545
Chris Jones
Pro
Sheet Author
That all seems to work perfectly for what i need - i'll have a play around and come back if i hit a brick wall, but if not, thanks so much for your help!
1621866710
The Aaron
Roll20 Production Team
API Scripter
No problem!
1621871766
Chris Jones
Pro
Sheet Author
One thing i've noticed is that the command only works for the GM - is there a toggle to open this up for players as well?
1621873656
Chris Jones
Pro
Sheet Author
Nvm, i've noticed it and removed it. thanks again!
1621874247
The Aaron
Roll20 Production Team
API Scripter
Ah, good catch, I'll adjust above for posterity.&nbsp; My base snippet boilerplate has that in it and I sometimes forget to remove it...