Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- on('ready', () => {
- // Command to setup or deplete Mirror Image on a selected token
- on('chat:message', function(msg) {
- if (msg.type === 'api' && msg.content.startsWith('!mirrorImage')) {
- const args = msg.content.split(' ');
- const mirrorCount = parseInt(args[1], 10) || 3; // Default to 3 duplicates if none specified
- const selected = msg.selected;
- if (!selected || selected.length === 0) {
- sendChat("", "/w gm Please select a token to apply or deplete Mirror Image.");
- return;
- }
- selected.forEach(obj => {
- const token = getObj("graphic", obj._id);
- if (token) {
- // Check if Mirror Image is already active (blue marker set)
- if (token.get("status_blue")) {
- // Mirror Image is active, so we deplete a duplicate
- let currentCount = parseInt(token.get("bar3_value"), 10);
- if (currentCount > 0) {
- currentCount -= 1; // Reduce the duplicate count by 1
- token.set("bar3_value", currentCount); // Update the count in bar3
- if (currentCount > 0) {
- sendChat("", `/em A mirror image of ${token.get("name") || "the creature"} shatters! ${currentCount} duplicates remain.`);
- } else {
- token.set("status_blue", false); // Remove blue marker if no duplicates remain
- sendChat("", `/em All of ${token.get("name") || "the creature"}'s mirror images have been destroyed.`);
- }
- } else {
- sendChat("", `/w gm ${token.get("name") || "The creature"} has no remaining mirror images.`);
- }
- } else {
- // Mirror Image is not active, so we set it up
- token.set("bar3_value", mirrorCount); // Set the initial count in bar3
- token.set("status_blue", true); // Apply the blue marker for Mirror Image
- sendChat("", `/em ${token.get("name") || "The creature"} shimmers as ${mirrorCount} mirror images appear around it!*`);
- }
- }
- });
- }
- });
- // Detect manual removal of the blue status marker and send deactivation message
- on('change:graphic:status_blue', function(obj) {
- const token = getObj("graphic", obj.id);
- if (token && !token.get("status_blue") && parseInt(token.get("bar3_value"), 10) > 0) {
- sendChat("", `/em ${token.get("name") || "The creature"}'s mirror images dissipate.*`);
- token.set("bar3_value", 0); // Clear the count in bar3 when marker is manually removed
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement