Combat.prototype.rollInitiative = async function ( ids, formula = null, messageOptions = {} ) { console.log( `${game.data.system.data.title} | Combat.rollInitiative()`, ids, formula, messageOptions ); // Structure input data ids = typeof ids === "string" ? [ids] : ids; const currentId = this.combatant._id; // calculate initiative if (ids.length == 1) { const c = this.getCombatant(ids[0]); if (!c) return results; const cf = formula || this._getInitiativeFormula(c); const roll = this._getInitiativeRoll(c, cf); const updates = this.combatants .filter( (combatant) => !combatant.actor || combatant.actor.data.type == "character" ) .map((combatant) => { return { _id: combatant._id, initiative: roll.total }; }); if (!updates.length) return this; // Update multiple combatants await this.updateEmbeddedEntity("Combatant", updates); // Ensure the turn order remains with the same combatant await this.update({ turn: this.turns.findIndex((t) => t._id === currentId), }); // Send a chat message let rollMode = messageOptions.rollMode || game.settings.get("core", "rollMode"); let messageData = mergeObject( { speaker: { scene: canvas.scene._id, actor: c.actor ? c.actor._id : null, token: c.token._id, alias: c.token.name, sound: CONFIG.sounds.dice, }, flavor: `${c.token.name} rolls for Party Initiative!`, }, messageOptions ); roll.toMessage(messageData, { rollMode, create: true }); return this; } };