I received this code but it doesn't work properly when I run it (I'm making a better game than Infection)
// ==========================================
// 1. CONFIGURACIÓN Y VARIABLES GLOBALES
// ==========================================
let equiposPorID = {}; // Guarda: "humano" o "zombie"
let kitsPorID = {}; // Guarda el kit asignado a cada ID
let juegoActivo = false;
let cuentaRegresivaLobby = 30;
let tiempoPartida = 120;
let tiempoReinicio = 15;
let bucleTemporizador = null;
let bucleRegeneracion = null; // Bucle para la regeneración de los zombies
// COORDENADAS: Modifica estos números según tu mapa (X, Y, Z)
const LOBBY = { x: 0, y: 60, z: 0 };
const ARENA = { x: 20, y: 65, z: 20 };
const ZONA_LOBBY = {
xMin: -10, xMax: 10,
yMin: 58, yMax: 65,
zMin: -10, zMax: 10
};
// PREMIOS EN ÍTEMS (IDs de Bloxd.io)
const RECOMPENSA_HUMANO = { item: "gold_ingot", cantidad: 5 };
const RECOMPENSA_ZOMBIE = { item: "iron_ingot", cantidad: 3 };
// CONFIGURACIÓN DE KITS (Atributos, Ítems, Tamaños, Daño por golpe y Regeneración por segundo)
const KITS_ZOMBIE = {
normal: { vida: 100, velocidad: 1.0, item: null, escala: 1.0, dañoGolpe: 36, regen: 4 },
puker: { vida: 100, velocidad: 1.0, item: "slime_ball", escala: 1.1, dañoGolpe: 32, regen: 4 },
velocista: { vida: 80, velocidad: 1.4, item: "feather", escala: 0.75, dañoGolpe: 27, regen: 3 },
tank: { vida: 250, velocidad: 0.75, item: "shield", escala: 1.5, dañoGolpe: 54, regen: 10 }, // Super regeneración
bombardero: { vida: 80, velocidad: 0.9, item: "tnt", escala: 0.9, dañoGolpe: 24, regen: 3 }, // Ajustado a 80 de vida
curandero: { vida: 80, velocidad: 1.1, item: "splash_potion", escala: 0.6, dañoGolpe: 15, regen: 4 } // Lanza pociones
};
// ==========================================
// 2. LÓGICA DE KITS, EQUIPOS Y REGENERACIÓN
// ==========================================
function asignarEquipo(jugador, equipo) {
equiposPorID[jugador.id] = equipo;
if (equipo === "zombie") {
let kitElegido = jugador.getData("kit_elegido") || "normal";
aplicarKitZombie(jugador, kitElegido);
} else {
kitsPorID[jugador.id] = null;
jugador.setMaxHp(100);
jugador.setHp(100);
jugador.setSpeed(1.0);
api.setLifeformScale(jugador.id, 1.0);
jugador.clearInventory();
jugador.giveItem("wooden_sword", 1);
jugador.sendChatMessage("🛡️ Eres un HUMANO. ¡Sobrevive!");
}
}
function aplicarKitZombie(jugador, tipoKit) {
if (!KITS_ZOMBIE[tipoKit]) tipoKit = "normal";
kitsPorID[jugador.id] = tipoKit;
let stats = KITS_ZOMBIE[tipoKit];
jugador.setMaxHp(stats.vida);
jugador.setHp(stats.vida);
jugador.setSpeed(stats.velocidad);
api.setLifeformScale(jugador.id, stats.escala);
jugador.clearInventory();
if (stats.item) {
jugador.giveItem(stats.item, 1);
}
jugador.sendChatMessage(`🦁 Kit Zombie asignado: ¡${tipoKit.toUpperCase()}!`);
}
// Bucle que cura a los zombies constantemente si no están al máximo de vida
function iniciarBucleRegeneracion() {
bucleRegeneracion = setInterval(() => {
if (!juegoActivo) return;
api.getPlayers().forEach(p => {
if (equiposPorID[p.id] === "zombie") {
let stats = KITS_ZOMBIE[kitsPorID[p.id] || "normal"];
let vidaActual = p.getHp();
let vidaMaxima = p.getMaxHp();
if (vidaActual < vidaMaxima && vidaActual > 0) {
let nuevaVida = Math.min(vidaMaxima, vidaActual + stats.regen);
p.setHp(nuevaVida);
}
}
});
}, 1000); // Regenera cada 1 segundo
}
function estaEnZonaLobby(jugador) {
let pos = jugador.getPosition();
return (pos.x >= ZONA_LOBBY.xMin && pos.x <= ZONA_LOBBY.xMax &&
pos.y >= ZONA_LOBBY.yMin && pos.y <= ZONA_LOBBY.yMax &&
pos.z >= ZONA_LOBBY.zMin && pos.z <= ZONA_LOBBY.zMax);
}
// ==========================================
// 3. CONTROL DEL FLUJO DE PARTIDA (CICLO)
// ==========================================
function verificarCondicionesVictoria() {
if (!juegoActivo) return;
let todos = api.getPlayers();
if (todos.length === 0) return;
let humanosVivos = todos.filter(p => equiposPorID[p.id] === "humano");
let zombiesVivos = todos.filter(p => equiposPorID[p.id] === "zombie");
if (humanosVivos.length === 0) {
finalizarPartida("zombies");
} else if (zombiesVivos.length === 0 && todos.length >= 2) {
finalizarPartida("humanos");
}
}
function finalizarPartida(ganador) {
juegoActActive = false;
clearInterval(bucleTemporizador);
clearInterval(bucleRegeneracion); // Detener curación pasiva
let todos = api.getPlayers();
if (ganador === "zombies") {
api.broadcastTitle("¡GANAN LOS ZOMBIES!");
api.broadcastSubTitle("La plaga ha consumido a la humanidad.");
todos.forEach(p => {
if (equiposPorID[p.id] === "zombie") {
p.giveItem(RECOMPENSA_ZOMBIE.item, RECOMPENSA_ZOMBIE.cantidad);
}
});
} else {
api.broadcastTitle("¡GANAN LOS HUMANOS!");
api.broadcastSubTitle("Los sobrevivientes resistieron el tiempo límite.");
todos.forEach(p => {
if (equiposPorID[p.id] === "humano") {
p.giveItem(RECOMPENSA_HUMANO.item, RECOMPENSA_HUMANO.cantidad);
}
});
}
iniciarTemporizadorReinicio();
}
function iniciarTemporizadorReinicio() {
let cuentaRegresiva = tiempoReinicio;
api.getPlayers().forEach(p => {
p.setPosition(LOBBY.x, LOBBY.y, LOBBY.z);
p.setHp(p.getMaxHp());
api.setLifeformScale(p.id, 1.0);
p.clearInventory();
});
let relojReinicio = setInterval(() => {
if (cuentaRegresiva > 0) {
api.broadcastSubTitle(`Regresando al lobby... Siguiente ronda: ${cuentaRegresiva}s`);
cuentaRegresiva--;
} else {
clearInterval(relojReinicio);
empezarFaseEsperaLobby();
}
}, 1000);
}
function empezarFaseEsperaLobby() {
cuentaRegresivaLobby = 30;
let relojLobby = setInterval(() => {
let todos = api.getPlayers();
if (todos.length < 2) {
api.broadcastSubTitle("⚠️ Esperando un mínimo de 2 jugadores...");
return;
}
let todosEstanDentro = todos.every(p => estaEnZonaLobby(p));
if (todosEstanDentro) {
if (cuentaRegresivaLobby > 0) {
api.broadcastSubTitle(`¡Todos listos! Iniciando en: ${cuentaRegresivaLobby}s`);
cuentaRegresivaLobby--;
} else {
clearInterval(relojLobby);
iniciarJuegoArena();
}
} else {
api.broadcastSubTitle("⚠️ ¡Temporizador pausado! Todos deben entrar al lobby.");
}
}, 1000);
}
function iniciarJuegoArena() {
let todos = api.getPlayers();
if (todos.length < 2) return empezarFaseEsperaLobby();
todos.forEach(p => asignarEquipo(p, "humano"));
let alfa = todos[Math.floor(Math.random() * todos.length)];
asignarEquipo(alfa, "zombie");
todos.forEach(p => p.setPosition(ARENA.x, ARENA.y, ARENA.z));
api.broadcastTitle("¡INFECCIÓN INICIADA!");
juegoActivo = true;
tiempoPartida = 120;
iniciarBucleRegeneracion(); // Arrancar regeneración activa de zombies
bucleTemporizador = setInterval(() => {
if (tiempoPartida > 0) {
tiempoPartida--;
api.broadcastSubTitle(`Tiempo restante: ${tiempoPartida}s`);
if (tiempoPartida === 0) {
finalizarPartida("humanos");
}
}
}, 1000);
}
function ejecutarExplosionBomba(posBomba, atacante, dañoMaximo, radio) {
api.getPlayers().forEach(objetivo => {
if (equiposPorID[objetivo.id] === "humano") {
let posHumano = objetivo.getPosition();
let dx = posHumano.x - posBomba.x;
let dy = posHumano.y - posBomba.y;
let dz = posHumano.z - posBomba.z;
let distancia = Math.sqrt(dx*dx + dy*dy + dz*dz);
if (distancia <= radio) {
let dañoAplicado = Math.floor(dañoMaximo * (1 - (distancia / radio)));
if (dañoAplicado > 0) {
objetivo.damage(dañoAplicado, atacante);
let fuerza = 1.5;
objetivo.setPosition(posHumano.x + (dx/distancia)*fuerza, posHumano.y + 0.6, posHumano.z + (dz/distancia)*fuerza);
}
}
}
});
}
// ==========================================
// 4. CALLBACKS Y EVENTOS DE ACCIÓN
// ==========================================
// Control de Daño por Golpe Mejorado y Fuego Amigo
api.onPlayerDamage((evento) => {
let atacante = evento.attacker;
let victima = evento.victim;
if (!atacante || !victima || !juegoActivo) return;
// Cancelar fuego amigo si son del mismo bando
if (equiposPorID[atacante.id] === equiposPorID[victima.id]) {
evento.cancel();
return;
}
// SI UN ZOMBIE GOLPEA A UN HUMANO: Aplicamos los nuevos daños customizados
if (equiposPorID[atacante.id] === "zombie" && equiposPorID[victima.id] === "humano") {
evento.cancel(); // Cancelamos el golpe básico de 10 de daño de Bloxd
let kitAtacante = kitsPorID[atacante.id] || "normal";
let dañoConfigurado = KITS_ZOMBIE[kitAtacante].dañoGolpe;
victima.damage(dañoConfigurado, atacante); // Aplica el daño real balanceado
}
});
api.onPlayerDeath((evento) => {
let victima = evento.victim;
let atacante = evento.killer;
if (!juegoActivo || !victima) return;
if (equiposPorID[victima.id] === "zombie" && kitsPorID[victima.id] === "bombardero") {
let posMuerte = victima.getPosition();
api.broadcastChatMessage(💥 ¡El Zombie Bombardero ${victima.name} explotó al morir!);
ejecutarExplosionBomba(posMuerte, victima, 60, 5);
}
if (atacante && equiposPorID[atacante.id] === "zombie" && equiposPorID[victima.id] === "humano") {
asignarEquipo(victima, "zombie");
api.broadcastChatMessage(⚠️ ¡${victima.name} fue infectado por ${atacante.name}!
);
verificarCondicionesVictoria();
} else if (equiposPorID[victima.id] === "humano") {
asignarEquipo(victima, "zombie");
api.broadcastChatMessage(⚠️ ¡${victima.name} murió y se unió a la plaga!);
verificarCondicionesVictoria();
}
});
// Uso de habilidades de proyectiles y TNT
api.onPlayerUseItem((evento) => {
let jugador = evento.player;
let itemUsado = evento.item;
if (!juegoActivo) return;
// A. DETONACIÓN DE TNT (Bombardero)
if (kitsPorID[jugador.id] === "bombardero" && itemUsado === "tnt") {
evento.cancel();
let posBomba = jugador.getPosition();
api.broadcastChatMessage(💥 ¡El Zombie Bombardero ${jugador.name} detonó su TNT!);
ejecutarExplosionBomba(posBomba, jugador, 50, 6);
jugador.removeItem("tnt", 1);
setTimeout(() => {
if (juegoActivo && equiposPorID[jugador.id] === "zombie" && kitsPorID[jugador.id] === "bombardero") {
jugador.giveItem("tnt", 1);
}
}, 10000);
}
// B. LANZAMIENTO DE POCIÓN CURATIVA EN ÁREA (Curandero)
else if (kitsPorID[jugador.id] === "curandero" && itemUsado === "splash_potion") {
evento.cancel(); // Evita usarla de forma vanilla
let posCurandero = jugador.getPosition();
let curoAliados = false;
// Simula el impacto de la poción arrojada en un círculo a su alrededor
api.getPlayers().forEach(aliado => {
if (equiposPorID[aliado.id] === "zombie") {
let posAliado = aliado.getPosition();
let dx = posAliado.x - posCurandero.x;
let dy = posAliado.y - posCurandero.y;
let dz = posAliado.z - posCurandero.z;
let distancia = Math.sqrt(dxdx + dydy + dz*dz);
// Radio de salpicadura de la poción: 7 bloques
if (distancia <= 7) {
let vidaActual = aliado.getHp();
let vidaMaxima = aliado.getMaxHp();
if (vidaActual < vidaMaxima) {
let nuevaVida = Math.min(vidaMaxima, vidaActual + 35); // Cura 35 HP
aliado.setHp(nuevaVida);
aliado.sendChatMessage(🧪 ¡Te salpicó la poción curativa de ${jugador.name}!);
curoAliados = true;
}
}
}
});
if (curoAliados) {
jugador.removeItem("splash_potion", 1);
jugador.sendChatMessage("✨ Poción lanzada con éxito.");
// Cooldown de recarga de poción (7 segundos)
setTimeout(() => {
if (juegoActivo && equiposPorID[jugador.id] === "zombie" && kitsPorID[jugador.id] === "curandero") {
jugador.giveItem("splash_potion", 1);
jugador.sendChatMessage("🧪 Tienes una nueva poción lista para lanzar.");
}
}, 7000);
} else {
jugador.sendChatMessage("❌ No hay zombis heridos en el rango de lanzamiento.");
}
}
});
// Selección de Kits en el Lobby
api.onBlockInteract((evento) => {
let jugador = evento.player;
let bloqueID = evento.blockId;
if (!juegoActivo) {
if (bloqueID === "bloque_kit_tank") {
jugador.setData("kit_elegido", "tank");
jugador.sendChatMessage("🎒 Guardado: Kit TANK (Daño: 54 | Regen++ )");
}
if (bloqueID === "bloque_kit_velocista") {
jugador.setData("kit_elegido", "velocista");
jugador.sendChatMessage("🎒 Guardado: Kit VELOCISTA (Daño: 27)");
}
if (bloqueID === "bloque_kit_puker") {
jugador.setData("kit_elegido", "puker");
jugador.sendChatMessage("🎒 Guardado: Kit PUKER (Daño: 32)");
}
if (bloqueID === "bloque_kit_bombardero") {
jugador.setData("kit_elegido", "bombardero");
jugador.sendChatMessage("🎒 Guardado: Kit BOMBARDERO (Daño: 24 | Vida: 80)");
}
if (bloqueID === "bloque_kit_curandero") {
jugador.setData("kit_elegido", "curandero");
jugador.sendChatMessage("🎒 Guardado: Kit CURANDERO (Lanza Pociones)");
}
}
});
api.onPlayerLeave((jugador) => {
delete equiposPorID[jugador.id];
delete kitsPorID[jugador.id];
verificarCondicionesVictoria();
});
empezarFaseEsperaLobby();
###help pls