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

Bag of Tokens - How to Achieve

Hi everyone, I have tried a few different ways to do this but can't seem to get very far, so I thought I'd check if anyone out there has found a nice (or indeed possible) way of doing this. The objective (simplified for illustration): - There are two types of tokens: an Archer and Swordsman - There are 5 of each of these - The player also has a bag that starts with 1 Archer token and 1 Swordsman token - Each round a player can do one of two things: (1) Add a token to a bag (they can choose which token type to add) (2) Draw a random token from the bag (which can be placed on the board either face up or face down) - Occasionally tokens go to a discard pile (for various reasons) - When the bag is empty, the discard pile tokens are placed in the bag I have been trying to simulate this with decks, but it's kind of messy with the player essentially needing to manually add entries to the deck when they want to do (2). Does anyone have a cleaner way of achieving this than manually changing the deck?
1604950824

Edited 1604950987
Gold
Forum Champion
Interesting idea and challenge for Roll20 building. My first analysis, Card Decks would be the closest feature in Roll20 for building this out. As you said. A short answer to a possible route: Maybe the API can help, but I am not sure of that. The Aaron or some other API scriptomancers of this forum may be able to help here. Unfortunately, the Roll20 Card Decks feature is not really finished being developed, it hasn't had any updates or new features in years. Adding a new card is usually only done by the GM, and usually isn't something you want to keep doing mid-game because of the amount of steps involved. A couple years ago one of the owners on Roll20 Team posted on the forum saying that there would be card deck updates in the future and they would be "driven by" publisher relations. It seemed to imply that they would improve the Card Decks capability when Magic: The Gathering, or some other popular card-based game, licenses a product on roll20 that requires it. I haven't seen any mention of Cards whatsoever in the 2020 plans, it has not been addressed this year. Based on this history, I wouldn't expect the features we'd really need to be available in Card Decks anytime soon, no indication of 2021 so far. Please PM me an Invite to your testing and set-up game. I'd be happy to experiment on this with you, as a Test-Player or promoted GM on your tabletop. In that case I will help with testing and continue thinking of alternative approaches to achieve this in Roll20's existing features. There may be whole other methods, apart from using Card Decks, such as tricks with possibly Fog Of War, Dynamic Light, Token "Controlled by" settings, the API scripts, Multi-sided Rollable Tokens, or other areas.
1604952921

Edited 1604952961
David M.
Pro
API Scripter
API script that adds/subtracts cards and deals random ones seems like it would work. Likewise, a script that does the same, but modifying a rollable table (only two entries, weighted appropriately based on how many of each is in the "bag") rather than a deck. The latter could use the !Spawn or !Summon scripts to bring the token "rolled" directly out to the table near an existing token (e.g. !Spawn --name|1t[TableName] --qty|1 --offset|0,1). The potential advantage of this is that the tokens would be linked to character sheets so when brought to the table they would automatically have their own attributes/attacks/hp/token-abilities, etc. associated with the corresponding sheet.  AFAIK, the table- or deck- editing scripts would have to be custom-made, however :/
1604956142
The Aaron
Roll20 Production Team
API Scripter
Agree with all the above.  Card Decks seem like the idea solution.  Setup is a bit of a pain, but you might be able to automate that with the API a bit better.  Either way, it would be custom.
Thanks for the suggestions everyone, since the decks are essentially a 90% fit they seem the best way to go. Now I just need to try and find out if I can work with the API :-). Gold - will certainly send over an invite if I decide to move forwards with this.
1605098329
David M.
Pro
API Scripter
I'm sure Aaron could chime in on the most efficient approach, but my first thought was something like: Make character sheets for the archer and swordsman, with a default token made from an image in your personal art library  (important for api access) Use the state object to store the number of cards remaining of each type (unclear from descr if this is per player or shared among all players) and the discard pile(s) Have api commands for restarting game (resets decks and state objects), adding chosen card to deck (comparing to remaining available), drawing random card to hand (steal code from  dealer script for this?), and recycling discard pile(s). Make several macros that call your script to trigger each of these events,  and then make a master macro that brings up a  chat menu  with buttons that call these specific event macros.  To add card to deck, get the imgsrc for the chosen default token, and copy to the avatar property of the new card, something like: card.set("avatar",  defaultTok.imgsrc ) ...where defaultTok.imgsrc is grabbed from: const getCleanImgsrc = function (imgsrc) {         let parts = imgsrc.match(/(.*\/images\/.*)(thumb|med|original|max)([^\?]*)(\?[^?]+)?$/);             if(parts) {                 return parts[1]+'thumb'+parts[3]+(parts[4]?parts[4]:`?${Math.round(Math.random()*9999999)}`);             }         return;     }; defaultTok.imgsrc = getCleanImgsrc(defaultTok.imgsrc); //ensure that we're using the thumb.png See here for documentation on creating objects. Also, scroll up for all the properties of the objects that you'll be using (character, graphic, deck, and card). This thread  also has some good info on where to start, including a generic starting template for your script that includes initiating your state object.  
Thanks David, that is incredibly useful! For the record: The tokens are per player, each will have access to 4 different token types (of roughly 20 different tokens available) and will have either 4 or 5 of each one (the actual number depends on which token type it is). The game I am going to be trying to replicate is this: Warchest .
1605183393

Edited 1605183418
David M.
Pro
API Scripter
Sounds like a fun project!
Looking forwards to it, but likely need to brush up on my javascript (which at first glance appears to be the appropriate language).