Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let actors = canvas.tokens.controlled.map(({ actor }) => actor);
- let actorCount = actors.length;
- let actorIncrement = 0;
- let randomActor = Math.floor(Math.random() * actorCount);
- let winningActor = '';
- let permissionCheck = false;
- if (game.user.isGM == true || game.user.isTrusted == true) { permissionCheck = true; }
- function awardCurrency(totalPP, totalGP, totalEP, totalSP, totalCP)
- {
- let splitPP = Math.floor(totalPP / actorCount);
- let splitGP = Math.floor(totalGP / actorCount);
- let splitEP = Math.floor(totalEP / actorCount);
- let splitSP = Math.floor(totalSP / actorCount);
- let splitCP = Math.floor(totalCP / actorCount);
- let leftoverPP = totalPP % actorCount;
- let leftoverGP = totalGP % actorCount;
- let leftoverEP = totalEP % actorCount;
- let leftoverSP = totalSP % actorCount;
- let leftoverCP = totalCP % actorCount;
- actors.forEach(actor =>
- {
- if(actorIncrement == randomActor)
- {
- winningActor = actor.data.name;
- actor.data.data.currency.pp += splitPP + leftoverPP;
- actor.data.data.currency.gp += splitGP + leftoverGP;
- actor.data.data.currency.ep += splitEP + leftoverEP;
- actor.data.data.currency.sp += splitSP + leftoverSP;
- actor.data.data.currency.cp += splitCP + leftoverCP;
- }
- else
- {
- actor.data.data.currency.pp += splitPP;
- actor.data.data.currency.gp += splitGP;
- actor.data.data.currency.ep += splitEP;
- actor.data.data.currency.sp += splitSP;
- actor.data.data.currency.cp += splitCP;
- }
- actorIncrement++;
- });
- let strOutput = "<b>Gave " + actorCount + " players each</b>: ";
- strOutput = strOutput + splitPP + "pp, ";
- strOutput = strOutput + splitGP + "gp, ";
- strOutput = strOutput + splitEP + "ep, ";
- strOutput = strOutput + splitSP + "sp, ";
- strOutput = strOutput + splitCP + "cp";
- if (leftoverPP != 0 || leftoverGP != 0 || leftoverEP != 0 || leftoverSP != 0 || leftoverCP != 0)
- {
- strOutput = strOutput + "<br /><b>" + winningActor + "</b> gets the excess (";
- strOutput = strOutput + leftoverPP + "pp, ";
- strOutput = strOutput + leftoverGP + "gp, ";
- strOutput = strOutput + leftoverEP + "ep, ";
- strOutput = strOutput + leftoverSP + "sp, ";
- strOutput = strOutput + leftoverCP + "cp";
- strOutput = strOutput + ")";
- }
- ChatMessage.create({content: strOutput});
- };
- let currencyTotals = permissionCheck ? `
- <b>Currency Totals:</b><br />
- <div style="display: flex; width: 100%; margin: 10px 0px 10px 0px">
- <label for="pp" style="white-space: nowrap; margin: 4px 10px 0px 10px;">PP:</label>
- <input type="number" id="pp" name="pp" />
- <label for="pp" style="white-space: nowrap; margin: 4px 10px 0px 10px;">GP:</label>
- <input type="number" id="gp" name="gp" />
- <label for="pp" style="white-space: nowrap; margin: 4px 10px 0px 10px;">EP:</label>
- <input type="number" id="ep" name="ep" />
- <label for="pp" style="white-space: nowrap; margin: 4px 10px 0px 10px;">SP:</label>
- <input type="number" id="sp" name="sp"/ >
- <label for="pp" style="white-space: nowrap; margin: 4px 10px 0px 10px;">CP:</label>
- <input type="number" id="cp" name="cp"/ >
- </div>
- ` : '';
- new Dialog({
- title: `Distribute Currency`,
- content: `
- <form>
- ${currencyTotals}
- </form>
- `,
- buttons: {
- yes: {
- icon: "<i class='fas fa-check'></i>",
- label: `Distribute`,
- callback: (html) => {
- let totalPP = html.find('#pp').val();
- let totalGP = html.find('#gp').val();
- let totalEP = html.find('#ep').val();
- let totalSP = html.find('#sp').val();
- let totalCP = html.find('#cp').val();
- if (totalPP == null || Number.isInteger(+totalPP) == false) { totalPP = 0; }
- if (totalGP == null || Number.isInteger(+totalGP) == false) { totalGP = 0; }
- if (totalEP == null || Number.isInteger(+totalEP) == false) { totalEP = 0; }
- if (totalSP == null || Number.isInteger(+totalSP) == false) { totalSP = 0; }
- if (totalCP == null || Number.isInteger(+totalCP) == false) { totalCP = 0; }
- if (permissionCheck) {
- awardCurrency(totalPP, totalGP, totalEP, totalSP, totalCP);
- }
- }
- },
- no: {
- icon: "<i class='fas fa-times'></i>",
- label: `Cancel`
- },
- },
- default: "yes"
- }).render(true)
RAW Paste Data