Jcrafter

Untitled

Dec 29th, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. // This is a "heal" chat command for the roll20 virtual tabletop API.
  2. // It can be used to heal all 3 bars for a token by name,
  3. // or you can have it heal the tokens for all the characters in your campaign's journal.
  4. //
  5. // E.g:
  6. // Healing one character named "Dave the Dwarf":
  7. // !heal Dave the Dwarf
  8. //
  9. // Healing all characters
  10. // !heal all
  11. on("chat:message", function(msg) {
  12. var cmdName = "!heal ";
  13. var msgTxt = msg.content;
  14.  
  15. // heals one token specified by name.
  16. var healCharacter = function(targetName, healNumber) {
  17. // sendChat(msg.who, "/em heals " + targetName);
  18.  
  19. var targetsMatched = findObjs({_type: "graphic", name: targetName});
  20. if(targetsMatched.length === 0) {
  21. sendChat(msg.who, "target " + targetName + " not found.");
  22. }
  23.  
  24. // heal the character token on all pages.
  25. for(var x in targetsMatched) {
  26. var target = targetsMatched[x];
  27.  
  28. /* if(target.get("bar1_value") !== "") {
  29. target.set("bar1_value", target.get("bar1_max"));
  30. }
  31.  
  32. //if(target.get("bar2_value") !== "") {
  33. target.set("bar2_value", target.get("bar2_max"));
  34. } */
  35.  
  36.  
  37. if(target.get("bar3_value") !== "") {
  38. if(healNumber == undefined) {
  39. target.set("bar3_value", target.get("bar3_max"));
  40. } else {
  41. target.set("bar3_value", Number(healNumber));
  42. }
  43. }
  44.  
  45. target.set({
  46. status_greenmarker: false,
  47. status_bluemarker: false,
  48. status_redmarker: false,
  49. status_dead: false
  50. });
  51. }
  52. };
  53.  
  54.  
  55. // Check for our heal command in the chat message.
  56. if(msg.type == "api" && msgTxt.indexOf(cmdName) !== -1) {
  57. var targetName = msgTxt.split(" ")[1];
  58. var healNumber = msgTxt.split(" ")[1];
  59.  
  60. // heal only one character
  61. if(targetName !== "all") {
  62. healCharacter(targetName, healNumber);
  63. }
  64.  
  65. // heal all characters
  66. else {
  67. var allCharacters = findObjs({_type: "character"});
  68. for(var x in allCharacters) {
  69. var character = allCharacters[x];
  70. healCharacter(character.get("name"), healNumber);
  71. }
  72. }
  73. }
  74. });
Advertisement
Add Comment
Please, Sign In to add comment