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

Using TokenMod to make random selection

Ok, so taking what I learned from using TokenMod for druid wildshape abilities I decided to try something similar to that but for a Bag of Tricks. I set up a blank character sheet for the BoT, made a random roll table with all the creatures and the base fuzz ball form and set that as the token for the BoT. Then I setup a macro just like that for the druid but what I want I couldn't figure out how to do is make it select a random face.

The Macro I'm using including a declaration in the chat:

&{template:dmg} {{rname=}} 0 {{range=}} {{damage=1}} {{dmg1flag=1}} {{dmg1=Grey Summons From His Bag of Tricks!}} {{dmg1type=}} 0 {{dmg2=[[0]]}} {{dmg2type=}} 0 {{desc=}}  {{spelllevel=}} {{innate=}} {{globaldamage=[[0]]}}
!token-mod {{
  --set
    ?{Select|Jackal,currentside#2 represents#@{Jackal|character_id} width#[[70]] height#[[70]]
      |Ape,currentside#3 represents#@{Ape|character_id} width#[[70]] height#[[70]]
      |Baboon,currentside#4 represents#@{Baboon|character_id} width#[[70]] height#[[70]]
      |Axe Beak,currentside#5 represents#@{Axe Beak|character_id} width#[[2*70]] height#[[2*70]]
      |Black Bear,currentside#6 represents#@{Black Bear|character_id} width#[[2*70]] height#[[2*70]]
      |Giant Weasel,currentside#7 represents#@{Giant Weasel|character_id} width#[[2*70]] height#[[2*70]]
      |Giant Hyena,currentside#8 represents#@{Giant Hyena|character_id} width#[[2*70]] height#[[2*70]]
      |Tiger,currentside#9 represents#@{Tiger|character_id} width#[[2*70]] height#[[2*70]]
    }
    bar1_link|hp
    bar2_link|npc_ac
    bar3_link|none
    name|"Fuzz Ball"
    showname|Yes
}}


November 29 (4 years ago)

Edited November 29 (4 years ago)
The Aaron
Roll20 Production Team
API Scripter

If you just want to choose a random side, you can do:

!token-mod --set currentside|*

If you want to randomly set many properties, you can create a Rollable Table with the commands in them, like:

currentside#2 represents#-JK14ad234s43 scale#1u

Then pass a roll of that Rollable Table to TokenMod:

!token-mod --set [[1t[BoTOptions] ]]

You will need to expand the character id instead of using an @{} reference, and no inline rolls, but that should otherwise work great.

November 29 (4 years ago)

Edited November 29 (4 years ago)

I'm still a bit lost. I don't actually write any code myself, I just find stuff and make changes accordingly so I'm not very proficient. Here's what I do know.

I know that the macro I showed first allows me to change the token face while at the same time changing what character (or monster) sheet assigned to the token (i.e. when I change the token to Giant Weasel and shift double click it brings up the sheet for the Giant Weasel) as well as assigning the appropriate size for the creature.
I know that !token-mod --set currentside|* does randomly change the face of the token but it doesn't change the size for any larger tokens and doesn't assign the correct sheet to the token when the face changes
I know that [[1t[BoT] ]] will roll from the table and show the result in the chat but I can't seem to get that to choose a side for the token

What I need to know if you would be so kind is the middle part of your suggestion, creating the rollable table with the commands in it. I don't know how to expand the character IDs (but I'll try to figure that out) or how to properly scale the token (what is 1u?)

Finally, would I have a single macro with both <!token-mod --set currentside|*> as well as <!token-mod --set [[1t[BoToptions] ]]> or would I need to set up two or only use one of the commands.

Thank you again so much for your help.


November 29 (4 years ago)
The Aaron
Roll20 Production Team
API Scripter

No problem.  Here's the parts:

Find the Character ID

When you use something like @{selected|token_id}, that's just asking Roll20 to look up the token_id of the currently selected token, and replace the whole @{...} part with it's value.  Similarly, you can look up the get a Character's ID with something like @{Ape|character_id}.  Just put in chat:

/w gm @{Ape|character_id} 

:and hit enter, you'll get a chat message with the id.  It will start with a - and look something like:

-MClN7CxELQc-W2E_Yf8
Sizing Tokens

TokenMod accepts units of measure applied to numbers:

  • u -- 70 pixels, the standard Roll20 Unit of measure.
  • g -- The size of one Grid square, usually 70 pixels, but different if you're using a different sized grid.
  • s -- The current Scale of the page, usually feet (ft), and usually 5 to a grid square.  You can also use one of ft, m, km, mi, in, un, hex, sq

You can use those to set the left, top, width, and height fields.  You can also set the special field scale, which sets width and height to the same value, these are all equivalent:

!token-mod --set width|140 height|140
!token-mod --set width|2u height|2u
!token-mod --set scale|2u
Creating a Rollable Table of Commands

Click on the Collections Tab:

Scroll down to the Rollable Tables section and click +Add:


Scroll down to the new-table entry and click its name:


Name it BoTOptions (or whatever makes sense to you).  Click +Add Item to open the Edit Table Item dialog.  Set the name to something like:

represents#<CHARACTER_ID> scale#2u currentside#2

Where <CHARACTER_ID> is replaced with whatever you got from @{Ape|character_id} or similar.  Leave the weight as 1 (unless some forms are more likely) and don't bother with a picture (unless you just want one in there fro identifying which row is which later).  Click Save Changes on the Edit Table Item dialog.  Repeat for each different creature.  You should end up with something like this:

Putting it all together

You can now pass a roll of that table to TokenMod:

!token-mod --set [[1t[BoTOptions] ]]

What will happen when you do that is first the chat system will roll that rollable table and substitute in a single row from the table, then the result will be sent to the API, conceptually it might look like this:

!token-mod --set represents#-LcB9UbSbHAzxanuT25q scale#2u currentside#2

The net effect is that your token is randomly changed to represent a different character, has its size changed, and changes to a different image.

Note that TokenMod accepts | and # as argument dividers, so scale#2u is the same as scale|2u.  It does this to let you nest them inside something that uses | for other purposes (like a Roll Query ?{...|...|...})


Hope that clears it up.  Let me know if I need to go into more detail or if there is something else to cover. =D

Man you are amazing!! I don't know how you could go into much more detail!! I did what you said and it works perfectly! Thanks again so much for the quick replies and great help. I also feel like I learned more from this that will help me with future games.

November 30 (4 years ago)

Good post, a lot of stuff in here i did not know about