Grebog

Hex

Jul 29th, 2021 (edited)
264
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Hex Macro by Grebog
  2. // version alpha 0.0.2
  3.  
  4. // user notes
  5. // this macro is inteded for use by the caster of the hex spell in D&D 5e on Forge VTT
  6. // it will then create an effect to add in hex damage
  7.  
  8. //user modifiable declarations CHANGE AT YOUR OWN RISK
  9. const hexIconPath = 'icons/svg/sun.svg';
  10. let hexMsg = ' has hexed their enemy!';
  11. let endhexMsg = ' is no longer hexed';
  12.  
  13. //fixed declarations DO NOT MODIFY
  14. let macroActor = token.actor;
  15. let chatMsg = '';
  16. let hexd = macroActor.effects.find(i => i.data.label === "hexed")
  17. let hex = {
  18.     changes: [
  19.         {
  20.             key: "data.bonuses.rsak.damage",
  21.             mode: 2,
  22.             priority: 20,
  23.             value: "+1d6",
  24.         },
  25.         {
  26.             key: "data.bonuses.msak.damage",
  27.             mode: 2,
  28.             priority: 20,
  29.             value: "+1d6",
  30.         },
  31.     ],
  32.     duration: {
  33.         "seconds": 60,
  34.     },
  35.     icon: hexIconPath,
  36.     label: "hexed",
  37.     tint: "#9b34eb"
  38. }
  39. //identify token
  40. if (macroActor === undefined || macroActor === null) {
  41.   ui.notifications.warn("Please select a token first.");
  42. }
  43. else {
  44. // If already hex  
  45. if (hexd) {
  46.     macroActor.deleteEmbeddedEntity("ActiveEffect", hexd.id)
  47. // anounce to chat
  48.     chatMsg = `${macroActor.name} ${endhexMsg}`;
  49. }
  50. // if not already hex  
  51. else {
  52.     macroActor.createEmbeddedEntity("ActiveEffect", hex)   
  53. // anounce to chat
  54.         chatMsg = `${macroActor.name} ${hexMsg}`;
  55. }
  56. // write to chat if needed:
  57. if (chatMsg !== '') {
  58.     let chatData = {
  59.         user: game.user._id,
  60.         speaker: ChatMessage.getSpeaker(),
  61.         content: chatMsg
  62.     };
  63.     ChatMessage.create(chatData, {});
  64. }
  65. }
RAW Paste Data