filler

Crash Glider

Crashing into the ground causes a big BOOM. More fall damage taken = bigger explosion damage

← Back to main

Code Block:


api.giveItem(myId, "Iron Hang Glider", 1, {
  customDisplayName: "Crash Glider"
});
      

World Code:


//Timeout Code by Sulfrox (the older one)
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]}}

onPlayerAltAction = (playerId) => {
  const held = api.getHeldItem(playerId);
  const facing = api.getPlayerFacingInfo(playerId);
  if (!facing || !facing.dir) return;
  if (!held || held.name !== "Iron Hang Glider" || held.attributes?.customDisplayName !== "Crash Glider") {
  return;
  }

  const [dx, dy, dz] = facing.dir;
  const force = 30;

  const impulseX = dx * force;
  const impulseY = dy * force + 10;
  const impulseZ = dz * force;

  // Launch
  api.setPlayerPhysicsState(playerId, { type: 0, tier: 0 });
  api.applyImpulse(playerId, impulseX, impulseY, impulseZ);


  // Restore physics state
  setTimeOut(() => {
    api.setPlayerPhysicsState(playerId, { type: 2, tier: 3 });
  }, 500);

  // Check if player is midair at launch
  const pos = api.getPosition(playerId);
  if (!pos) return;

  const [startX, startY, startZ] = pos.map(Math.floor);
  const blockBelow = api.getBlock(startX, startY - 1, startZ);
  if (blockBelow !== "Air") return;
  const inithealth = api.getHealth(playerId)

  // Start FAST FALL tracking
  let tries = 0;
  const checkFall = () => {
    const pos = api.getPosition(playerId);
    if (!pos) return;
    const [x, y, z] = pos.map(Math.floor);
    const blockBelow = api.getBlock(x, y - 1, z);

    if (blockBelow !== "Air") {
      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: 80,
        gravity: [0, -15, 0],
        colorGradients: [
            {
                timeFraction: 0,
                minColor: [255, 100, 0, 1],
                maxColor: [255, 200, 50, 1],
            },
        ],
        velocityGradients: [
            {
                timeFraction: 0,
                factor: 1,
                factor2: 1,
            },
        ],
        blendMode: 1,
        hideDist: 25,
      });
      const newhealth = api.getHealth(playerId)
      const healthdiff = inithealth - newhealth
      const radius = 5;
      
      for (const otherId of api.getPlayerIds()) {
        if (otherId === playerId) continue;
        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 <= radius * radius) {
          setTimeOut(api.attemptApplyDamage({eId:playerId,hitEId:otherId,attemptedDmgAmt:Math.max(healthdiff*1.5,10),withItem:"Iron Hang Glider",attackDir:[dx,dy,dz],showCritParticles:!0,isTrueDamage:!0}), 100)
        }
      }
      api.setPlayerPhysicsState(playerId, { type: 0, tier: 0 });
      return; // Stop tracking after explosion
    }

    tries++;
    if (tries < 20) {
      setTimeOut(checkFall, 100);
    }
  };

  setTimeOut(checkFall, 100);
};