#I need help with detecting player air value underwater
1 messages · Page 1 of 1 (latest)
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
@regal thistle Do you have any idea?
perhaps record the previous location of when the player's airSupply wasn't decreasing
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
I need to have only one location, so it's fine. But this code is not working somehow
with the import stuff?
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
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);
Honestly I don't know, it's not working
//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))
}
})