filler

Gaster Blaster

Shoot a WARDEN BEAM, that freezes, blinds and tosses enemies up

← Back to main

Code Block:


api.giveItem(myId, "Apple", 3, {
  customDisplayName: "Gaster Blaster"
});
      

World Code:


//Timeout Code by Sulfrox
class MinQueue{constructor(i,t,e){t=e=Uint32Array,this.c=i,this.k=new t(i+1),this.p=new e(i+1),this.h=!1,this.l=0}bbu(i){let t=this.k,e=this.p,r=t[i],h=e[i];for(;i>1;){let s=i>>>1;if(e[s]<=h)break;t[i]=t[s],e[i]=e[s],i=s}t[i]=r,e[i]=h}bbd(i){let t=this.k,e=this.p,r=t[i],h=e[i],s=1+(this.l>>>1),u=this.l+1;for(;i<s;){let n=i<<1,l=e[n],m=t[n],_=n,p=n+1;if(p<u&&e[p]<l&&(l=e[p],m=t[p],_=p),l>=h)break;t[i]=m,e[i]=l,i=_}t[i]=r,e[i]=h}push(i,t){if(this.l===this.c)throw"heap full";if(this.h)this.k[1]=i,this.p[1]=t,this.l++,this.bbd(1),this.h=!1;else{let e=this.l+1;this.k[e]=i,this.p[e]=t,this.l++,this.bbu(e)}}pop(){if(0!==this.l)return this.rpe(),this.l--,this.h=!0,this.k[1]}peekPriority(){if(0!==this.l)return this.rpe(),this.p[1]}peek(){if(0!==this.l)return this.rpe(),this.k[1]}rpe(){this.h&&(this.k[1]=this.k[this.l+1],this.p[1]=this.p[this.l+1],this.bbd(1),this.h=!1)}}let currently_running_timer,TimerQueue=new MinQueue(1024),TimerDictionary=[],TimerNum=0,TickNum=0;function setTimeOut(i,t){let e=TickNum+Math.floor(t/50);TimerDictionary[TimerNum]=i,TimerQueue.push(TimerNum,e),TimerNum++}function tick(){if(TickNum++,currently_running_timer)currently_running_timer(),currently_running_timer=void 0;else if(TimerQueue.peekPriority()<=TickNum){let i=TimerQueue.peek();void 0!==i&&(currently_running_timer=TimerDictionary[i]),TimerQueue.pop(),delete TimerDictionary[i]}}

const windBeamCooldowns = {};

onPlayerFinishChargingItem = (playerId,u,item,dur) => {
  if (item !== "Apple") return;
  if (u !== true) return
  fireWindBeam(playerId);
};

function blindness(playerId, durationMs) {
  const ticks = Math.floor(durationMs / 100); // number of visual pulses
  let count = 0;
  const interval = 100;

  // Apply Slowness and Darkness
  api.applyEffect(playerId, "Slowness", durationMs*1.5, { inbuiltLevel: 2 });
  api.applyEffect(playerId, "Darkness", durationMs*1.5, {
    displayName: "Darkness",
    icon: "Obsidian"
  });

  // Flash visual particles around the player's head
  const flashTick = () => {
    const pos = api.getPosition(playerId);
    if (!pos) return;

    const [x, y, z] = pos;
    const headY = y + 1.6;

    api.playParticleEffect({
      texture: "square_particle",
      dir1: [-1, -1, -1],
      dir2: [1, 1, 1],
      pos1: [x - 2, headY - 2, z - 2],
      pos2: [x + 2, headY + 2, z + 2],
      minLifeTime: 0.2,
      maxLifeTime: 0.4,
      minEmitPower: 0,
      maxEmitPower: 0,
      minSize: 1.5,
      maxSize: 3.5,
      manualEmitCount: 150,
      gravity: [0, 0, 0],
      colorGradients: [
        {
          timeFraction: 0,
          minColor: [0, 0, 0, 1],
          maxColor: [0, 0, 0, 1],
        },
      ],
      velocityGradients: [
        {
          timeFraction: 0,
          factor: 0,
          factor2: 0,
        },
      ],
      blendMode: 1,
      hideDist: 30,
    });

    count++;
    if (count < ticks) {
      setTimeOut(flashTick, interval);
    }
  };

  flashTick(); // Start visual effect loop
}


function fireWindBeam(playerId) {
  const now = Date.now();
  const cooldown = 10000;
  const lastUse = windBeamCooldowns[playerId] || 0;

  if (now - lastUse < cooldown) {
    const timeLeft = Math.ceil((cooldown - (now - lastUse)) / 1000);
    api.sendMessage(playerId, `Gaster Blaster on cooldown (${timeLeft}s left)`, { color: "gray" });
    api.giveItem(playerId, "Apple", 1, {customDisplayName: "Gaster Blaster"});
    return;
  }

  const pos = api.getPosition(playerId);
  const facing = api.getPlayerFacingInfo(playerId);
  const dir = facing?.dir;
  api.giveItem(playerId, "Apple", 1, {customDisplayName: "Gaster Blaster"});
  if (!pos || !dir) return;

  windBeamCooldowns[playerId] = now;

  const steps = 20;
  const spacing = 0.7;
  const radius = 1.5;

  for (let i = 1; i <= steps; i++) {
    const px = pos[0] + dir[0] * i * spacing;
    const py = pos[1] + dir[1] * i * spacing + 1;
    const pz = pos[2] + dir[2] * i * spacing;

    api.playParticleEffect({
      dir1: [-1, -1, -1],
      dir2: [1, 1, 1],
      pos1: [px, py, pz],
      pos2: [px + 1, py + 1, pz + 1],
      texture: "bubble",
      minLifeTime: 0.2,
      maxLifeTime: 0.6,
      minEmitPower: 2,
      maxEmitPower: 2,
      minSize: 0.25,
      maxSize: 0.35,
      manualEmitCount: 20,
      gravity: [0, -10, 0],
      colorGradients: [
        {
          timeFraction: 0,
          minColor: [60, 60, 150, 1],
          maxColor: [200, 200, 255, 1],
        },
      ],
      velocityGradients: [
        {
          timeFraction: 0,
          factor: 1,
          factor2: 1,
        },
      ],
      blendMode: 1,
    });

    // Check for enemy hits
    for (const otherPlayerId of api.getPlayerIds()) {
      if (otherPlayerId === playerId) continue;

      const opPos = api.getPosition(otherPlayerId);
      if (!opPos) continue;

      const dx = opPos[0] - px;
      const dy = opPos[1] - py;
      const dz = opPos[2] - pz;
      const distSq = dx * dx + dy * dy + dz * dz;

      if (distSq <= radius * radius) {
        api.attemptApplyDamage({
          eId: playerId,
          hitEId: otherPlayerId,
          attemptedDmgAmt: 35,
          withItem: "Apple",
          attackDir: [dir[0], dir[1], dir[2]],
          showCritParticles: true
        });

        // Chance-based effect
        const effectRoll = Math.random();
        if (effectRoll < 0.4) {
          api.applyEffect(otherPlayerId, "Frozen", 2000, { inbuiltLevel: 1 });
        } else if (effectRoll < 0.7) {
          api.applyImpulse(otherPlayerId, 0, 15, 0);
        } else {
          blindness(otherPlayerId, 4000);
        }    
      }
    }
  }
}