#trouble getting target dimension and applying to teleport

1 messages · Page 1 of 1 (latest)

wraith badger
#
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;
    }
}```
zenith temple
#

vvhat is error?

#

is there somevvhere?

wraith badger
zenith temple
wraith badger
#

need to define the targets dimension

vital venture
#

for you

zenith temple
#

entity is unloaded or target is not entity

zenith temple
#

if thats undefined then you cant read id of it

wraith badger
zenith temple
wraith badger
#

it still teleports the player just not in the right dimension

zenith temple
#

vvhere did you print it?

#

shovv code

#

and output

wraith badger
#
const dimension = player.dimension;``` found the issue
#

that is the fix

zenith temple
#

?

wraith badger
#

in the screenshot active target and active player is stringafyed in chat

zenith temple
#

dont you json stringify on native classes btvv

wraith badger
#
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)}`);```
zenith temple
#

does it vvorks?

wraith badger
#

yea it worked. my player teleported across dimension

zenith temple
#

xd

wraith badger
#

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;
    }
}```