Jcrafter

Updated Heal Command

Dec 29th, 2013
1,156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 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. // E.g:
  5. // Healing one character named "Dave" (Only Tokens with only a first name can be used. You can still have the full name in the journal.)
  6. // !heal Dave X (Where x is the amount healed. Putting no value for X resets health to max value)
  7. //
  8. // Healing all characters no longer works as perscribed. Working on finding bug.
  9. // !heal all
  10. on("chat:message", function(msg) {
  11. var cmdName = "!heal ";
  12. var msgTxt = msg.content;
  13.  
  14. // heals one token specified by name.
  15. var healCharacter = function(targetName, healNumber) {
  16. sendChat(msg.who, "/em heals " + targetName);
  17. //The above line (which sends the emote to chat) can be disabled with a simple in line comment notation ( // ), like this line.
  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(target.get("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(" ")[2];
  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