#Roll Table macro

1 messages · Page 1 of 1 (latest)

royal delta
#

Several ways to do this. Mind posting the macro?

severe wasp
royal delta
#

The chat card functionality you have below the table roll is specific to the system and so it's not built into foundry core. The roll table button is core to foundry and so it doesn't know that the item it's displaying has a chat card functionality.

#

Those two need to be married together in a macro

#

Which system is this?

severe wasp
#

The unofficial Mutant Year Zero one :)

royal delta
#

Alright. I am not familiar with the API there. So I am not sure how to conjure the chat card.

severe wasp
#

So there's no like standardized way to emulate the little button to send stuff to the chat log?

royal delta
#

It can quickly get complicated, but assuming @pure adder might be able to enlighten

#

I am usually on phone these days so I'm unable to look up how MYZ has implemented it

severe wasp
#

Ah, alright! My mistake, then. I'll dig around in the js and see if i can find something (and also wait for happysteve to show up maybe). Thanks a bunch for the info though :)

pure adder
#

Hi therem, hm... I am trying to understand the request

severe wasp
#

haha sorry!

pure adder
#

so instead of link to the crit in the chat you want to have full description in a chat card

#

is that correct ?

severe wasp
#

well ideally i'd like to have both, i think

#

such that it's still easy to drag the crit onto a sheet

pure adder
#

you can drag it

#

just drag that crit link if that is all you need

#

or click on it

#

it is a link

severe wasp
#

yeah that part works, i'd just like it to also post the actual chat card thing as well

pure adder
#

once on the sheet you'll see a chat bubble next to it

severe wasp
#

so it'd look something like this immediately after rolling on the table, instead of needing to press the chat bubble

royal delta
#

Assuming it is sendToChat though. you'd want a script looking like this:

(async function () {
    const results = await game.tables.getName(tableName).table.roll();
    const result = results.results[0];
    const chatData = {
        content: `<div class="chat-item" style="text-align:center"><div class="border">
            <h3>Critical Injury</h3><h4>You suffer a wound:</h4>
            <p style="padding:10px">@${result.data.collection}[${result.data.resultId}]</p>
            <p>Result: ${result.data.range[0]} - ${result.data.range[1]}</p>
            </div></div>`,
        card: game.items.get(result.data.resultId).sendToChat(),
    };
    ChatMessage.create(chatData, {});
})()```
pure adder
#

I'll need to send it to a chat after the roll

#

there is a fuinction in the Item for that

#

I am just not calling it after the table roll

#

I need to check what's the name of that function... probably sendToChat 🙂

#

let me see the code

severe wasp
#

thanks a lot for helping me out with this :) I think i'm gonna be able to figure out more stuff on my own when i have some macros and stuff that i actually understand what they do, lol

pure adder
#

so using the code above. it should be

#
    const results = await game.tables.getName("MYZCB - Critical Injuries").roll();
    const result = results.results[0];
    const chatData = {
        content: `<div class="chat-item" style="text-align:center"><div class="border">
            <h3>Critical Injury</h3><h4>You suffer a wound:</h4>
            <p style="padding:10px">@${result.data.collection}[${result.data.resultId}]</p>
            <p>Result: ${result.data.range[0]} - ${result.data.range[1]}</p>
            </div></div>`,
        card: game.items.get(result.data.resultId).sendToChat(),
    };
    ChatMessage.create(chatData, {});
})()```
severe wasp
#

Oh, fantastic

#

thanks a ton!

pure adder
#

np. glad we can help

#

tnx Daddy

severe wasp
#

another question you might be able to answer, actually; would it be feasible to change how rolls are displayed, to make the dice types grouped together on their own lines? Not at all a big issue, though, just curious and i've gotten used to how an old bot i made displayed its rolls (as in the image)

pure adder
#

It would require different chat message template and I am bit busy to implement that atm

severe wasp
#

alright, was just curious! the whole system is awesome though

severe wasp
#

hello again, I'm trying to code in an optional thing where you can shift-click the macro and then get to choose a specific critical damage (mostly for nine lives and slayer, but maybe itll be relevant in other cases too), but I'm not really able to make it work

#

here's the mess I have rn, but thats mostly just from like testing stuff to understand js which i dont know anything about

(async function () {
  if (!event.shiftKey){
    const results = await game.tables.getName("Critical Damage RollTable").roll();
    const result = results.results[0];
    const chatData = {
        content: `<div class="chat-item" style="text-align:center"><div class="border">
            <p style="padding:0px">@${result.data.collection}[${result.data.resultId}]</p>
            <p>Result: ${result.data.range[0]}</p>
            </div></div>`,
        card: game.items.get(result.data.resultId).sendToChat(),
    };
    ChatMessage.create(chatData, {});
  } else {
    let myValue = await Dialog.prompt({
      content: `<label>Specific Injury Number:</label><input type="number">`,
      callback: (html) => html.find('input').val() 
    });
    let myroll = new Roll(`${myValue}d1`);
    const table = await game.tables.getName("Critical Damage RollTable");
    let draw = table.draw({myroll});
    console.log(draw);
  };
})()
#

I have a different macro in which table.draw({a roll}) works to overwrite the roll formula, but it doesn't seem to work here?

#

Even then, i think I'd prefer to use .roll() to keep the format the same, but i can't find any documentation on how they all work..

#

@royal delta could you take a look when you have time? :)

royal delta
#
(async function (event) {
  if (!event.shiftKey){
...
severe wasp
#

that's actually almost the only part that does work lol

royal delta
#

Alright so you are getting a dialogue when pressing shift and nothing happens when not?

severe wasp
#

yep

#

when not pressing shift the thing works just like it should, but I'm not really sure how to pull a specific result from it since i can't really go by index

royal delta
#

Ah alright so the initial macro functions. That's good. Well one thing is you name the roll myRoll and then shorthand reference it when drawing from the table. The thing is shorthand should refer to an actual property e.g. roll so rename the variable and change the reference to begin with.

#

Draw should then work

#

with a specific result

severe wasp
#

does the roll() function as used in the non-shift thing take a formula too?

royal delta
#

You can also just roll a value new Roll(myValue);

severe wasp
royal delta
#

You can refactor here to write less repetetive code.

severe wasp
#

i definitely can, i just don't have any experience with js so i wanted to get it working and then look into refactoring it :)

royal delta
severe wasp
#

that's perfect then

royal delta
#

Don't quote me on that as I am very rusty on the API

severe wasp
#

i'll test it, no worries

royal delta
severe wasp
#

what did you mean about the whole shorthand referencing thing? I'm not familiar with that term

royal delta
#

This is the same as RollTable.roll({roll: roll})

severe wasp
#

Ohh

#

Okay, that makes sense and is also pretty neat

royal delta
#

It's handy

#

Essentially what we are talking about is used as an example here:

// Draw results using a custom roll formula
const roll = new Roll("1d20 + @abilities.wis.mod", actor.getRollData());
const customResults = await table.roll({roll});
severe wasp
#

Yeah i see

#

I'll see if i can get it to work now, give me a minute

royal delta
#

Note that draw is also asynchronous. So if you want to wait for the results before console logging them you need to let draw = await table.draw({myroll});

severe wasp
#

Right

#

Also is there a module that makes the script box a little nicer to work in? Or do you good scripters use some external ide or something?

royal delta
#

Yeah I use an external editor (and I really recommend doing so since losing your code is on cmd/ctrl+r away).

#

There is a module that adds syntax highlighting though

severe wasp
#

Do you have to do the reload application thing to refresh the code in that case?

royal delta
#

Nono I just write out the code in vscode then paste it into foundry or run it in dev console.

severe wasp
#

Oh okay

severe wasp
#

hah, it works!

#
(async function () {
  let roll = null;
  if (event.shiftKey){
    let myValue = await Dialog.prompt({
      content: `<label>Specific Injury Number:</label><input type="number">`,
      callback: (html) => html.find('input').val() 
    });
    roll = new Roll(myValue);
  };
    const results = await game.tables.getName("Critical Damage RollTable").roll({roll});
    const result = results.results[0];
    const chatData = {
        content: `<div class="chat-item" style="text-align:center"><div class="border">
            <p style="padding:0px">@${result.data.collection}[${result.data.resultId}]</p>
            <p>Result: ${result.data.range[0]}</p>
            </div></div>`,
        card: game.items.get(result.data.resultId).sendToChat(),
    };
    ChatMessage.create(chatData, {});
})()
severe wasp
#

dont know if doing let roll = null makes sense but it works so im happy lol

royal delta
severe wasp
#

Cool that's like in lua :)

sonic glacier
#

With that macro, where does the data that shows up in chat come from? Where is it stored and what part of the macro calls it up? (I have a very minimal understanding of how to code. My evel is basically: I can tweak someone else's macros for my own needs, but I would not be able to write a macro from scratch.)

royal delta
severe wasp
#

as far as i understand it, the card shows up because of the game.items.get(result.data.resultId).sendToChat()bit, and the smaller message is from ChatMessage.create, though both may be from the latter, i just think it still sent the card without chatmessage.create

royal delta
severe wasp
#

it is there in the script you sent

sonic glacier
royal delta
royal delta
#

So MYZ, FBL, probably Vaesen and some others may support this Macro

sonic glacier
#

Coriolis?

royal delta
sonic glacier
#

Or I could just test it when I get a chance.