function tpAccept(player, target) {
//player.sendMessage(`Active Requests: ${JSON.stringify(req.from)}`);
const req = requests.find((r) => r.from == target && r.to == player.name);
if (!req) player.sendMessage(`§4There is no tp request to §e"${player.name}"§4 from §a"${target}"`);
const currentTime = world.getAbsoluteTime();
const timeDifference = currentTime - req.time;
const dimension = target.dimension;
player.sendMessage(`Active Requests time: ${JSON.stringify(req.time)}`);
player.sendMessage(`Active current time: ${JSON.stringify(currentTime)}`);
player.sendMessage(`Active timeDifference time: ${JSON.stringify(timeDifference)}`);
player.sendMessage(`Active const dimension: ${JSON.stringify(dimension)}`);
if (timeDifference >= 1200) {
player.sendMessage(`§4The tp request from§e ${req.from} §4has expired`);
return;
}
if (timeDifference <= 1201) {
const tgt = world.getAllPlayers().find((t) => t.name == req.from);
tgt.teleport(player.location, {dimension: dimension});
//tgt.teleport(player.location, dimension);
requests.splice(requests.indexOf(req), 1);
player.sendMessage(`§eYou have accepted§a ${target} §eteleport request!`)
tgt.sendMessage(`§a ${player.name} §eHas accepted your teleport request!`)
return;
}
}```
#trouble getting target dimension and applying to teleport
1 messages · Page 1 of 1 (latest)
there could be tvvo reasons
need to define the targets dimension
entity is unloaded or target is not entity
nah, dont do that
if thats undefined then you cant read id of it
i have 2 accounts on a local world testing this in diffrent dimension
try printing that target and shovv me vvhat is that
it still teleports the player just not in the right dimension
ight
so? vvhat is target?
vvhere did you print it?
shovv code
and output
?
in the screenshot active target and active player is stringafyed in chat
dont you json stringify on native classes btvv
player.sendMessage(`Active Requests time: ${JSON.stringify(req.time)}`);
player.sendMessage(`Active current time: ${JSON.stringify(currentTime)}`);
player.sendMessage(`Active timeDifference time: ${JSON.stringify(timeDifference)}`);
player.sendMessage(`Active const dimension: ${JSON.stringify(dimension)}`);
player.sendMessage(`Active target: ${JSON.stringify(target)}`);
player.sendMessage(`Active player: ${JSON.stringify(player.name)}`);```
does it vvorks?
yea it worked. my player teleported across dimension
xd
and this just prints the variables in chat
in game
function tpAccept(player, target) {
//player.sendMessage(`Active Requests: ${JSON.stringify(req.from)}`);
const req = requests.find((r) => r.from == target && r.to == player.name);
if (!req) player.sendMessage(`§4There is no tp request to §e"${player.name}"§4 from §a"${target}"`);
const currentTime = world.getAbsoluteTime();
const timeDifference = currentTime - req.time;
const dimension = player.dimension;
//player.sendMessage(`Active Requests time: ${JSON.stringify(req.time)}`);
//player.sendMessage(`Active current time: ${JSON.stringify(currentTime)}`);
//player.sendMessage(`Active timeDifference time: ${JSON.stringify(timeDifference)}`);
//player.sendMessage(`Active const dimension: ${JSON.stringify(dimension)}`);
//player.sendMessage(`Active target: ${JSON.stringify(target)}`);
//player.sendMessage(`Active player: ${JSON.stringify(player.name)}`);
if (timeDifference >= 1200) {
player.sendMessage(`§4The tp request from§e ${req.from} §4has expired`);
return;
}
if (timeDifference <= 1201) {
const tgt = world.getAllPlayers().find((t) => t.name == req.from);
tgt.teleport(player.location, {dimension: dimension});
//tgt.teleport(player.location, dimension);
requests.splice(requests.indexOf(req), 1);
player.sendMessage(`§eYou have accepted§a ${target} §eteleport request!`)
tgt.sendMessage(`§a ${player.name} §eHas accepted your teleport request!`)
return;
}
}```