Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Use Token GMNotes as Spell Slot and Other Resource

1644465689

Edited 1644465756
I wrote a simple script to use the GMnotes to track spell slots on tokens (rather than character sheets). !TokR <label> // Displays current label and associated value. !TokR <label>+ // Increases value associated with label and displays new value. !TokR <label>- // Decreases value associated with label and displays new value. sample list of labels and values: spell0: 4 spell1: 4 spell2: 2 spell3: 1 potions: 2 Other labels and variables can be used, keeping to the same format (label: value). on("ready",function(){     on("chat:message",function(msg){         if(msg.type=="api" && msg.content.match(/^!tokR/) && playerIsGM(msg.playerid)){             var reg = /^!tokR ([-a-zA-Z0-9 _]*)([+-])$/ig;             var cmd = reg.exec(msg.content);             var selected = msg.selected;             if (selected===undefined){                 sendChat("tokR","Please select a character.");                 return;             }             var tok = getObj("graphic",selected[0]._id);             var gmnote = tok.get("gmnotes");             var decodedText = decodeURIComponent(gmnote);             if (!cmd) {                 reg = /^!tokR ([-a-zA-Z0-9 _]*)$/ig;                 cmd = reg.exec(msg.content);                 var label = cmd[1];                 var regexstr = label + ": [\\d]\+";                 const labelRegex = new RegExp(regexstr,'ig');                 var match = decodedText.match(labelRegex);                 if (!cmd) {                     sendChat("tokR","Please enter !tokR <label>, !tokR <label>+, or !tokR <label>-")                     return;                 } else {                     if (match){                     sendChat("tokR",match[0]);                     return;                     } else {                         sendChat("tokR","No label found!");                         return;                     }                     return;                 }             } else {                 var label = cmd[1];                 var regexstr = label + ": [\\d]\+";                 const labelRegex = new RegExp(regexstr,'ig');                 var match = decodedText.match(labelRegex);                 let value = match[0];                 value = value.split(' ')[1];                 var args=cmd[2];                 if (args == '+') {                     sendChat("tokR", "Value of " + label + ": " + value);                     value++;                     sendChat ("tokR", "Updated to " + value);                     var valuestr = label + ": " + value;                     text = decodedText.replace(labelRegex,valuestr);                     tok.set("gmnotes",text);                     return;                 } else if (args == '-') {                     sendChat("tokR", "Value of " + label + ": " + value);                     value--;                     sendChat ("tokR", "Updated to " + value);                     var valuestr = label + ": " + value;                     text = decodedText.replace(labelRegex,valuestr);                     tok.set("gmnotes",text);                     return;                 } else {                     sendChat("tokR","Please enter !tokR <label>, !tokR <label>+, or !tokR <label>-")                     return;                                      }                                                                }                                                                              }     }); }); Theoretically, this shouldn't interfere with other API scripts that use the GMnotes. It uses .replace() to update the targeted text, though I have not tested this API Script with any other Script. I also have not tested this with a lot of other characters. It has to decode the unicode from the GMnotes, but no problems arise with basic characters or colons.
I'm pretty sure you could award 1 billion dollars to a player if they use an expendable potion during a session and they still wouldn't use them.  
DM Eddie said: I'm pretty sure you could award 1 billion dollars to a player if they use an expendable potion during a session and they still wouldn't use them.   It's made for monsters. The players could make use of it, too; though, you would have to delete the playerIsGM bit. The problem is that monsters on the map generally all use a global character sheet, which means tracking changes to a monster on its character sheet is going to affect the other monsters using that character sheet. This just gives you an additional tool to be able to easily track changes to your monsters on their tokens, which is not shared with other monsters of its type.