#Making fall damage negligible using scripts ?

1 messages · Page 1 of 1 (latest)

hushed hare
#

Your only reliable options using just scripts are to either add slow_falling or resistance V right before the player hits the ground.
Other than that you could try to teleport the player in place to reset their velocity, or launch them upwards at just the right speed using applyKnockback , but I don't know for sure if they negate fall damage.

runic heart
#

maybe but it will be quite a lot to do, use this:

let fallingState = new Map();
system.runInterval(() => {
  const players = world.getAllPlayers();
  players.forEach(player => {
    const playerId = player.id;
    const playerloc = player.location;
    const loc1 = player.dimension.getBlock(playerloc).below(2);
    const isOnGround = loc1.typeId.split(':')[1] !== 'air';
    const isFalling = player.isFalling && !player.isJumping && !player.isSprinting;
    const healthComponent = player.getComponent('health');
    if (!fallingState.has(playerId)) {
      fallingState.set(playerId, { isFalling: false, lastYPos: playerloc.y, sent: false });
    }
    const playerState = fallingState.get(playerId);
    if (isFalling && !playerState.isFalling) {
      fallingState.set(playerId, { isFalling: true, lastYPos: playerloc.y, sent: false });
    }
    if (isOnGround && playerState.isFalling && !playerState.sent) {
      const fallDistance = playerState.lastYPos - playerloc.y;
      if (Math.floor(fallDistance) >= 2) {
        const fallDamage = Math.floor(fallDistance - 1); //damage when fall
        const currentHealth = healthComponent.currentValue;
        player.applyDamage(0.01)
        //code
        healthComponent.setCurrentValue(currentHealth - fallDamage);
        player.sendMessage(`you have fall ${fallDistance.toFixed(2)} block with ${fallDamage} damage.`);
      }
      fallingState.set(playerId, { isFalling: false, lastYPos: playerloc.y, sent: true });
    }
    if (!isFalling && !isOnGround) {
      fallingState.set(playerId, { isFalling: false, lastYPos: playerloc.y, sent: false });
    }
  });
});
#

I'm pretty bad at calculating distance and velocity, but I got it close to the in-game damage.

#

make sure you turn off fall damage in game, use

/gamerule falldamage false
safe scroll
#

You can use player.json with scripts for that, if you are able to use it

unkempt pumice
#

Uhm I just change a little bit of things