Skip to content

Commit

Permalink
Updated macros
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyVadala committed Oct 21, 2022
1 parent 9d16920 commit 37c8309
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions packs/macros-roll.db
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
{"_id":"fEzHEn3tGXXIRHpU","name":"Chartopia Roller","type":"script","author":"y5gmtwxmW3A5ZuOP","img":"icons/svg/dice-target.svg","scope":"global","command":"/**\n * Make a roll from chartopia and output the results in the chat window.\n * If you find yourself using this macro often, please support chartopia on patreon.\n */\n\n// chart id from url. IE 19449 is the chart id in https://chartopia.d12dev.com/chart/19449/\nlet chartId = 19449;\n// only let the gm see the results. false = everyone sees in chat. true = gm whispered results.\nlet gmOnly = false;\n\n\n//////////////////////////////////\n/// Don't edit past this point ///\n//////////////////////////////////\n\nvar rootUrl = \"https://chartopia.d12dev.com/test/\";\n\nfunction roll(id) {\n let request = new XMLHttpRequest();\n request.open('GET', rootUrl+'dice-roll-result?chart_id='+id, true);\n\n request.onload = function() {\n if (request.status >= 200 && request.status < 400) {\n // Success!\n let whisper = !!gmOnly ? game.users.map(u => {\n if (u.isGM) return u.id;\n }) : [];\n console.log('whisper',whisper);\n let chatData = {\n user: game.userId,\n speaker: ChatMessage.getSpeaker(),\n content: request.responseText,\n whisper\n };\n\n ChatMessage.create(chatData, {});\n } else {\n // We reached our target server, but it returned an error\n console.log(\"Server error.\");\n }\n };\n\n request.onerror = function() {\n // There was a connection error of some sort\n console.log(\"Error getting result.\");\n };\n\n request.send();\n} \n\nroll(chartId);","folder":null,"sort":0,"permission":{"default":0,"y5gmtwxmW3A5ZuOP":3},"flags":{}}
{"_id":"sXxLpBqCRhCQeGLV","name":"Mass Roll Check","type":"script","author":"y5gmtwxmW3A5ZuOP","img":"icons/svg/dice-target.svg","scope":"global","command":"/*\n* Gets a list of selected tokens (or defaults to the user's character), provides a list of\n* skills, and then makes a roll for all the selected tokens with that skill. It then spits out\n* the poorly-formatted results to chat (or the GM if you uncomment the whisper line).\n*/\n\nlet targetActors = getTargetActors().filter(a => a != null);\nfunction checkForActors(){\n if (!targetActors.length > 0)\n throw new Error('You must designate at least one token as the roll target');\n};\ncheckForActors();\n\n// Choose roll type dialog\nlet rollTypeTemplate = `\n<div>\n <div class=\"form-group\">\n <label>Choose roll type</label>\n <select id=\"selectedType\">\n <option value=\"save\">Saving Throw</option>\n <option value=\"ability\">Ability Check</option>\n <option value=\"skill\">Skill Check</option>\n </select>\n </div>\n</div>`;\n\nlet chooseCheckType = new Dialog({\n title: \"Choose check type\",\n content: rollTypeTemplate,\n buttons: {\n ok: {\n icon: '<i class=\"fas fa-check\"></i>',\n label: \"OK\",\n callback: async (html) => {\n let checkType = html.find(\"#selectedType\")[0].value;\n selectedCheckDialog(checkType).render(true);\n }\n },\n cancel: {\n icon: '<i class=\"fas fa-times\"></i>',\n label: 'Cancel'\n }\n },\n default: \"cancel\"\n});\n\n// Choose ability mod dialog\nfunction selectedCheckDialog(checkType) {\n\n let dialogTitle = getCheckDialogTitle(checkType);\n let dialogContent = getCheckTemplate(checkType);\n\n return new Dialog({\n title: dialogTitle,\n content: dialogContent,\n buttons: {\n ok: {\n icon: '<i class=\"fas fa-check\"></i>',\n label: \"OK\",\n callback: async (html) => {\n let id = html.find(\"#selectedAbility\")[0].value;\n\n let messageContent = `<div><h2>${checkType.toUpperCase()} Roll</h2></div>`\n for (let a of targetActors) {\n let name = a.name;\n let mod = 0; \n switch (checkType) {\n case \"save\":\n mod = a.data.data.abilities[id].save;\n messageContent += `${name}: <b>[[1d20+${mod}]]</b> (${game.dnd5e.config.abilities[id]} saving throw)<br>`;\n break;\n case \"ability\":\n mod = a.data.data.abilities[id].mod + a.data.data.abilities[id].checkBonus;\n messageContent += `${name}: <b>[[1d20+${mod}]]</b> (${game.dnd5e.config.abilities[id]} check)<br>`;\n break;\n case \"skill\":\n mod = a.data.data.skills[id].total;\n messageContent += `${name}: <b>[[1d20+${mod}]]</b> (${game.dnd5e.config.skills[id]} (${a.data.data.skills[id].ability}) check)<br>`;\n break;\n default:\n objects = game.dnd5e.config.skills;\n break;\n }\n }\n \n let chatData = {\n user: game.user.id,\n speaker: game.user,\n content: messageContent,\n // Uncomment the following line if you want the results whispered to the GM.\n // whisper: game.users.filter(u => u.isGM).map(u => u._id)\n };\n ChatMessage.create(chatData, {});\n }\n },\n cancel: {\n icon: '<i class=\"fas fa-times\"></i>',\n label: 'Cancel'\n }\n },\n default: \"cancel\"\n });\n}\n\n// Gets list of selected tokens, or if no tokens are selected then the user's character.\nfunction getTargetActors() {\n const character = game.user.character;\n const controlled = canvas.tokens.controlled;\n let actors = [];\n\n if (controlled.length === 0) return [character] || null;\n\n if (controlled.length > 0) {\n let actors = [];\n for (let i = 0; i < controlled.length; i++) {\n actors.push(controlled[i].actor);\n }\n\n return actors;\n}\nelse throw new Error('You must designate at least one token as the roll target');\n}\n\n\n// Gets a template of abilities or skills, based on the type of check chosen.\nfunction getCheckTemplate(checkType) {\n let objects = new Object();\n \n switch (checkType) {\n case \"save\":\n case \"ability\":\n objects = game.dnd5e.config.abilities;\n break;\n case \"skill\":\n objects = game.dnd5e.config.skills;\n break;\n default:\n objects = game.dnd5e.config.skills;\n break;\n }\n\n let template = `\n <div>\n <div class=\"form-group\">\n <label>Choose check</label>\n <select id=\"selectedAbility\">`\n \n for (let [checkId, check] of Object.entries(objects)) {\n template += `<option value=\"${checkId}\">${check}</option>`; \n } \n \n template += `</select>\n </div>\n </div>`;\n\n return template;\n}\n\nfunction getCheckDialogTitle(checkType) {\n switch (checkType) {\n case \"save\":\n return \"Saving Throw\"\n case \"ability\":\n return \"Ability Check\"\n case \"skill\":\n return \"Skill Check\"\n default:\n return \"Unknown Check\"\n }\n}\n\nchooseCheckType.render(true);","folder":null,"sort":0,"permission":{"default":0,"y5gmtwxmW3A5ZuOP":3},"flags":{}}
{"_id":"xMJc8qLMu8rcTJ8z","name":"Token HP","type":"script","author":"y5gmtwxmW3A5ZuOP","img":"icons/svg/dice-target.svg","scope":"global","command":"/**\n * Roll/Reroll selected token HP\n * Author: Tielc#7191\n */\n\nconst tokens = canvas.tokens.controlled;\nlet choice = 0;\n\nif (tokens.length > 0){\n\ttokens.forEach(rollHP);\n} else {\n\tprintMessage(\"No Tokens were selected\");\n}\n\nasync function rollHP(token, index){\n\tlet actor = token.actor;\n\tlet formula = actor.data.data.attributes.hp.formula;\n\t\t\n\tif (actor.data.type != \"npc\" || !formula) return;\n\t\n\tlet hp = (await new Roll(formula).roll()).total;\n\t\n\tawait actor.update({\"data.attributes.hp.value\": hp, \"data.attributes.hp.max\": hp});\n\t\n\tprintMessage('<h2>' + actor.data.name + '</h2><strong>HP:</strong> ' + actor.data.data.attributes.hp.value + '/' + actor.data.data.attributes.hp.max + '<span style=\"float:right\"><em>(' + token.data._id + ')</em></span>');\n}\n\nfunction printMessage(message){\n\tlet chatData = {\n\t\tuser : game.user._id,\n\t\tcontent : message,\n\t\tblind: true,\n\t\twhisper : game.users.filter(u => u.isGM).map(u => u.id)\n\t};\n\n\tChatMessage.create(chatData,{});\t\n}","folder":null,"sort":0,"permission":{"default":0,"y5gmtwxmW3A5ZuOP":3},"flags":{}}
{"_id":"fEzHEn3tGXXIRHpU","name":"Chartopia Roller","type":"script","author":"y5gmtwxmW3A5ZuOP","img":"icons/svg/dice-target.svg","scope":"global","command":"/**\n * Make a roll from chartopia and output the results in the chat window.\n * If you find yourself using this macro often, please support chartopia on patreon.\n */\n\n// chart id from url. IE 19449 is the chart id in https://chartopia.d12dev.com/chart/19449/\nconst chartId = 61778;\n// only let the gm see the results. false = everyone sees in chat. true = gm whispered results.\nconst gmOnly = false;\n\n\n//////////////////////////////////\n/// Don't edit past this point ///\n//////////////////////////////////\n\nconst requestUrl = `https://chartopia.d12dev.com/api/charts/${chartId}/roll/`;\n\n\nfunction roll(id) {\n let request = new XMLHttpRequest();\n request.open('POST', requestUrl, true);\n\n request.onload = function() {\n if (request.status >= 200 && request.status < 400) {\n // Success!\n let whisper = !!gmOnly ? game.users.map(u => {\n if (u.isGM) return u.id;\n }) : [];\n console.log('whisper', whisper);\n // Create chat content.\n const response = JSON.parse(request.response);\n let resultsList = ``;\n if (Array.isArray(response.results)) {\n response.results.forEach(result => {\n result = result.replace(\"**\", \"<strong>\");\n result = result.replace(\"**\", \"</strong>\");\n resultsList += `<li>${result}</li>`;\n });\n } \n console.log(resultsList);\n \n let chatContent = `<h4><strong>Chart</strong></br> ${response.chart_name}(${response.chart_id})</h4>` +\n `<h4><strong>URL</strong></br> ${response.chart_url}</h4>` +\n `<h4><strong>Results</strong></h4>` +\n `<ul id=\"results-list\">${resultsList}</ul>`;\n let chatData = {\n user: game.userId,\n speaker: ChatMessage.getSpeaker(),\n content: chatContent,\n whisper\n };\n\n ChatMessage.create(chatData, {});\n } else {\n // We reached our target server, but it returned an error\n console.log(\"Server error.\");\n }\n };\n\n request.onerror = function() {\n // There was a connection error of some sort\n console.log(\"Error getting result.\");\n };\n\n request.send();\n} \n\nroll(chartId);","folder":null,"sort":0,"permission":{"default":0,"y5gmtwxmW3A5ZuOP":3},"flags":{}}

0 comments on commit 37c8309

Please sign in to comment.