I have not run into this problem myself, but I want to try something out if you'll let me. I have this add-on to the companion script that will decrement the number of spell slots remaining rather than count up to the limit of spells per day. Would you add this as an additional script (after the companion script has been added to the game), and see if your spell slots and longrest work as expected (minus the change of decrementing the number of spells left instead of increasing the number of spells expended). Here is the script. var resolveslot = function(msg,character,player,spellslot) {
log("Overwrote resolveslot");
var charslot = findObjs({type: 'attribute', characterid: character.id, name: "lvl" + spellslot + "_slots_expended"}, {caseInsensitive: true})[0];
if(!charslot) {
charslot = createObj("attribute", {name: "lvl" + spellslot + "_slots_expended", current: "0", max: "", characterid: character.id});
//var charslot = findObjs({type: 'attribute', characterid: character.id, name: "lvl" + spellslot + "_slots_expended"}, {caseInsensitive: true})[0];
}
var charslotmax = findObjs({type: 'attribute', characterid: character.id, name: "lvl" + spellslot + "_slots_total"}, {caseInsensitive: true})[0];
if(!charslotmax) {
charslotmax = createObj("attribute", {name: "lvl" + spellslot + "_slots_total", current: "0", max: "", characterid: character.id});
//var charslotmax = findObjs({type: 'attribute', characterid: character.id, name: "lvl" + spellslot + "_slots_total"}, {caseInsensitive: true})[0];
}
var max = charslotmax.get("current");
var remain = parseInt(charslot.get("current"), 10) - 1;
charslot.set({current:remain});
var output = "SPELL SLOT LEVEL " + spellslot + ":\n" + (remain >= 0 ? remain + " LEFT" : "<span style='color:red'>ALL SLOTS EXPENDED</span>");
var formattedOutput = (getAttrByName(character.id, "wtype") === "" ? "" : "/w gm ") + "&{template:desc} {{desc=" + output + "}}";
if(state.FifthEditionOGLbyRoll20.spelltracking != "quiet") {
sendChat(msg.who, formattedOutput);
}
}
var longrest = function(msg) {
log("Overwrote longrest");
charname = msg.content.substring(msg.content.indexOf(" ") + 1);
var character = findObjs({name: charname, type: "character"}, {caseInsensitive: true})[0];
if(!character) {
log("NO CHARACTER BY THAT NAME FOUND");
}
else {
var spellslots = filterObjs(function(obj) {
if(obj.get("type") && obj.get("type") === "attribute" && obj.get("name") && obj.get("name").indexOf("expended") > -1) {
return true;
}
else {
return false;
}
});
_.each(spellslots, function(obj) {
var spellSlotMaxName = obj.get("name").replace("expended", "total");
var charslotmax = findObjs({type: 'attribute', characterid: character.id, name: obj.get("name").replace("expended", "total")}, {caseInsensitive: true})[0];
obj.set({current: charslotmax ? charslotmax.get("current") : 0});
});
var maxhp = getAttrByName(character.id, "hp", "max");
var hp = findObjs({type: 'attribute', characterid: character.id, name: "hp"}, {caseInsensitive: true})[0];
if(hp && maxhp) {
hp.set({current: maxhp});
}
}
}