Advertisement
Guest User

MirrorImage

a guest
Oct 28th, 2024
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. on('ready', () => {
  2. // Command to setup or deplete Mirror Image on a selected token
  3. on('chat:message', function(msg) {
  4. if (msg.type === 'api' && msg.content.startsWith('!mirrorImage')) {
  5. const args = msg.content.split(' ');
  6. const mirrorCount = parseInt(args[1], 10) || 3; // Default to 3 duplicates if none specified
  7. const selected = msg.selected;
  8.  
  9. if (!selected || selected.length === 0) {
  10. sendChat("", "/w gm Please select a token to apply or deplete Mirror Image.");
  11. return;
  12. }
  13.  
  14. selected.forEach(obj => {
  15. const token = getObj("graphic", obj._id);
  16.  
  17. if (token) {
  18. // Check if Mirror Image is already active (blue marker set)
  19. if (token.get("status_blue")) {
  20. // Mirror Image is active, so we deplete a duplicate
  21. let currentCount = parseInt(token.get("bar3_value"), 10);
  22.  
  23. if (currentCount > 0) {
  24. currentCount -= 1; // Reduce the duplicate count by 1
  25. token.set("bar3_value", currentCount); // Update the count in bar3
  26.  
  27. if (currentCount > 0) {
  28. sendChat("", `/em A mirror image of ${token.get("name") || "the creature"} shatters! ${currentCount} duplicates remain.`);
  29. } else {
  30. token.set("status_blue", false); // Remove blue marker if no duplicates remain
  31. sendChat("", `/em All of ${token.get("name") || "the creature"}'s mirror images have been destroyed.`);
  32. }
  33. } else {
  34. sendChat("", `/w gm ${token.get("name") || "The creature"} has no remaining mirror images.`);
  35. }
  36. } else {
  37. // Mirror Image is not active, so we set it up
  38. token.set("bar3_value", mirrorCount); // Set the initial count in bar3
  39. token.set("status_blue", true); // Apply the blue marker for Mirror Image
  40. sendChat("", `/em ${token.get("name") || "The creature"} shimmers as ${mirrorCount} mirror images appear around it!*`);
  41. }
  42. }
  43. });
  44. }
  45. });
  46.  
  47. // Detect manual removal of the blue status marker and send deactivation message
  48. on('change:graphic:status_blue', function(obj) {
  49. const token = getObj("graphic", obj.id);
  50. if (token && !token.get("status_blue") && parseInt(token.get("bar3_value"), 10) > 0) {
  51. sendChat("", `/em ${token.get("name") || "The creature"}'s mirror images dissipate.*`);
  52. token.set("bar3_value", 0); // Clear the count in bar3 when marker is manually removed
  53. }
  54. });
  55. });
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement