-
Notifications
You must be signed in to change notification settings - Fork 1
Examples
muhahahahe edited this page Jul 16, 2024
·
5 revisions
The examples use the DnD5e system but it should work in any system.
The values used in the examples:


values are being applied to the rolls

// Get the "DamageFormula" value from Sheexcel with the actor id
let refFormula = game.sheexcel.getSheexcelValue("0vGDwnZ67AklqbM1", "DamageFormula");
if (!refFormula.value) {
ui.notifications.warn("No 'DamageFormula' value found in the Sheexcel sheet. Make sure you have a cell reference with the keyword 'DamageFormula'.");
return;
}
// Get more values from the actor if needed
let refMod = refFormula.actor.sheet.getSheexcelValue("DamageMod");
let totalRoll = refFormula.value.toString() + " + " + refMod;
// Parse the roll value and create a Roll object
let roll = new Roll(totalRoll);
// Execute the roll
roll.evaluate().then(() => {
// Create the chat message content with detailed roll information
let messageContent = `<h2>${refFormula.actor.name} makes an attack roll!</h2>`;
// Add roll formula
messageContent += `<p><strong>Roll Formula:</strong> ${roll.formula}</p>`;
// Add individual term results
messageContent += `<p><strong>Term Results:</strong></p><ul>`;
roll.terms.forEach(term => {
if (term instanceof Die) {
messageContent += `<li>Dice (${term.number}d${term.faces}): ${term.total}</li>`;
} else if (term instanceof NumericTerm) {
messageContent += `<li>Modifier: ${term.number}</li>`;
}
});
messageContent += `</ul>`;
// Add total
messageContent += `<p><strong>Total:</strong> ${roll.total}</p>`;
// Create a chat message
ChatMessage.create({
user: game.user.id,
speaker: ChatMessage.getSpeaker({actor: refFormula.actor}),
content: messageContent,
rolls: roll
});
});
or use a selected token:
// Get the selected token
let selectedToken = canvas.tokens.controlled[0];
if (!selectedToken) {
ui.notifications.warn("Please select a token first.");
return;
}
let actor = selectedToken.actor;
if (!actor) {
ui.notifications.error("The selected token has no associated actor.");
return;
}
// Get the desired reference
let value = actor.sheet.getSheexcelValue("Description")
// Create a new chat message
ChatMessage.create({
user: game.user.id,
speaker: ChatMessage.getSpeaker({actor: actor}),
content: value
});