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

[Script] Deck Utilities

March 29 (11 years ago)

Edited March 31 (11 years ago)
What Does it Do?

This script allows you to pull from Decks and/or Rollable Tables. You can:

  • Filter the results in a variety of ways (or not).
  • Get the results as a list in chat, or have tokens created from the chosen image.
  • Get all the results, or one randomly selected (respecting weights, if defined).
Why Do You Want It?

  • Since infinite decks lose their randomness (you will always pull each card, in order, then start again at the first), this script can put that randomness back in. You could have a card for all your different types of gear, define some weights on it via a Rollable table (or not, if equal weighting is fine), and then randomly select one. (Unfortunately, it can't actually deal cards yet - but it can make a token from one.)
  • You can quickly get a random token from a rollable table, as opposed to only being able to roll on the table, get the first token, and then manually change it to the one you rolled.
  • You can consolidate your decks and tables. For example, you might currently have several Loot tables, split up by rarity or by item type. But with this script, you can put them all together because you can choose at any time to roll on only part of the table.
Usage:

  • Every command must begin with !deck-util
  • The second word will be interpreted as the Deck name. If invalid (e.g. "none" or "0") it doesn't use a deck.
  • If a third word is entered prior to any other keywords, that's the Rollable Table. If blank or invalid, it attempts to resolve a Rollable Table with the same name as your Deck. If that fails, equal weighting is used on the Deck you entered. (You *must* include either a valid Deck or a valid Rollable Table.)
  • (From this point forward, order doesn't matter unless otherwise stated.)
  • If you include "!w", the result is returned to you as a whisper instead of being public.
  • If you include "!all", you get all matches instead of one randomly chosen.
  • If you include "!token", a token is created from the image on your card or table.
  • If you include "!filter", then everything afterward until the next keyword is used to define your possible results:
    • Every filter term must have quotes around it. This makes it possible to include spaces.
    • Every filter term defines a condition that must be true. That is, a valid result will have ALL terms, not ANY.
    • If a term begins (just after the quote) with the ^ symbol, then the condition is that the term must not be in the item name in order for that item to be a valid result.
    • If a term begins (just after the quote) with the / symbol, then the rest of the string is interpreted as a regular expression. (Do not end the term with another /). So if you're wanting something more complicated, you'll want to look into Regular Expressions. One relatively simple usage would allow you to put two valid words with a | symbol separating them (no spaces) which would return results with either term.

Examples:


The following examples assume that you have a "Spells" Deck and a "Spells" Rollable Table and that every value in the Rollable Table exists as a card. (There's no problem with there being card items that don't exist in the Rollable Table).

Both have the following items:
  • Buff: Armour (Novice)
  • Buff: Deflection (Novice)
  • Buff: Smite (Novice)
  • Combat: Blast (Seasoned)
  • Combat: Bolt (Novice)
  • Healing: Healing (Novice)
CommandResultValid
!deck-util Spells !all !filter "Buff"Immediately lists all buff spells.Armour, Deflection
!deck-util 0 Spells !w !filter "/Heal|Combat"Whispers you a random healing or combat spell, weighted per the Spells table.Blast, Bolt, Healing
!deck-util Spells !filter "Novice" "Combat" !tokenDraws the token for a random novice combat spell, weighted per the Spells table. (In the future, I hope for this to actually draw the card instead of just a token based on it).Bolt
!deck-util Spells 0 !token "^Combat" "/Novice|SeasonedCreates a token for a random non-combat novice or seasoned spell, using equal weights of 1. (Again, I'd like for it to draw the card instead of a token, but not yet.)Armour, Deflection, Smite, Healing

Updates & To-Do (as of March 29, 2014):
  • [FUTURE] When the API allows for it, the ability to deal from the deck. This would combine nicely with my Inventory Extension script.

Script:

https://gist.github.com/Parmeisan/9864305
April 03 (11 years ago)
Does the deck still treat it as thought the card has been drawn? Such as, is there any way to "remove" a card/table result from the pool?

I host a Betrayal at House on the Hill game, and the current deck system isn't very friendly to it's deck setup.
April 03 (11 years ago)
Unfortunately, I do not believe there is any way to affect the actual deck from within the API, yet. So the deck is not affected in any way - yet. The token cannot be picked up as a card and it does not count as having been dealt out.

I suppose it might not take a lot of extra code to add an option to keep track of this completely separate from the decks... a new command to, as you said, consider the chosen card removed, and then another new one to "shuffle" or reset the deck / rollable table.

I would hesitate to begin reproducing the existing functionality, though. Cards & decks are still new and I hope that it won't be long before we can access them from the API and do this the proper way. And as long as you can't put the cards in your hand like real cards - something that I could never reproduce - it seems almost pointless to try.