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

[Query] Any way to get who made a change to a character sheet?

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.");     } });
Now obviously I could just remove ControlledBy from all the characters and store that information. Would probably be a lot easier, but some players may want to work on their macros or something... which this script would let them do.
1488888449
The Aaron
Pro
API Scripter
What you're running up against is exactly what I hit with TokenLock.  There isn't a way to know who performed the action.  The best you can do is disallow action on a character (and related) that has a controlled by.   However, since you're looking at non-game times, you could have it check who is logged in (player.get('online') ) and only block characters from being changed when one of the controlledby players is logged in (and not a gm).
1488893843
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Other problem you're going to have is the API timeout when no one is logged in.
1488894092
The Aaron
Pro
API Scripter
That **should** be fixed to where it starts up when someone joins the game. You know, it might be far easier to write a command that removes the controlled by on everything and another the restores it.  That would prevent any "between game" messing about.
1488906209
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
huh, so it is. Could of sworn it still wasn't booting up for just a player account.
The Aaron said: That **should** be fixed to where it starts up when someone joins the game. You know, it might be far easier to write a command that removes the controlled by on everything and another the restores it.  That would prevent any "between game" messing about. Yeah. I had considered that... and totally forgot about the API not always spinning up and also crashing when a DM isn't around. Bleh. 
1488916911
The Aaron
Pro
API Scripter
I really think the spin up/crash isn't a problem any more.
The Aaron said: I really think the spin up/crash isn't a problem any more. I meant some player crashing the API...
1488919658
The Aaron
Pro
API Scripter
Yeah, that could be a problem.  Makes the idea of saving/restoring control of characters even more appealing as the API only needs to run when the change occurs.
1488963798
Ziechael
Forum Champion
Sheet Author
API Scripter
^^ OR when they are working on macros (which I'm assuming would mean Powercards for SC's players ;) )