1

Halp

Ayimany 7/12/20 4:50 pm
130
7/13/2020 1:48 am
K, so i'll be brief about this



I'm making a new datapack, i won't spoil what it is



But there is this little problem:

There is this command:
tp @s ^ ^2 ^10




Whenever the command is executed from the datapack's commands, it teleports the player to 24 0 56





Whenever the player executes it in game, it teleports them to the right place (Ten blocks in the direction you are facing)



Any ideas?
Posted by
Ayimany
Level 21 : Expert Llama
6

  Have something to say?

JoinSign in

2

One_Nose
07/13/2020 1:48 am
He/Him • Level 59 : Grandmaster Dragonborn Hero
history
This is because the command doesn't run at the right place. Adding "execute at @s" causes the command to run at the player.execute at @s run tp ^ ^2 ^10
2
Bertiecrafter
07/12/2020 5:30 pm
Level 72 : Legendary System
history
Yeah, by default a data pack executes as the server entity at the world spawn.
For command blocks it's the server entity at the command block location.
To change the location of execution, use /execute at:

/execute at @p run tp @p ^x ^y ^z(Note that @s wouldn't work, because that selects the server entity, not the player)
We can extend this to execute as the player, making @s refer to the nearest player:
/execute as @p at @s run tp @s ^x ^y ^zAnd finally, instead of selecting the nearest player, we can select all players matching a certain conditions, see target selector arguments.
/execute as @a[​gamemode=survival] at @s run tp @s ^x ^y ^zNote that "@s" still refers to what's being targetted in the "as" instruction, which is "@a[​gamemode=survival]" in the last command.
4

Welcome