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

Summoning Rollable Table Token from API

One of my players has a sort of shape-shifting summon in my game.  I made a multi-sided token to represent it, and a macro that changes its side and stats using TokenMod.  This all works fine with the token.  I am trying to write an API script for the player to click that will effectively "cast" this summon spell and generate the original token from the rollable table without me having to manually place it.  But I can't for the life of me figure out how to make the token that is summoned represent the multi-sided one from the table.  Can anyone help me?  
1611954809
GiGs
Pro
Sheet Author
API Scripter
I believe there's at least one available script that will do this already. It might even be called Summon.
1611956277

Edited 1611956340
The Aaron
Roll20 Production Team
API Scripter
Rollable Table Tokens, once created, have no relationship to their source Table.  Similarly, creating a multi-sided Token is only loosely informed by the Rollable Table you are creating it from. To create a multi-sided token, you need to set up 3 properties on the created graphic: 1) sides -- this is a | (pipe) delimited string list of image urls.  Each URL is URI encoded (encodeURIComponent() )  You could gather all these image urls from a Rollable Table's Table Items to base it on a table. 2) currentSide -- this is the index of the image that is currently displayed. It is 0-biased, so the first image is 0, the second is 1, etc. 3) imgsrc -- you need to set the initial image for the token. Other than that, they are the same as creating normal tokens.
1612014574

Edited 1612015176
David M.
Pro
API Scripter
The SpawnDefaultToken script will do this. Set up the rollable table token as the default token for a character (named "MultiSummon" in the example below), then call the script with something like:  !Spawn{{ --name|MultiSummon --offset|1,0 --side|3 }} This spawns one instance of the rollable token (on side 3) one square to the right of a selected token. Note that for any api script, the image must be in your personal art library, as the api does not have access to marketplace images. EDIT - If you don't want all the bells and whistles and/or just want to continue making your own script (it's fun!), the function in my script that does the spawning is on line 137 of v0.12, called "spawnTokenAtXY". Basically you just use a createObj call after defining a bunch of properties. The rollable table side stuff starts on line 235. Note, my version of the function is asynchronous, as it can get called a bunch of times for cases with multiple quantities and multiple source targets, and would run into timing issues otherwise. Yours likely wouldn't need that.