Nuke Sword
Hitting enenmies has a chance of them exploding
← Back to main
World Code:
const damageBlockedPlayers = new Set();
const blastSwordName = "Explosive Sword";
const explosionRadius = 5;
const explosionForce = 30;
const explosionDamage = 25;
onPlayerDamagingOtherPlayerExplosive = (attackerId, targetId, damageDealt, withItem, bodyPartHit, damagerDbId) => {
if (damageBlockedPlayers.has(attackerId)) return;
const held = api.getHeldItem(attackerId);
if (!held || held.name !== "Iron Sword" || held.attributes?.customDisplayName !== blastSwordName) return;
// 🎲 20% chance to trigger explosion
if (Math.random() >= 0.2) return;
const pos = api.getPosition(targetId);
if (!pos) return;
const [x, y, z] = pos;
// 💥 Particle explosion
api.playParticleEffect({
texture: "square_particle",
dir1: [-1, -1, -1],
dir2: [1, 1, 1],
pos1: [x - 2.5, y, z - 2.5],
pos2: [x + 2.5, y + 2, z + 2.5],
minLifeTime: 0.3,
maxLifeTime: 0.6,
minEmitPower: 5,
maxEmitPower: 8,
minSize: 0.4,
maxSize: 0.7,
manualEmitCount: 100,
gravity: [0, -10, 0],
colorGradients: [
{
timeFraction: 0,
minColor: [255, 100, 0, 1],
maxColor: [255, 200, 50, 1],
},
],
velocityGradients: [
{
timeFraction: 0,
factor: 1,
factor2: 1,
},
],
blendMode: 1,
hideDist: 30,
});
// 🌪 Knockback all players and damage others (except attacker)
for (const otherId of api.getPlayerIds()) {
const otherPos = api.getPosition(otherId);
if (!otherPos) continue;
const dx = otherPos[0] - x;
const dy = otherPos[1] - y;
const dz = otherPos[2] - z;
const distSq = dx * dx + dy * dy + dz * dz;
if (distSq <= explosionRadius * explosionRadius) {
const dist = Math.sqrt(distSq);
let pushX, pushY = 10, pushZ;
if (dist === 0) {
pushX = 0;
pushZ = 0;
} else {
pushX = (dx / dist) * explosionForce;
pushZ = (dz / dist) * explosionForce;
}
api.applyImpulse(otherId, pushX, pushY, pushZ);
if (otherId !== attackerId) {
damageBlockedPlayers.add(attackerId);
api.attemptApplyDamage({
eId: attackerId,
hitEId: otherId,
attemptedDmgAmt: explosionDamage,
withItem: "Iron Sword",
attackDir: [dx, dy, dz],
showCritParticles: true,
isTrueDamage: true,
});
damageBlockedPlayers.delete(attackerId);
}
}
}
};