#Spawn with tag

1 messages · Page 1 of 1 (latest)

cyan crow
#

How can i make a zone that if u are in there u have a tag and if u leave the zone u dont have the tag anymore

strange wren
haughty girder
haughty girder
#

Okay, no problem 👍

cyan crow
#

Its the same for me

haughty girder
#

That's what I asked if you wanted the script that does it for you...

#
import { system, world } from ('@minecraft/server');

// Define the zone (example: coordinates of two opposite corners)
const zone = {
  x1: 100, y1: 60, z1: 100, // first corner
  x2: 200, y2: 80, z2: 200  // second corner
};

// The tag you want to apply
const tag = 'inZone';

system.runInterval(() => {
  for (const player of world.getPlayers()) {
    // Get player position
    const { x, y, z } = player.location;

    // Check if the player is within the defined zone
    const inZone = x >= zone.x1 && x <= zone.x2 &&
      y >= zone.y1 && y <= zone.y2 &&
      z >= zone.z1 && z <= zone.z2;

    if (inZone) {
      // Add the tag if the player is inside the zone
      if (!player.hasTag(tag)) {
        player.addTag(tag);
      }
    } else {
      // Remove the tag if the player is outside the zone
      if (player.hasTag(tag)) {
        player.removeTag(tag);
      }
    }
  }
});```