So I have this campaign lock script I'm working on for GM's that don't want their players changing characters in between sessions and I can't figure out a way to determine who made a change so I can allow GM's to make changes even while the campaign is locked. Is there a way or not? on("change:attribute", function(obj, prev) {
var CampaignLock = (!state.CampaignLock || state.CampaignLock["status"] == "LOCKED") ? "LOCKED" : "UNLOCKED";
if (CampaignLock == "LOCKED") {
// Prevent any changes to character attributes by non-GM's.
var AttrName = obj.get("name");
var Changed = _.keys(obj.changed)[0];
var NewValue = obj.changed[Changed];
var OldValue = prev[Changed];
//log (AttrName + " (Old): " + OldValue);
//log (AttrName + " (New): " + NewValue);
// Reset these attributes...
var LockedAttributes = ["hp", "cp", "sp", "ep", "gp", "pp", "experience", "strength", "dexterity", "constitution", "intelligence", "wisdom", "charisma"];
if (LockedAttributes.indexOf(AttrName) !== -1) {
setTimeout(function() {
obj.set(Changed, OldValue);
}, 1000);
}
} else {
// Ignore any changes.
}
});
// API COMMAND HANDLER
on("chat:message", function(msg) {
if (msg.type !== "api") return;
if (msg.content.split(" ")[0] === "!lock" && playerIsGM(msg.playerid)) {
state.CampaignLock["status"] = "LOCKED";
sendChat("DM Toolkit", "/w GM Campaign has been locked by " + msg.who + ".")
// log ("Campaign locked.");
}
if (msg.content.split(" ")[0] === "!unlock" && playerIsGM(msg.playerid)) {
state.CampaignLock["status"] = "UNLOCKED";
sendChat("DM Toolkit", "/w GM Campaign has been unlocked by " + msg.who + ".");
// log ("Campaign unlocked.");
}
});