function startCountdown(player, locationName, x, y, z) {
let countdown = 5;
let cancel = false;
function countdownTick() {
if (cancel) {
player.sendMessage('§cWarp cancelled.');
return;
}
if (countdown > 0) {
player.sendMessage(`§fWarping in §a§l${countdown} §r§fseconds...`);
countdown--;
system.run(countdownTick, 20);
} else {
teleportPlayer(player, locationName, x, y, z);
}
}
player.sendMessage(`§fYou will be warped to §a§l${locationName}§r §fin §a§l${countdown} §r§fseconds. \n§cType 'cancel' to stop.`);
system.run(countdownTick, 20);
world.afterEvents.chat.subscribe((eventData) => {
if (eventData.source === player && eventData.message.toLowerCase() === 'cancel') {
cancel = true;
}
});
}
function teleportPlayer(player, locationName, x, y, z) {
player.teleport({ x: x, y: y, z: z });
player.sendMessage(`§aYou have successfully warped to your §l${locationName}!`);
}
#Am i doing this as it is not working and idk why
1 messages · Page 1 of 1 (latest)
function startCountdown(player, locationName, x, y, z) {
let countdown = 5;
let cancel = false;
function countdownTick() {
if (cancel) {
player.sendMessage('§cWarp cancelled.');
return;
}
if (countdown > 0) {
player.sendMessage(`§fWarping in §a§l${countdown} §r§fseconds...`);
countdown--;
system.runTimeout(countdownTick, 20);
} else {
teleportPlayer(player, locationName, x, y, z);
}
}
player.sendMessage(`§fYou will be warped to §a§l${locationName}§r §fin §a§l${countdown} §r§fseconds. \n§cType 'cancel' to stop.`);
system.runTimeout(countdownTick, 20);
world.afterEvents.chatSend.subscribe((eventData) => {
if (eventData.sender instanceof Player && eventData.message.toLowerCase() === 'cancel') {
cancel = true;
}
});
}
function teleportPlayer(player, locationName, x, y, z) {
player.teleport({ x: x, y: y, z: z });
player.sendMessage(`§aYou have successfully warped to your §l${locationName}!`);
}
also how would i do it so that if the player moves it cansels it
keep checking if the velocity is not equal to 0 then cancel it
what the he
what did you change
system.run to syste.runTmeout
oh
so how do i make it if thay move it cansels
how i do that
if (player.getVelocity().x != 0 || player.getVelocity().y != 0 || player.getVelocity().z != 0) cancel = true;
llike this
function startCountdown(player, locationName, x, y, z) {
let countdown = 5;
let cancel = false;
function countdownTick() {
if (cancel) {
player.sendMessage('§cWarp cancelled.');
return;
}
const velocity = player.velocity;
if (velocity.x !== 0 || velocity.y !== 0 || velocity.z !== 0) {
cancel = true;
player.sendMessage('§cWarp cancelled due to movement.');
return;
}
if (countdown > 0) {
player.sendMessage(`§fWarping in §a§l${countdown} §r§fseconds...`);
countdown--;
system.runTimeout(countdownTick, 20);
} else {
teleportPlayer(player, locationName, x, y, z);
}
}
player.sendMessage(`§fYou will be warped to §a§l${locationName}§r §fin §a§l${countdown} §r§fseconds. \n§cType 'cancel' to stop.`);
system.runTimeout(countdownTick, 20);
world.afterEvents.chatSend.subscribe((eventData) => {
if (eventData.sender === player && eventData.message.toLowerCase() === 'cancel') {
cancel = true;
}
});
}
function teleportPlayer(player, locationName, x, y, z) {
player.teleport({ x: x, y: y, z: z });
player.sendMessage(§aYou have successfully warped to your §l${locationName}!);
}
no, it's player.getVelocity()
were i put it
if (player.getVelocity().x != 0 || player.getVelocity().y != 0 || player.getVelocity().z != 0) cancel = true;
cancel = true;
player.sendMessage('§cWarp cancelled due to movement.');
return;
}
iv never delt with volcity
if (player.getVelocity().x != 0 || player.getVelocity().y != 0 || player.getVelocity().z != 0) {
cancel = true;
player.sendMessage('§cWarp cancelled due to movement.');
return;
}
how do i defin player
idk
.
Player
Player or player
Player
player in this is not define
player.sendMessage(§fYou will be warped to §a§o${locationName}§r §fin §a§l${countdown} §r§fseconds. \n§cType 'cancel' to stop.);
.
the entire code
function startCountdown(player, locationName, x, y, z) {
let countdown = 5;
let cancel = false;
function countdownTick() {
if (cancel) {
player.sendMessage('§cWarp cancelled.');
return;
}
if (player.getVelocity().x != 0 || player.getVelocity().y != 0 || player.getVelocity().z != 0) {
cancel = true;
player.sendMessage('§cWarp cancelled due to movement.');
return;
}
if (countdown > 0) {
player.sendMessage(`§fWarping in §a§l${countdown} §r§fseconds...`);
countdown--;
system.runTimeout(countdownTick, 20);
} else {
teleportPlayer(player, locationName, x, y, z);
}
}
}
player.sendMessage(`§fYou will be warped to §a§o${locationName}§r §fin §a§l${countdown} §r§fseconds. \n§cType 'cancel' to stop.`);
system.runTimeout(countdownTick, 20);
world.afterEvents.chatSend.subscribe((eventData) => {
if (eventData.sender === player && eventData.message.toLowerCase() === 'cancel') {
cancel = true;
}
});
function teleportPlayer(player, locationName, x, y, z) {
player.teleport({ x: x, y: y, z: z });
player.sendMessage(`§aYou have successfully warped to your §l${locationName}!`);
}