filler

Trumpet

Blow your enemies away!

← Back to main

Code Block:


api.giveItem(myId, "Gold Bar", 1, {
  customDisplayName: "Trumpet",
  customDescription: "Right-click to blast nearby players away!",
});
      

World Code:


//world code
const trumpetCooldowns = {};

onPlayerAltAction = function(playerId, x, y, z, block, targetEId) => {
    const heldItem = api.getHeldItem(playerId);
    if (!heldItem || heldItem.name !== "Gold Bar" || heldItem.attributes?.customDisplayName !== "Trumpet") return;

    const now = api.now(); 
    const lastUsed = trumpetCooldowns[playerId] || 0;
    const cooldown = 20000; 

    if (now - lastUsed < cooldown) {
        const secondsLeft = Math.ceil((cooldown - (now - lastUsed)) / 1000);
        api.sendMessage(playerId, `🎺 Trumpet is on cooldown (${secondsLeft}s left)`, { color: "gray" });
        return;
    }

    trumpetCooldowns[playerId] = now;

    const playerPos = api.getPosition(playerId);
    const [px, py, pz] = playerPos;

    // Play trumpet sound
    api.broadcastSound("sheepBaa1", 1, 1, {
        playerIdOrPos: playerId,
        maxHearDist: 15,
        refDistance: 10
    });

    // Particle effect
    api.playParticleEffect({
      dir1: [-1, -1, -1],
      dir2: [1, 1, 1],
      pos1: [px - 1.5, py, pz - 1.5],
      pos2: [px + 1.5, py + 1.5, pz + 1.5],
      texture: "soul_0",
      minLifeTime: 0.3,
      maxLifeTime: 0.6,
      minEmitPower: 2,
      maxEmitPower: 3,
      minSize: 0.2,
      maxSize: 0.4,
      manualEmitCount: 60,
      gravity: [0, -5, 0],
      colorGradients: [{
        timeFraction: 0,
        minColor: [189, 186, 0, 1],
        maxColor: [255, 255, 0, 1],
      }],
      velocityGradients: [{
        timeFraction: 0,
        factor: 1,
        factor2: 1,
      }],
      blendMode: 1,
    });

    // Push nearby players
    for (const otherId of api.getPlayerIds()) {
        if (otherId === playerId) continue;

        const [ox, oy, oz] = api.getPosition(otherId);
        const dx = ox - px, dy = oy - py, dz = oz - pz;
        const dist = Math.sqrt(dx * dx + dy * dy + dz * dz);

        if (dist <= 5) {
            const pushX = (dx / dist) * 40;
            const pushY = 30;
            const pushZ = (dz / dist) * 40;
            api.applyImpulse(otherId, pushX, pushY, pushZ);
        }
    }
};