Daniel Vazquez

import { world, system, ItemStack, GameMode } from "@minecraft/server";

// ====================== CONFIGURACIÓN ====================== // Cambia estas coordenadas por las de tu mapa

const CONFIG = { // Posición donde aparece el huevo eggSpawn: { x: 0, y: 65, z: 0 },

// Zona de entrega del equipo ROJO (radio de 3 bloques) redBase: { x: -30, y: 65, z: 0, radius: 3 },

// Zona de entrega del equipo AZUL blueBase: { x: 30, y: 65, z: 0, radius: 3 },

// Ítem que se usa como huevo eggItem: "minecraft:dragon_egg",

// Puntos que se ganan al entregar pointsPerCapture: 1,

// Tiempo en ticks para volver a poner el huevo (20 ticks = 1 segundo) respawnDelay: 60 };

// ====================== VARIABLES ====================== let eggExists = false; let isRespawning = false;

// ====================== FUNCIONES ======================

function getDistance(pos1, pos2) { const dx = pos1.x - pos2.x; const dy = pos1.y - pos2.y; const dz = pos1.z - pos2.z; return Math.sqrt(dx dx + dy dy + dz * dz); }

function playerHasEgg(player) { const inventory = player.getComponent("minecraft:inventory"); if (!inventory || !inventory.container) return false;

for (let i = 0; i < inventory.container.size; i++) { const item = inventory.container.getItem(i); if (item && item.typeId === CONFIG.eggItem) { return true; } } return false; }

function removeEggFromPlayer(player) { const inventory = player.getComponent("minecraft:inventory"); if (!inventory || !inventory.container) return;

for (let i = 0; i < inventory.container.size; i++) { const item = inventory.container.getItem(i); if (item && item.typeId === CONFIG.eggItem) { inventory.container.setItem(i, undefined); break; } } }

function spawnEgg() { const dim = world.getDimension("overworld"); try { // Elimina huevos viejos si existen const items = dim.getEntities({ type: "minecraft:item" }); for (const item of items) { if (item.nameTag === "Huevo" || item.getComponent("minecraft:item")?.itemStack?.typeId === CONFIG.eggItem) { item.remove(); } }

// Coloca el bloque de huevo de dragón dim.setBlockType(CONFIG.eggSpawn, "minecraft:dragon_egg"); eggExists = true; isRespawning = false;

world.sendMessage("§e¡El huevo ha aparecido en el centro!"); } catch (e) { console.warn("Error al spawnear el huevo:", e); } }

function givePoint(player, team) { // Scoreboard let objective = world.scoreboard.getObjective("puntos"); if (!objective) { objective = world.scoreboard.addObjective("puntos", "Puntos"); world.scoreboard.setObjectiveAtDisplaySlot("Sidebar", { objective: objective }); }

const current = objective.getScore(player) ?? 0; objective.setScore(player, current + CONFIG.pointsPerCapture);

// Mensaje const color = team === "rojo" ? "§c" : "§9"; const teamName = team === "rojo" ? "Rojo" : "Azul"; world.sendMessage(\( {color}¡ \){player.name} ha robado el huevo para el Equipo ${teamName}!);

// Quitar huevo y programar respawn removeEggFromPlayer(player); eggExists = false;

if (!isRespawning) { isRespawning = true; system.runTimeout(() => { spawnEgg(); }, CONFIG.respawnDelay); } }

// ====================== DETECCIÓN PRINCIPAL ======================

system.runInterval(() => { const players = world.getAllPlayers();

for (const player of players) { if (!playerHasEgg(player)) continue;

const pos = player.location;

// Equipo Rojo if (player.hasTag("rojo")) { const dist = getDistance(pos, CONFIG.redBase); if (dist <= CONFIG.redBase.radius) { givePoint(player, "rojo"); } }

// Equipo Azul if (player.hasTag("azul")) { const dist = getDistance(pos, CONFIG.blueBase); if (dist <= CONFIG.blueBase.radius) { givePoint(player, "azul"); } } } }, 10); // Revisa cada 0.5 segundos

// ====================== COMANDOS ÚTILES ======================

world.beforeEvents.chatSend.subscribe((event) => { const msg = event.message.toLowerCase(); const player = event.sender;

// Unirse a equipos if (msg === "!rojo") { event.cancel = true; player.removeTag("azul"); player.addTag("rojo"); player.sendMessage("§cTe uniste al Equipo Rojo"); }

if (msg === "!azul") { event.cancel = true; player.removeTag("rojo"); player.addTag("azul"); player.sendMessage("§9Te uniste al Equipo Azul"); }

// Reiniciar huevo (solo operadores) if (msg === "!resethuevo" && player.isOp()) { event.cancel = true; spawnEgg(); }

// Ver puntuación if (msg === "!puntos") { event.cancel = true; const objective = world.scoreboard.getObjective("puntos"); if (objective) { const score = objective.getScore(player) ?? 0; player.sendMessage(§eTus puntos: §f${score}); } } });

// ====================== INICIO ======================

world.afterEvents.worldInitialize.subscribe(() => { // Crear scoreboard al cargar el mundo if (!world.scoreboard.getObjective("puntos")) { const obj = world.scoreboard.addObjective("puntos", "Puntos"); world.scoreboard.setObjectiveAtDisplaySlot("Sidebar", { objective: obj }); }

// Spawnear el huevo al inicio system.runTimeout(() => { spawnEgg(); }, 40); }); Minecraft bedrock

Kodari AI
KodariOct 27 at 5:10 am 1
EggStealBedrock
A capture-the-flag style Minecraft Bedrock plugin where players on Red or Blue teams compete to steal a dragon egg from the center map and deliver it to their team's base. Players join teams via chat commands (!rojo/!azul), earn points on successful captures, and track scores through a sidebar scoreboard. The egg respawns automatically after each delivery with configurable delay, includes operator commands for resetting the egg, and displays real-time capture announcements in chat. Spawn points, base locations, and point values are all configurable through a centralized config object at the top of the file.

Created a Bedrock behavior pack with manifest.json and scripts/main.js. It sets up the teams, scoreboard, egg respawn, delivery scoring, and chat commands. Adjust the spawn and base coordinates at the top of scripts/main.js, then activate the behavior pack in your world.

Kodari can make mistakes. Review important code before using.
Files
scripts
manifest.json
Code
2 157
scripts/main.js
import { DisplaySlotId, world, system } from "@minecraft/server";

const CONFIG = {
  eggSpawn: { x: 0, y: 65, z: 0 },
  redBase: { x: -30, y: 65, z: 0, radius: 3 },
  blueBase: { x: 30, y: 65, z: 0, radius: 3 },
  eggItem: "minecraft:dragon_egg",
  pointsPerCapture: 1,
  respawnDelay: 60
};

let eggExists = false;
let isRespawning = false;

function getObjective() {
  let objective = world.scoreboard.getObjective("puntos");
  if (!objective) {
    objective = world.scoreboard.addObjective("puntos", "Puntos");
  }
  world.scoreboard.setObjectiveAtDisplaySlot(DisplaySlotId.Sidebar, { objective });
  return objective;
}

function getDistance(position, target) {
  const dx = position.x - target.x;
  const dy = position.y - target.y;
  const dz = position.z - target.z;
  return Math.sqrt(dx * dx + dy * dy + dz * dz);
}

function findEggSlot(player) {
  const inventory = player.getComponent("minecraft:inventory");
  const container = inventory?.container;
  if (!container) return -1;

  for (let slot = 0; slot < container.size; slot++) {
    if (container.getItem(slot)?.typeId === CONFIG.eggItem) return slot;
  }
  return -1;
}

function spawnEgg() {
  try {
    world.getDimension("overworld").setBlockType(CONFIG.eggSpawn, CONFIG.eggItem);
    eggExists = true;
    isRespawning = false;
    world.sendMessage("§e¡El huevo ha aparecido en el centro!");
  } catch (error) {
    isRespawning = false;
    console.warn(`No se pudo colocar el huevo: ${error}`);
  }
}

function givePoint(player, team, slot) {
  if (!eggExists) return;

  const objective = getObjective();
  const identity = player.scoreboardIdentity;
  const inventory = player.getComponent("minecraft:inventory")?.container;
  if (!identity || !inventory) return;

  const currentScore = objective.getScore(identity) ?? 0;
  objective.setScore(identity, currentScore + CONFIG.pointsPerCapture);
  inventory.setItem(slot, undefined);
  eggExists = false;

  const color = team === "rojo" ? "§c" : "§9";
  const teamName = team === "rojo" ? "Rojo" : "Azul";
  world.sendMessage(`${color}¡${player.name} ha entregado el huevo para el Equipo ${teamName}!`);

  if (!isRespawning) {
    isRespawning = true;
    system.runTimeout(spawnEgg, CONFIG.respawnDelay);
  }
}

system.runInterval(() => {
  if (!eggExists) return;

  for (const player of world.getAllPlayers()) {
    const slot = findEggSlot(player);
    if (slot < 0) continue;

    if (player.hasTag("rojo") && getDistance(player.location, CONFIG.redBase) <= CONFIG.redBase.radius) {
      givePoint(player, "rojo", slot);
    } else if (player.hasTag("azul") && getDistance(player.location, CONFIG.blueBase) <= CONFIG.blueBase.radius) {
      givePoint(player, "azul", slot);
    }

    if (!eggExists) break;
  }
}, 10);

world.beforeEvents.chatSend.subscribe((event) => {
  const message = event.message.trim().toLowerCase();
  const player = event.sender;

  if (message === "!rojo") {
    event.cancel = true;
    player.removeTag("azul");
    player.addTag("rojo");
    player.sendMessage("§cTe uniste al Equipo Rojo");
  } else if (message === "!azul") {
    event.cancel = true;
    player.removeTag("rojo");
    player.addTag("azul");
    player.sendMessage("§9Te uniste al Equipo Azul");
  } else if (message === "!resethuevo") {
    event.cancel = true;
    if (player.isOp()) {
      spawnEgg();
    } else {
      player.sendMessage("§cSolo un operador puede reiniciar el huevo.");
    }
  } else if (message === "!puntos") {
    event.cancel = true;
    const objective = world.scoreboard.getObjective("puntos");
    const identity = player.scoreboardIdentity;
    const score = objective && identity ? objective.getScore(identity) ?? 0 : 0;
    player.sendMessage(`§eTus puntos: §f${score}`);
  }
});

system.runTimeout(() => {
  getObjective();
  spawnEgg();
}, 40);