'use strict'; /* global on log playerIsGM findObjs getObj getAttrByName sendChat globalconfig */ /* CASHMASTER 0.7.0 A currency management script for the D&D 5e OGL sheets on roll20.net. Please use `!cm` for inline help and examples. arthurbauer@me.com */ // How much each coing is worth of those below it. // In order: pp, gp, ep, sp var conversionRatio = [10, 2, 5, 10]; var cashsplit = function cashsplit(c, m, x) { //! cashsplit var ct = 0; var cr = 0; if (c !== null) { ct = Math.floor(c / m); cr = c % m; if (cr >= x || c < 0 && cr < 0 && -cr < x) { ct += 1; } } return ct; }; var getattr = function getattr(cid, att) { //! getattr var attr = findObjs({ type: 'attribute', characterid: cid, name: att })[0]; if (attr) { return attr.get('current'); } return ''; }; var setattr = function setattr(cid, att, val) { //! setattr var attr = findObjs({ type: 'attribute', characterid: cid, name: att })[0]; if (typeof attr === 'undefined' || attr == null) { var _attr = createObj('attribute', { name: att, characterid: cid, current: parseFloat(val) }); // eslint-disable-line no-unused-vars, no-undef, no-shadow } else { attr.setWithWorker({ current: parseFloat(val) }); // .set() } }; var changeMoney = function changeMoney(startamount, addamount) { //! changeMoney if (addamount !== null) { var total = startamount; var currency = addamount.slice(-2); var amount2 = -parseFloat(addamount.substr(0, addamount.length - 2)); var origamount = total; var amount3 = 0; if (currency === 'cp') { amount3 = amount2 / 100; } if (currency === 'sp') { amount3 = amount2 / 10; } if (currency === 'ep') { amount3 = amount2 / 2; } if (currency === 'gp') { amount3 = amount2; } if (currency === 'pp') { amount3 = amount2 * 10; } if (total[0] * 10 + total[1] + total[2] / 2 + total[3] / 10 + total[4] / 100 >= -amount3) { total[4] += amount3 * 100; while (total[4] < 0) { total[4] += 10; total[3] -= 1; } // cp while (total[3] < 0) { if (total[4] >= 10) { total[4] -= 10; total[3] += 1; } else { total[3] += 5; total[2] -= 1; } } // sp while (total[2] < 0) { if (total[3] >= 5) { total[3] -= 5; total[2] += 1; } else { total[2] += 2; total[1] -= 1; } } // ep while (total[1] < 0) { if (total[2] >= 2) { total[2] -= 2; total[1] += 1; } else { total[1] += 10; total[0] -= 1; } } // gp while (total[0] < 0) { if (total[1] >= 10) { total[1] -= 10; total[0] += 1; } else { total = origamount; return 'ERROR: Not enough cash.'; } } // pp return total; } return 'ERROR: Not enough cash.'; } return 0; }; // Merge funds into the densest denomination possible. // Account expects {pp, gp, ep, sp, cp} var mergeMoney = function mergeMoney(account) { if (account == null) { return 'ERROR: Acount does not exist.'; } if (account.length !== 5) { return 'ERROR: Account must be an array in the order of {pp, gp, ep, sp, cp}.'; } for (var i = account.length - 1; i > 0; i -= 1) { var coinCount = account[i]; var carry = Math.floor(coinCount / conversionRatio[i - 1]); var remainder = coinCount % conversionRatio[i - 1]; account[i] = remainder; // eslint-disable-line no-param-reassign account[i - 1] += carry; // eslint-disable-line no-param-reassign } return account; }; var toUsd = function toUsd(total) { var usd = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 110; //! toUsd var output = ''; if (usd > 0) { output = total + ' gp
(~ ' + Math.round(total * usd / 5) * 5 + ' USD)
'; } else { output = total + ' gp'; } return output; }; var playerCoinStatus = function playerCoinStatus(character) { var usd = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 110; //! playerCoinStatus var name = getAttrByName(character.id, 'character_name'); var pp = parseFloat(getattr(character.id, 'pp')) || 0; var gp = parseFloat(getattr(character.id, 'gp')) || 0; var ep = parseFloat(getattr(character.id, 'ep')) || 0; var sp = parseFloat(getattr(character.id, 'sp')) || 0; var cp = parseFloat(getattr(character.id, 'cp')) || 0; var total = Math.round((pp * 10 + ep * 0.5 + gp + sp / 10 + cp / 100) * 10000) / 10000; var weight = (pp + gp + ep + sp + cp) / 50; var output = name + ': $' + toUsd(total, usd) + '
'; if (pp) output += '' + pp + ' pp, '; if (gp) output += '' + gp + ' gp, '; if (ep) output += '' + ep + ' ep, '; if (sp) output += '' + sp + ' sp, '; if (cp) output += '' + cp + ' cp'; output += '
(' + weight + ' lbs)


'; return [output, total]; }; on('ready', function () { var v = '0.7.0'; // version number var usd = 110; /* Change this if you want to have a rough estimation of a character’s wealth in USD. After some research I believe a reasonable exchange ratio is roughly 1 gp = 110 USD Set it to 0 to disable it completely. */ var scname = 'CashMaster'; // script name var selectedsheet = 'OGL'; // You can set this to "5E-Shaped" if you're using the Shaped sheet // detecting useroptions from one-click if (globalconfig && globalconfig.cashmaster && globalconfig.cashmaster.useroptions) { selectedsheet = globalconfig.cashmaster.useroptions.selectedsheet; // eslint-disable-line prefer-destructuring } var rt = ''; if (selectedsheet === 'OGL') { rt = ['desc', 'desc']; } else if (selectedsheet === '5E-Shaped') { rt = ['5e-shaped', 'text']; } else { rt = ['default', 'name=' + scname + ' }}{{note']; } log(scname + ' v' + v + ' online. Select one or more party members, then use `!cm -help`'); var pp = void 0; var gp = void 0; var ep = void 0; var sp = void 0; var cp = void 0; var total = void 0; var output = void 0; var ppa = void 0; var gpa = void 0; var epa = void 0; var spa = void 0; var cpa = void 0; var ppg = void 0; var gpg = void 0; var epg = void 0; var spg = void 0; var cpg = void 0; var name = void 0; var usd2 = void 0; on('chat:message', function (msg) { if (msg.type !== 'api') return; if (msg.content.startsWith('!cm') !== true) return; if (msg.selected == null) { sendChat(scname, '/w gm **ERROR:** You need to select at least one character.'); return; } if (msg.content.includes('-help') || msg.content === '!cm' || msg.content.includes('-h')) { //! help sendChat(scname, '/w gm

CashMaster

A currency management script for the D&D 5e OGL and 5e Shaped sheets on Roll20.net.

Please use !cm for inline help and examples.

Setup

Make sure you use the correct sheet setting (OGL, 5E-Shaped, or other).

Usage

First, select one or several party members if you are the DM or your own token if you are a player.

Player Commands

GM Commands

Base commands

Payment commands

Conversion/Cleanup commands

Note: You can use several coin values at once, e.g. !cm -loot 50gp 150sp 2000cp or !cm -pay 2sp 5cp.

Examples

  1. !cm -overview will show a cash overview.
  2. !cm -add 50gp will add 50 gp to every selected character.
  3. !cm -loot 50gp will (more or less evenly) distribute 50 gp among the party members.
  4. !cm -pay 10gp will subtract 10gp from each selected character. It will try to exchange the other coin types (e.g. it will use 1pp if the player doesn't have 10gp).
  5. !cm -share will collect all the money and share it evenly on the members, using gp, sp and cp only (pp and ep will be converted). Can also be used for one character to 'exchange' money.
  6. !cm -transfer "Tazeka Cauldron" 40gp will transfer 40 gp from the selected token to the character sheet named Tazeka Cauldron.
  7. !cm -convert - same as !cm -share, but will also use platinum and electrum.

Credits

With thanks to Kryx/mlenser and Michael G./VoltCruelerz for their contributions.

'); // eslint-disable-line quotes } // Coin Transfer between players if (msg.content.includes('-transfer') || msg.content.includes('-t')) { ppg = /([0-9 -]+)pp/; ppa = ppg.exec(msg.content); gpg = /([0-9 -]+)gp/; gpa = gpg.exec(msg.content); epg = /([0-9 -]+)ep/; epa = epg.exec(msg.content); spg = /([0-9 -]+)sp/; spa = spg.exec(msg.content); cpg = /([0-9 -]+)cp/; cpa = cpg.exec(msg.content); // Retrieve target from quoted section of input var startQuote = msg.content.indexOf('"'); var endQuote = msg.content.lastIndexOf('"'); if (startQuote >= endQuote) { sendChat(scname, '**ERROR:** You must specify a target by name within double quotes.'); log('no quote'); return; } var targetName = msg.content.substring(startQuote + 1, endQuote); // Retrieve target's id var list = findObjs({ _type: 'character', name: targetName }); if (list.length === 0) { sendChat(scname, '**ERROR:** No character exists by the name ' + targetName + '.'); return; } else if (list.length > 1) { sendChat(scname, '**ERROR:** character name ' + targetName + ' must be unique.'); return; } var targetId = list[0].id; output = ''; var transactionOutput = ''; var donorOutput = ''; var targetOutput = ''; if (msg.selected.length > 1) { sendChat(scname, '**ERROR:** Transfers can only have on sender.'); return; } var donorName = ''; msg.selected.forEach(function (obj) { var token = getObj('graphic', obj._id); // eslint-disable-line no-underscore-dangle var donor = void 0; if (token) { donor = getObj('character', token.get('represents')); } if (donor) { // Check that the sender is not attempting to send money to themselves if (donor.id === targetId) { sendChat(scname, '**ERROR:** target character must not be selected character.'); return; } // Verify donor has enough to perform transfer // Check if the player attempted to steal from another and populate the transaction data transactionOutput += '
Transaction Data'; if (ppa !== null) { var val = parseFloat(ppa[1]); transactionOutput += '
' + ppa[0]; if (val < 0 && !playerIsGM(msg.playerid)) { sendChat(scname, '**ERROR:** ' + msg.who + ' may not demand payment from ' + targetName + '.'); return; } } if (gpa !== null) { var _val = parseFloat(gpa[1]); transactionOutput += '
' + gpa[0]; if (_val < 0 && !playerIsGM(msg.playerid)) { sendChat(scname, '**ERROR:** ' + msg.who + ' may not demand payment from ' + targetName + '.'); return; } } if (epa !== null) { var _val2 = parseFloat(epa[1]); transactionOutput += '
' + epa[0]; if (_val2 < 0 && !playerIsGM(msg.playerid)) { sendChat(scname, '**ERROR:** ' + msg.who + ' may not demand payment from ' + targetName + '.'); return; } } if (spa !== null) { var _val3 = parseFloat(spa[1]); transactionOutput += '
' + spa[0]; if (_val3 < 0 && !playerIsGM(msg.playerid)) { sendChat(scname, '**ERROR:** ' + msg.who + ' may not demand payment from ' + targetName + '.'); return; } } if (cpa !== null) { var _val4 = parseFloat(cpa[1]); transactionOutput += '
' + cpa[0]; if (_val4 < 0 && !playerIsGM(msg.playerid)) { sendChat(scname, '/w gm **ERROR:** ' + msg.who + ' may not demand payment from ' + targetName + '.'); return; } } // Load donor's existing account donorName = getAttrByName(donor.id, 'character_name'); var dpp = parseFloat(getattr(donor.id, 'pp')) || 0; var dgp = parseFloat(getattr(donor.id, 'gp')) || 0; var dep = parseFloat(getattr(donor.id, 'ep')) || 0; var dsp = parseFloat(getattr(donor.id, 'sp')) || 0; var dcp = parseFloat(getattr(donor.id, 'cp')) || 0; var donorAccount = [dpp, dgp, dep, dsp, dcp]; if (ppa !== null) donorAccount = changeMoney(donorAccount, ppa[0]); if (gpa !== null) donorAccount = changeMoney(donorAccount, gpa[0]); if (epa !== null) donorAccount = changeMoney(donorAccount, epa[0]); if (spa !== null) donorAccount = changeMoney(donorAccount, spa[0]); if (cpa !== null) donorAccount = changeMoney(donorAccount, cpa[0]); // Verify donor has enough to perform transfer donorOutput += '
' + donorName + ' has '; if (donorAccount === 'ERROR: Not enough cash.') { donorOutput += 'not enough cash!'; } else { // Update donor account and update output setattr(donor.id, 'pp', parseFloat(donorAccount[0])); setattr(donor.id, 'gp', parseFloat(donorAccount[1])); setattr(donor.id, 'ep', parseFloat(donorAccount[2])); setattr(donor.id, 'sp', parseFloat(donorAccount[3])); setattr(donor.id, 'cp', parseFloat(donorAccount[4])); donorOutput += '
' + donorAccount[0] + 'pp'; donorOutput += '
' + donorAccount[1] + 'gp'; donorOutput += '
' + donorAccount[2] + 'ep'; donorOutput += '
' + donorAccount[3] + 'sp'; donorOutput += '
' + donorAccount[4] + 'cp'; // targetFunds var tpp = parseFloat(getattr(targetId, 'pp')) || 0; var tgp = parseFloat(getattr(targetId, 'gp')) || 0; var tep = parseFloat(getattr(targetId, 'ep')) || 0; var tsp = parseFloat(getattr(targetId, 'sp')) || 0; var tcp = parseFloat(getattr(targetId, 'cp')) || 0; if (ppa !== null) tpp += parseFloat(ppa[1]); if (gpa !== null) tgp += parseFloat(gpa[1]); if (epa !== null) tep += parseFloat(epa[1]); if (spa !== null) tsp += parseFloat(spa[1]); if (cpa !== null) tcp += parseFloat(cpa[1]); setattr(targetId, 'pp', tpp); setattr(targetId, 'gp', tgp); setattr(targetId, 'ep', tep); setattr(targetId, 'sp', tsp); setattr(targetId, 'cp', tcp); targetOutput += '
' + targetName + ' has '; targetOutput += '
' + tpp + 'pp'; targetOutput += '
' + tgp + 'gp'; targetOutput += '
' + tep + 'ep'; targetOutput += '
' + tsp + 'sp'; targetOutput += '
' + tcp + 'cp'; } } }); sendChat(scname, '/w gm &{template:' + rt[0] + '} {{' + rt[1] + '=GM Transfer Report
' + donorName + '>' + targetName + '
' + transactionOutput + donorOutput + targetOutput + '}}'); sendChat(scname, '/w ' + msg.who + ' &{template:' + rt[0] + '} {{' + rt[1] + '=Sender Transfer Report
' + donorName + ' > ' + targetName + '
' + output + transactionOutput + donorOutput + '}}'); sendChat(scname, '/w ' + targetName + ' &{template:' + rt[0] + '} {{' + rt[1] + '=Recipient Transfer Report
' + donorName + ' > ' + targetName + '
' + output + transactionOutput + targetOutput + '}}'); return; } if (msg.content.includes('-status') || msg.content.includes('-s')) { output = ''; msg.selected.forEach(function (obj) { var token = getObj('graphic', obj._id); // eslint-disable-line no-underscore-dangle var character = void 0; if (token) { character = getObj('character', token.get('represents')); } if (character) { var coinStatus = playerCoinStatus(character); sendChat(scname, '/w ' + msg.who + ' &{template:' + rt[0] + '} {{' + rt[1] + '=Coin Purse Status
' + coinStatus[0] + '}}'); } }); return; } // GM-Only Commands if (playerIsGM(msg.playerid)) { // Calculate pre-existing party total var partytotal = 0; var partycounter = 0; var partymember = Object.entries(msg.selected).length; msg.selected.forEach(function (obj) { var token = getObj('graphic', obj._id); // eslint-disable-line no-underscore-dangle var character = void 0; if (token) { character = getObj('character', token.get('represents')); } if (character) { partycounter += 1; name = getAttrByName(character.id, 'character_name'); pp = parseFloat(getattr(character.id, 'pp')) || 0; gp = parseFloat(getattr(character.id, 'gp')) || 0; ep = parseFloat(getattr(character.id, 'ep')) || 0; sp = parseFloat(getattr(character.id, 'sp')) || 0; cp = parseFloat(getattr(character.id, 'cp')) || 0; total = Math.round((pp * 10 + ep * 0.5 + gp + sp / 10 + cp / 100) * 10000) / 10000; partytotal = total + partytotal; } }); partytotal = Math.round(partytotal * 100, 0) / 100; // Merge a player's coin into the densest possible if (msg.content.includes('-merge') || msg.content.includes('-m')) { output = ''; msg.selected.forEach(function (obj) { var token = getObj('graphic', obj._id); // eslint-disable-line no-underscore-dangle var character = void 0; if (token) { character = getObj('character', token.get('represents')); } if (character) { // Load player's existing account var characterName = getAttrByName(character.id, 'character_name'); var playerAccount = [parseFloat(getattr(character.id, 'pp')) || 0, parseFloat(getattr(character.id, 'gp')) || 0, parseFloat(getattr(character.id, 'ep')) || 0, parseFloat(getattr(character.id, 'sp')) || 0, parseFloat(getattr(character.id, 'cp')) || 0]; var mergeResult = mergeMoney(playerAccount); if (mergeResult.length == null) { output += '
' + characterName + ' has '; output += mergeResult; output += '
' + playerAccount[0] + 'pp'; output += '
' + playerAccount[1] + 'gp'; output += '
' + playerAccount[2] + 'ep'; output += '
' + playerAccount[3] + 'sp'; output += '
' + playerAccount[4] + 'cp'; return; } // Udate donor account and update output setattr(character.id, 'pp', parseFloat(mergeResult[0])); setattr(character.id, 'gp', parseFloat(mergeResult[1])); setattr(character.id, 'ep', parseFloat(mergeResult[2])); setattr(character.id, 'sp', parseFloat(mergeResult[3])); setattr(character.id, 'cp', parseFloat(mergeResult[4])); output += '
' + characterName + ' has '; output += '
' + mergeResult[0] + 'pp'; output += '
' + mergeResult[1] + 'gp'; output += '
' + mergeResult[2] + 'ep'; output += '
' + mergeResult[3] + 'sp'; output += '
' + mergeResult[4] + 'cp'; } sendChat(scname, '/w gm &{template:' + rt[0] + '} {{' + rt[1] + '=Coin Merge Report
' + output + '}}'); }); } // Reallocate existing resources of party as if all coin purses were thrown together and split evenly if (msg.content.includes('-share') || msg.content.includes('-best-share') || msg.content.includes('-s') || msg.content.includes('-bs')) { //! share and convert output = ''; var cashshare = partytotal / partycounter; var newcounter = 0; var pps = Math.floor(cashshare / 10); if (msg.content.includes('-share') || msg.content.includes('-s')) { pps = 0; } var rest = cashshare - pps * 10; var gps = Math.floor(rest); rest = (rest - gps) * 2; var eps = Math.floor(rest); if (msg.content.includes('-share') || msg.content.includes('-s')) { eps = 0; } rest = (rest - eps) * 5; var sps = Math.floor(rest); rest = (rest - sps) * 10; var cps = Math.round(rest); rest = (rest - cps) * partycounter; sendChat(scname, '/w gm &{template:' + rt[0] + '} {{' + rt[1] + '=Let\u2019s share this!
Everyone receives the equivalent of ' + toUsd(cashshare) + ' gp: ' + pps + ' platinum, ' + gps + ' gold, ' + eps + ' electrum, ' + sps + ' silver, and ' + cps + ' copper.}}'); msg.selected.forEach(function (obj) { var token = getObj('graphic', obj._id); // eslint-disable-line no-underscore-dangle var character = void 0; newcounter += 1; if (token) { character = getObj('character', token.get('represents')); } if (character) { setattr(character.id, 'pp', pps); setattr(character.id, 'gp', gps); setattr(character.id, 'ep', eps); setattr(character.id, 'sp', sps); // enough copper coins? If not, the last one in the group has to take the diff if ((rest > 0.999 || rest < -0.999) && newcounter === partycounter) { cps += Math.round(rest); } setattr(character.id, 'cp', cps); } }); } // Add coin to target if (msg.content.includes('-add') || msg.content.includes('-a')) { //! add ppg = /([0-9 -]+)pp/; ppa = ppg.exec(msg.content); gpg = /([0-9 -]+)gp/; gpa = gpg.exec(msg.content); epg = /([0-9 -]+)ep/; epa = epg.exec(msg.content); spg = /([0-9 -]+)sp/; spa = spg.exec(msg.content); cpg = /([0-9 -]+)cp/; cpa = cpg.exec(msg.content); output = ''; msg.selected.forEach(function (obj) { var token = getObj('graphic', obj._id); // eslint-disable-line no-underscore-dangle var character = void 0; if (token) { character = getObj('character', token.get('represents')); } if (character) { partycounter += 1; name = getAttrByName(character.id, 'character_name'); pp = parseFloat(getattr(character.id, 'pp')) || 0; gp = parseFloat(getattr(character.id, 'gp')) || 0; ep = parseFloat(getattr(character.id, 'ep')) || 0; sp = parseFloat(getattr(character.id, 'sp')) || 0; cp = parseFloat(getattr(character.id, 'cp')) || 0; total = Math.round((pp * 10 + ep * 0.5 + gp + sp / 10 + cp / 100) * 10000) / 10000; partytotal = total + partytotal; output += '
' + name + ''; if (ppa) { setattr(character.id, 'pp', parseFloat(pp) + parseFloat(ppa[1])); output += '
' + ppa[0]; } if (gpa) { setattr(character.id, 'gp', parseFloat(gp) + parseFloat(gpa[1])); output += '
' + gpa[0]; } if (epa) { setattr(character.id, 'ep', parseFloat(ep) + parseFloat(epa[1])); output += '
' + epa[0]; } if (spa) { setattr(character.id, 'sp', parseFloat(sp) + parseFloat(spa[1])); output += '
' + spa[0]; } if (cpa) { setattr(character.id, 'cp', parseFloat(cp) + parseFloat(cpa[1])); output += '
' + cpa[0]; } } sendChat(scname, '/w ' + name + ' &{template:' + rt[0] + '} {{' + rt[1] + '=GM has Disbursed Coin
' + output + '}}'); }); var s = msg.selected.length > 1 ? 's' : ''; sendChat(scname, '/w gm &{template:' + rt[0] + '} {{' + rt[1] + '=Disbursement to Player' + s + '
' + output + '}}'); } // Subtract coin from target if (msg.content.includes('-pay') || msg.content.includes('-p')) { //! pay ppg = /([0-9 -]+)pp/; ppa = ppg.exec(msg.content); gpg = /([0-9 -]+)gp/; gpa = gpg.exec(msg.content); epg = /([0-9 -]+)ep/; epa = epg.exec(msg.content); spg = /([0-9 -]+)sp/; spa = spg.exec(msg.content); cpg = /([0-9 -]+)cp/; cpa = cpg.exec(msg.content); output = ''; msg.selected.forEach(function (obj) { var token = getObj('graphic', obj._id); // eslint-disable-line no-underscore-dangle var character = void 0; if (token) { character = getObj('character', token.get('represents')); } if (character) { partycounter += 1; name = getAttrByName(character.id, 'character_name'); pp = parseFloat(getattr(character.id, 'pp')) || 0; gp = parseFloat(getattr(character.id, 'gp')) || 0; ep = parseFloat(getattr(character.id, 'ep')) || 0; sp = parseFloat(getattr(character.id, 'sp')) || 0; cp = parseFloat(getattr(character.id, 'cp')) || 0; var startamount = [pp, gp, ep, sp, cp]; if (ppa !== null) startamount = changeMoney(startamount, ppa[0]); if (gpa !== null) startamount = changeMoney(startamount, gpa[0]); if (epa !== null) startamount = changeMoney(startamount, epa[0]); if (spa !== null) startamount = changeMoney(startamount, spa[0]); if (cpa !== null) startamount = changeMoney(startamount, cpa[0]); output += '
' + name + ' has '; if (startamount === 'ERROR: Not enough cash.') output += 'not enough cash!';else { setattr(character.id, 'pp', parseFloat(startamount[0])); output += '
' + startamount[0] + 'pp'; setattr(character.id, 'gp', parseFloat(startamount[1])); output += '
' + startamount[1] + 'gp'; setattr(character.id, 'ep', parseFloat(startamount[2])); output += '
' + startamount[2] + 'ep'; setattr(character.id, 'sp', parseFloat(startamount[3])); output += '
' + startamount[3] + 'sp'; setattr(character.id, 'cp', parseFloat(startamount[4])); output += '
' + startamount[4] + 'cp'; } } sendChat(scname, '/w ' + name + ' &{template:' + rt[0] + '} {{' + rt[1] + '=GM has Removed Coin
' + output + '}}'); }); var _s = msg.selected.length > 1 ? 's' : ''; sendChat(scname, '/w gm &{template:' + rt[0] + '} {{' + rt[1] + '=Bill Collection from Player' + _s + '
' + output + '}}'); } // Evenly distribute sum of coin to group of players if (msg.content.includes('-loot') || msg.content.includes('-l')) { //! loot ppg = /([0-9 -]+)pp/; ppa = ppg.exec(msg.content); gpg = /([0-9 -]+)gp/; gpa = gpg.exec(msg.content); epg = /([0-9 -]+)ep/; epa = epg.exec(msg.content); spg = /([0-9 -]+)sp/; spa = spg.exec(msg.content); cpg = /([0-9 -]+)cp/; cpa = cpg.exec(msg.content); output = ''; partycounter = 0; msg.selected.forEach(function (obj) { var token = getObj('graphic', obj._id); // eslint-disable-line no-underscore-dangle var character = void 0; if (token) { character = getObj('character', token.get('represents')); } if (character) { partycounter += 1; name = getAttrByName(character.id, 'character_name'); pp = parseFloat(getattr(character.id, 'pp')) || 0; gp = parseFloat(getattr(character.id, 'gp')) || 0; ep = parseFloat(getattr(character.id, 'ep')) || 0; sp = parseFloat(getattr(character.id, 'sp')) || 0; cp = parseFloat(getattr(character.id, 'cp')) || 0; var ppt = void 0; var gpt = void 0; var ept = void 0; var spt = void 0; var cpt = void 0; if (ppa !== null) { ppt = cashsplit(ppa[1], partymember, partycounter); } if (gpa !== null) { gpt = cashsplit(gpa[1], partymember, partycounter); } if (epa !== null) { ept = cashsplit(epa[1], partymember, partycounter); } if (spa !== null) { spt = cashsplit(spa[1], partymember, partycounter); } if (cpa !== null) { cpt = cashsplit(cpa[1], partymember, partycounter); } output += '
' + name + ''; if (ppa) { setattr(character.id, 'pp', parseFloat(pp) + parseFloat(ppt)); output += '
' + ppt + 'pp'; } if (gpa) { setattr(character.id, 'gp', parseFloat(gp) + parseFloat(gpt)); output += '
' + gpt + 'gp'; } if (epa) { setattr(character.id, 'ep', parseFloat(ep) + parseFloat(ept)); output += '
' + ept + 'ep'; } if (spa) { setattr(character.id, 'sp', parseFloat(sp) + parseFloat(spt)); output += '
' + spt + 'sp'; } if (cpa) { setattr(character.id, 'cp', parseFloat(cp) + parseFloat(cpt)); output += '
' + cpt + 'cp'; } sendChat(scname, '/w ' + name + ' &{template:' + rt[0] + '} {{' + rt[1] + '=Distributing Loot
' + output + '}}'); } }); sendChat(scname, '/w gm &{template:' + rt[0] + '} {{' + rt[1] + '=Distributing Loot
' + output + '}}'); } // Calculate party gold value if (msg.content.includes('-add') || msg.content.includes('-pay') || msg.content.includes('-share') || msg.content.includes('-best-share') || msg.content.includes('-loot') || msg.content.includes('-overview') || msg.content.includes('-a') || msg.content.includes('-p') || msg.content.includes('-s') || msg.content.includes('-bs') || msg.content.includes('-l') || msg.content.includes('-o')) { //! overview partytotal = 0; partycounter = 0; if (!msg.content.includes('--usd')) usd2 = 0;else usd2 = usd; output = '/w gm &{template:' + rt[0] + '} {{' + rt[1] + '=Party\u2019s cash overview

'; msg.selected.forEach(function (obj) { var token = getObj('graphic', obj._id); // eslint-disable-line no-underscore-dangle var character = void 0; if (token) { character = getObj('character', token.get('represents')); } if (character) { output += playerCoinStatus(character, usd2)[0]; partytotal += playerCoinStatus(character, usd2)[1]; } }); partytotal = Math.round(partytotal * 100, 0) / 100; output += 'Party total: ' + toUsd(partytotal, usd2) + '}}'; sendChat(scname, output); } } else if (msg.content.includes('-add') || msg.content.includes('-pay') || msg.content.includes('-share') || msg.content.includes('-best-share') || msg.content.includes('-loot') || msg.content.includes('-merge') || msg.content.includes('-overview') || msg.content.includes('-a') || msg.content.includes('-p') || msg.content.includes('-s') || msg.content.includes('-bs') || msg.content.includes('-l') || msg.content.includes('-o') || msg.content.includes('-m')) { sendChat(scname, '/w ' + msg.who + ' **ERROR:** You do not have permission to use that action.'); sendChat(scname, '/w gm **WARNING:** ' + msg.who + ' attempted to use a GM-Only command.'); } }); });