#Roll Table macro
1 messages · Page 1 of 1 (latest)
Macro? This is just a rollable table right now
Ah, in which case you'd need a macro.
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?
The unofficial Mutant Year Zero one :)
Alright. I am not familiar with the API there. So I am not sure how to conjure the chat card.
So there's no like standardized way to emulate the little button to send stuff to the chat log?
No, no. Some systems have it some don't. Those who implement it may call it by different names. E.g. in Forbidden Lands it is named sendToChat() and exists on the item itself and not the item sheet.
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
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 :)
Hi therem, hm... I am trying to understand the request
haha sorry!
so instead of link to the crit in the chat you want to have full description in a chat card
is that correct ?
well ideally i'd like to have both, i think
such that it's still easy to drag the crit onto a sheet
you can drag it
just drag that crit link if that is all you need
or click on it
it is a link
yeah that part works, i'd just like it to also post the actual chat card thing as well
once on the sheet you'll see a chat bubble next to it
so it'd look something like this immediately after rolling on the table, instead of needing to press the chat bubble
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, {});
})()```
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
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
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, {});
})()```
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)
It would require different chat message template and I am bit busy to implement that atm
alright, was just curious! the whole system is awesome though
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? :)
Yeah I was looking at it, and one thing here is that I am not certain that event.shiftKey would work? I am not aware that macros pass an event argument in any way, but if they do you need to declare it as a parameter to the function
(async function (event) {
if (!event.shiftKey){
...
that's actually almost the only part that does work lol
Alright so you are getting a dialogue when pressing shift and nothing happens when not?
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
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
does the roll() function as used in the non-shift thing take a formula too?
You can also just roll a value new Roll(myValue);
Sure
would that still give a roll that can only be one value?
You can refactor here to write less repetetive code.
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 :)
Yeah afaik a roll can actually take a constant number as a string
that's perfect then
Don't quote me on that as I am very rusty on the API
i'll test it, no worries
For ref: https://foundryvtt.com/api/Roll.html
Documentation for the client-side JavaScript API in Foundry Virtual Tabletop.
what did you mean about the whole shorthand referencing thing? I'm not familiar with that term
In JS you can shorthand reference a variable that has the same name as an object property when passing it into another object. E.g. const roll = "1d6"... RollTable.roll({roll})
This is the same as RollTable.roll({roll: roll})
It's handy
Here's ref on rolltable rolls https://foundryvtt.com/api/RollTable.html#roll
Documentation for the client-side JavaScript API in Foundry Virtual Tabletop.
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});
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});
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?
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
Do you have to do the reload application thing to refresh the code in that case?
Introduces the "Ajax.org Cloud9 Editor" to Foundry VTT for editing Macro scripts.This editor enhances Foundry's Macro Editor with useful features …
Nono I just write out the code in vscode then paste it into foundry or run it in dev console.
Oh okay
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, {});
})()
Naisu!
dont know if doing let roll = null makes sense but it works so im happy lol
Is ok:) you could also just let roll;
Cool that's like in lua :)
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.)
It's a rolltable made up of "entities" (items). The macro looks up the items referenced in the table.
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
This is correct. The card property doesn't exist on ChatMessage. I'm not sure why it was written this way. That part is not something I wrote, I think.
it is there in the script you sent
And where are the entities that the table references? When you say "items" are those specifically things in the "items" tab? Journal entries? Some other sort of asset? (I appreciate the guidance. I'm just knowledgable about this sort of thing to know how much I don't know.)
I think I stole part of it from somewhere.
Items in the items tab. But then this is specifically tailored to systems which have items with a method named sendToChat() if the items in the system doesn't have this method it will simply fail.
So MYZ, FBL, probably Vaesen and some others may support this Macro
Coriolis?
Good question! I am not sure. @upper plaza may be able to tell you whether it would work.
Or I could just test it when I get a chance.