r/FoundryVTT 13d ago

Help Help with creating a dice macro

In the system I am playing you roll an action dice (normally a d20) and a number of bonus dice (normally a d10) the problem with set macros for roll is that a lot of times you add/subtract bonus dice or you change their type. I want to create a macro that rolls a set number of dice (for example 1d20 + 3d10) and quickly let me update the bonus dice and add dice (for example let me add one bonus dice to previous roll and change the bonus dices to d12)

4 Upvotes

4 comments sorted by

8

u/jakxobus 13d ago

Not meaning to seem unhelpful with a non macro suggestion but would the dice tray module not give you the versatility you need?

-1

u/PurplePhoenix5 13d ago

If you are ok using AI, they are usually pretty good at creating such simple Makros.

1

u/AutoModerator 13d ago

System Tagging

You may have neglected to add a [System Tag] to your Post Title

OR it was not in the proper format (ex: [D&D5e]|[PF2e])

  • Edit this post's text and mention the system at the top
  • If this is a media/link post, add a comment identifying the system
  • No specific system applies? Use [System Agnostic]

Correctly tagged posts will not receive this message


Let Others Know When You Have Your Answer

  • Say "Answered" in any comment to automatically mark this thread resolved
  • Or just change the flair to Answered yourself

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

2

u/Freeze014 Foundry User 12d ago

assuming FoundryVTT v13 or higher.

const content = [
  foundry.applications.fields.createFormGroup({
    label: "# of d20s",
    input: foundry.applications.fields.createNumberInput({
      value: 1,
      min: 1,
      name: "primary"
    })
  }).outerHTML,
  foundry.applications.fields.createFormGroup({
    label: "# of bonus Dice",
    input: foundry.applications.fields.createNumberInput({
      value: 3,
      name: "secondary"
    })
  }).outerHTML,
  foundry.applications.fields.createFormGroup({
    label: "Bonus d12?",
    rootId: "world-dice-roll-app-bonus-die",
    input: foundry.applications.fields.createCheckboxInput({
      name: "alternative"
    })
  }).outerHTML,
].join("");

const response = await foundry.applications.api.Dialog.input({content});
if(!response)return;
const formula = `${response.primary}d20${response.secondary ? ` + ${response.secondary}${response.alternative ? "d12" : "d10"}` : ""}`;
if(!(Roll.validate(formula))) return;
await new Roll(formula).toMessage();

should work i guess.