Guest User

Untitled

a guest
Feb 18th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.41 KB | None | 0 0
  1. // author: gui8312
  2. // version: 1.1
  3.  
  4. // install instructions
  5. // 1. add API to library - this means create a New Script, paste all this code, save script
  6. // 2. open the campaign - launch the game on roll20
  7. // 3. Send into chat the following text: !get_every_id_sheet_tracker
  8. // 4. note down the IDs of all the GMs. Not of all the players, only of the GMs. This includes the ID of the creator.
  9. // 5. add the ID of the GMs to settings (underneath functionality instructions).
  10. // 5b. remember, updating the IDs in the settings is a step to repeat if you ever change who the GMs are.
  11. // 6. done!
  12.  
  13. // functionality instructions
  14. // the goal of this API is to track changes to the character sheets. this allows to correct mistakes, or even detect attempts at cheating.
  15. // it will detect any changes in any character sheet, as long as the value changed is listed under "attributes and abilities".
  16. // it will send messages that make it clear what sheet was changed and what was changed in the sheet.
  17. // if you have up to 4 GMs (and however many players) this script will work.
  18. // this script has two modes of operation, it switches between them automatically.
  19. // mode 1: if one of the GMs is online it will switch to "game session mode". the messages sent about sheet changes will be hidden from players and will be short and concise to avoid spamming the chat too much for the GM. they will have a yellow background.
  20. // mode 2: if no GM is online it will switch to "in-between sessions mode". the messages will be visible to everyone, all the players and GMs. they will explain that a change was detected and ask to undo them. it will also inform that the GM can look at these changes later. these messages will be orange.
  21. // note on mode 2: has a player made changes when you were offline? you can check that by launching cour game and at the top of the chat clicking "View all chat entries for this game »". you can use ctrl+f to find the word "golly", it automatically finds the messages that concern this situation.
  22. // note on mode 2: you should clean the chat archive once in a while for longer campaigns (can be erased on game page under settings, right above the option to erase game. PLEASE CONFIRM THAT YOU HAVE NOT MISSCLICKED when the confirmation box appears - erasing your game by a distraction would be horrible). you can save the chat log before erasing it, by opening the chat log and copying all its content.
  23. // the idea is to allow for a smoother experience when in a session, while also helping players who change something in between session to know that this was tracked and how to undo this.
  24. // to test it: follow install instructions and after that open a character sheet. try changing anything, for example, add one xp Point. the script will detect it and send you a message. this message will be a whisper to GM, because you (the creator) are a GM and the API will be in "game session mode".
  25. // troubleshoothing: if testing works as decribed above, everything should be set up right. if you get the message from the "in-between sessions mode" (if they are orange) you need to add the ID of the GM and of any co-GMs to the setting correctly.
  26.  
  27. // formatting info
  28. // here are the default messages that will be output:
  29. // mode 1 - "/w gm :::: char name - [character name] :::: attribute changed - [attribute name] :::: original value (current/max) - [old value current]/[old value max] :::: changed value (current/max) - [new value current]/[new value max] ::::"
  30. // mode 2 - "/em Golly! the GM is not here and it seems like you changed something with your character. \n /em Please change it back to avoid gameplay problems (change information follows below). \n /em No worries, worst case scenario all changes are logged and the GM can fix it for you if needed. \n /em Char name - [character name] \n /em Attribute changed - [attribute name] \n /em Original value (current/max) - [old value current]/[old value max] \n /em Changed value (current/max) - [new value current]/[new value max]"
  31.  
  32.  
  33. on("change:attribute", function(obj, prev) {
  34.  
  35. //settings: add the IDs of GMs here! even if your game has less than 4 GMs, do not erase any line in the settings. just leave the IDs blank if not needed.
  36.  
  37. var GM1_ID = "-KsZ2gc2WYA7GaZzsqLN";
  38. var GM2_ID = "-L4ByxaM5xxOJ4xrRBCb";
  39. var GM3_ID = "";
  40. var GM4_ID = "";
  41.  
  42.  
  43.  
  44. // sees if code would create erroes that crash the API sandbox
  45. try {
  46.  
  47. // code explained: get info about character that just changed, including the name of said character
  48. var char_ID = obj.get("_characterid");
  49. var Character = findObjs({_type: "character", _id: char_ID})[0];
  50. var Character_Name = Character.get("name");
  51. var Attribute_Name = obj.get("name");
  52. var Old_Value = prev["current"];
  53. var Old_Value_Max = prev["max"];
  54. var New_Value = obj.get("current");
  55. var New_Value_Max = obj.get("max");
  56.  
  57. }
  58.  
  59. catch (err) {
  60. sendChat("SheetChange","/w GM Something went wrong. " );
  61. sendChat("SheetChange","/w GM " + err.name + "; " + err.message);
  62. return; // to ensure the rest of the code doesnt run when there's an error.
  63. }
  64.  
  65. // optional: if you want no notification for lets say current HP being changed:
  66. // if(obj.get("name") == "HP" && obj.get("max") == prev["max"] ) return;
  67.  
  68. // code explained: get info about GMs, if they are online or not.
  69. var GM1 = findObjs({_type: "player", _id: GM1_ID })[0];
  70. var GM2 = findObjs({_type: "player", _id: GM2_ID })[0];
  71. var GM3 = findObjs({_type: "player", _id: GM3_ID })[0];
  72. var GM4 = findObjs({_type: "player", _id: GM4_ID })[0];
  73.  
  74. var GM1_online = ""
  75. if(GM1 != undefined) GM1_online = GM1.get("_online");
  76. var GM2_online = ""
  77. if(GM2 != undefined) GM2_online = GM2.get("_online");
  78. var GM3_online = ""
  79. if(GM3 != undefined) GM3_online = GM3.get("_online");
  80. var GM4_online = ""
  81. if(GM4 != undefined) GM4_online = GM4.get("_online");
  82.  
  83. //code explained: diagnostic tools
  84. //log(GM1);
  85. //log(GM1_online);
  86.  
  87.  
  88. // just for reference
  89. /*
  90. var Character_Name = Character.get("name");
  91. var Attribute_Name = obj.get("name");
  92. var Old_Value = prev["current"];
  93. var Old_Value_Max = prev["max"];
  94. var New_Value = obj.get("current");
  95. var New_Value_Max = obj.get("max");
  96. */
  97.  
  98. // code explained: "game session mode"; the tracker works hidden during the sessions, players should not be spammed with these message during the session.
  99. if(GM1_online == true || GM2_online == true || GM3_online == true || GM4_online == true){
  100. sendChat("GM","/w gm :::: char name - " + Character_Name + " :::: attribute changed - " + Attribute_Name + " :::: original value (current/max) - " + Old_Value + "/" + Old_Value_Max + " :::: changed value (current/max) - " + New_Value + "/" + New_Value_Max + " ::::" );
  101. }
  102.  
  103. // code explained: "in-between sessions mode"; the script works more visibly: a message makes it clear to players that stats are being tracked and that something changed.
  104. // code explained: the GM can ctrl+f search for golly on the chat archive to see if anything was changed when he was away.
  105. else{
  106. sendChat("","/em Golly! the GM is not here and it seems like you changed something with your character.");
  107. sendChat("","/em Please change it back to avoid gameplay problems (change information follows below).");
  108. sendChat("","/em No worries, worst case scenario all changes are logged and the GM can fix it for you if needed.");
  109. sendChat("","/em Char name - " + Character_Name );
  110. sendChat("","/em Attribute changed - " + Attribute_Name );
  111. sendChat("","/em Original value (current/max) - " + Old_Value + "/" + Old_Value_Max );
  112. sendChat("","/em Changed value (current/max) - " + New_Value + "/" + New_Value_Max );
  113. }
  114.  
  115. });
  116.  
  117. // code explained: this section allows for the !get_every_id_sheet_tracker command to work.
  118. on('ready',function(){
  119. "use strict";
  120. on('chat:message',function(msg){
  121. if('api' == msg.type && '!get_every_id_sheet_tracker' == msg.content){
  122. var every_id = findObjs({_type: "player"});
  123. //log(every_id);
  124. _.each(every_id, function(obj) {
  125. sendChat("ID Finder","The player named " + obj.get("_displayname") + " has the following player ID: \n " + obj.get("_id") + "\n _______________________________________ \n");
  126. });
  127. }
  128. });
  129. });
Add Comment
Please, Sign In to add comment