#I need help with detecting player air value underwater

1 messages · Page 1 of 1 (latest)

regal thistle
spice quest
#

Yup, total can be 15, but what if there will be 0?
I want script to detect that and then teleport player above water

#

Also, I want that because player have disabled damage cause on full map inside entity.json

#

This won't do the dmg to player, but it needs to teleport him

spice quest
#

@regal thistle Do you have any idea?

regal thistle
#
import { system, world } from "@minecraft/server";

const previousBeathableLocations = {};

system.runInterval(() => {
    for (const player of world.getAllPlayers()) {
        const air = player.getComponent("minecraft:breathable").airSupply;
        const previousBreath = previousBeathableLocations[player.id] ??= { air }

        if (air === 0) {
            if (previousBreath.air++ < 2) continue;
            previousBreath.air = 0;
            player.teleport(previousBreath.location, { facingLocation: player.location });
        } else {
            previousBreath.air &&= 0
            if (air === 15) previousBreath.location = player.location
        };
    }
}, 10);
#

;-;

#

it only saves one location tho

#

so if that location got obstructed, then it's gona be another code

spice quest
spice quest
#

I think I might miss understood this. I don't need previouslocation. I have one spawn point for player near lake. I want, every time player reach 0 of air under water in lake - he will be teleported to this spawn point

regal thistle
#
import { system, world } from "@minecraft/server";


const teleportLocation = { x: -107.02, y: 50.20, z: 97.15 };
const previousBeathableLocations = {};

system.runInterval(() => {
    for (const player of world.getAllPlayers()) {
        const air = player.getComponent("minecraft:breathable").airSupply;
        const previousBreath = previousBeathableLocations[player.id] ??= { air }

        if (air === 0) {
            if (previousBreath.air++ < 2) continue;
            previousBreath.air = 0;
            player.teleport(teleportLocation, { facingLocation: player.location });
        } else previousBreath.air &&= 0;
    }
}, 10);
spice quest
#

Honestly I don't know, it's not working

regal thistle
#

//for testing purposes
system.runInterval(() => {
    for (const player of world.getAllPlayers()) {
        const breath = player.getComponent("breathable")
        const brr = {}
        for (const key in breath) {
            if (typeof breath[key] !== "number") continue;
            brr[key] = breath[key];
        }
        console.warn(JSON.stringify(brr, null, 3))
    }
})