I'd like to cancel fall damage only if specific criteria are met, but I don't know of any way to cancel damage in ScriptAPI
I believe there is a way to do so using the player.json, but it's not dynamically controlled by the SciptAPI
What would be the best way to sync up the two? Is there another way to cancel damage? Like make the player invulnerable for a tick?
#Cancel damage
1 messages · Page 1 of 1 (latest)
You could try this:
system.runInterval(() => {
world.getPlayers().forEach((player) => {
if (!(/** YOUR CRITERIA HERE */)) return;
if (player.isFalling && !world.getDimension(player.dimension).getBlock(new Vector3(player.location.x, player.location.y - 0.5, player.location.z)).isAir) {
player.applyImpulse(new Vector3(0, player.getVelocity().y, 0));
}
});
});
aplyImpulse doesn't work for players
What about applyKnockback()? That works
I'm not sure applying knockback resets fall timer
actually I know it doesn't, I tested it for another project
teleport the player to where the player already is
That resets the fall timer, if the documentation is correct
oh thanks
I would recommend you to just use player.fallDistance, is the property that keeps track of how many blocks an entity (players included) has falled and how much damage it will take once ir touches ground, constantly setting it to 1 if your criteria is met should be enough.
You could just constantly set the fall distance to 1 or 0, the teleport does the same, reset the fall distance, but if you wanna be more specific, just do what our other friend suggested but instead of the teleport just do
player.fallDistance = 1```
And that should be enough
what version of script api can you do this in?
i only checked the docs for 1.4.0 beta and 1.20.30.21 preview beta, and both had the property as read only
Documentation for Script API - v1.20.30.21
just tested and it throws no setter for this property
Well, then forget what I said xd
I normally use this documentation so, I thought it was not read only.
But, a more discrete way than the teleport I think would be to just give 1 or 2 seconds of slow falling when the player is about to touch the ground,
Documentation for Script API - v1.20.30.21
When they have enough speed the effect doesn't shows them down but still cancels fall damage
I'm not sure if it resets the fall distance, I think it does, but you can't apply that constant
.
Or third option, just use player.json , do so the fall damage is negated when the player has a tag, and control that that through scripting using player.addTag() player.removeTag() and player.hasTag()
@vernal nimbus
If you prefer that
You could still use player.fallDamage to know when the player is going to hurt themselves for the fall to avoid constant teleports or slow falling when they give down a 1 block tall fall if you want xd
.
Or Sprint jumping
I thought about it but yeah it's readonly
oh my not applyImpulse
@leaden rivere teleportaion trick worked, thanks
Happy to hear that!
It works for u but it’s not 100% sure it does for others players as they could lag
teleporting alway resets velocity, I don't see how lag would affect that
Might not always execute the code in time