Foundry-Workshop / Item-Macro

Store macros in your items, execute them from your character sheet or from your favorite automation module!
MIT License
1 stars 4 forks source link

Doubt about roll. #7

Closed Manume96 closed 9 months ago

Manume96 commented 9 months ago

Hi, im using simple world-building and i'm not sure how to make a macro that involves a roll (for example for a health potion that doesn't heal a constant amount of HP).

Thank you.

Forien commented 9 months ago

Hi, im using simple world-building and i'm not sure how to make a macro that involves a roll (for example for a health potion that doesn't heal a constant amount of HP).

Thank you.

Hello!

First of all, for general Macro help, I would suggest either heading out to my Discord, where you can ask these types of questions on either the #macros channel or the #item-macro channel. Or you could head to the official Foundry VTT Discord, where channel #macro-polo exists and is always full of people willing to help.

Keep in mind, that on these channels as well, it's best to give as much of additional context as you can. For example what Game System are you using, because it could be hard to provide any help without knowing that. Every system uses different data structure. Some systems have concept of "hit points", others have "wounds" etc.

That being said, a simple macro you could use in the Simple Worldbuilding System:

const rollFormula = item.system.attributes.healingPotency.value;
let quantity = item.system.quantity;

if (quantity < 1)
  return ui.notifications.warn(`${actor.name} has no ${item.name} left!`);

if (actor.system.health.value >= actor.system.health.max)
  return ui.notifications.warn(`${actor.name} does not need healing!`);

quantity--;
const roll = new Roll(rollFormula);

await roll.roll();
await roll.toMessage({flavor: `Using ${item.name}`});

let newHealth = actor.system.health.value + roll.total;
newHealth = Math.min(newHealth, actor.system.health.max);

await actor.update({"system.health.value": newHealth});
await item.update({"system.quantity": quantity});

Keep in mind, that I used an attribute I named healingPotency on my item. If you would like to attach it into an attribute group or change it's key, then you would need to edit the first line. image