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

How do I automate placement of a token on the token layer?

Is there a macro or script that, when run, and when provided with input "x", would place a new token, Tx, using the the name of an image, Ix, in my library, on the token layer? Ideally, I'd use it to allow each of my players to create any number of instances of token Tx on the token layer, tokens they would then be able to move around.. Extending this, what I'd REALLY like, and will build if it's possible and hasn't already been built, is for a player to be able to roll xd6, say 5d6, and for the script to then figure out what the rolls were on each of the five dice and create five new tokens on the token layer for each of those dice. Like a visual dice pool. Has this been done? If not, is it possible using the API that is available? Thanks --Andy
1593626167
The Aaron
Roll20 Production Team
API Scripter
King's summon script will create tokens on the map for you based on a few things, one of which is characters.  It's a bit long in the tooth, but might be a good starting point for you when thinking about your own script. Some challenges you'll face: The API can only create images from a User's Library, so things someone uploaded. The API only knows URLs, not names, so you can't just name them in your library and create from that.  Additionally, they must be the "thumb" URL (so replace max, min, original, etc with thumb) The API doesn't know where you're looking, so it must pick the place to put them.  King's puts them adjacent to a selected token. Some scripts put things in the middle of the map or next to the last thing that was moved, etc. There are 3 places to look to know what map a player is on:  the _lastpage property (for GMs), the Campaign playerspecificpages array for players that have been moved to their own page, and the Campaign playerpage for everyone else. 
Thanks Aaron. I see the first bullet above will prevent each player from being able to run the script as I don't want to rely on each of them having to upload the same six dice images to their own libraries. I'll start with King's script. --Andy
1593626973
The Aaron
Roll20 Production Team
API Scripter
It won't prevent it.  It just has to be in a User's Library, not any specific user.  The API script can create images from your User Library.  My scripts (like TurnMarker1) create images out of my User Library for people to use.
1593630925
GiGs
Pro
Sheet Author
API Scripter
Andy B. said: Thanks Aaron. I see the first bullet above will prevent each player from being able to run the script as I don't want to rely on each of them having to upload the same six dice images to their own libraries. I'll start with King's script. --Andy Just to clarify this: there's a difference between items in your librrary, and items in the marketplace. Things you buy off the marketplace do not get added to your library, and so the API cannot access them. You need to download those images (if the product allows that) and upload them back to your library to be able to access them with an API script.