I am working on a trident that tps the player who threw it to itself. It works pretty well, but I would like it to target only players who are at least five blocks away. The point of this is to be able to tp the player next to the trident (where it would not be picked up immediately) without causing a loop.
I tried using this command, but it does not work. It tps the player to itself regardless of distance.
execute as @e[type=minecraft:trident,nbt={inGround: 1b,CustomName: '{"text":"test"}'}] at @a[distance=5..] if score @p player_id = @s player_id run tp @p @s
Can anyone see what I am missing?
Regards!
P.S.: the problem with teleporting to the trident's exact position is that if you throw it at a wall, you will spawn inside it and suffocate.
A repeating command to assign all players an id if they don't already have one
execute as @a unless score @s id = @s id store result score @s id run scoreboard players add #id_holder id 1
Lastly a repeating chain to teleport the player to their trident if it is in the ground and more than 5 blocks away:
1: Copy the players ID to the nearest trident that doesn't have an ID, if that player has just thrown a tagged trident.
execute as @a[scores={used_trident=1}] at @s as @e[type=trident, sort=nearest, limit=1, nbt={Trident:{tag:{my:trident}}}] unless score @s id = @s id run scoreboard players operation @s id = @a[distance=..0.1] id
2: Teleport the player to any trident that is in the ground and has the same ID as the player.
execute as @e[type=trident, nbt={inGround:true, Trident:{tag:{my:trident}}}] at @s as @a[distance=5..] if score @s id = @e[type=trident, distance=..0.1, nbt={Trident:{tag:{my:trident}}}, limit=1] id run tp @s[tag=!dev] @e[type=trident, distance=..0.1, nbt={Trident:{tag:{my:trident}}}, limit=1]
3: Reset the players score.
scoreboard players reset @a used_trident
This may not be exactly what you want, but hopefully it will help a bit.
There is actually an even easier and more performant way to do this.
# Setup command
/scoreboard objectives add useTrident minecraft.used:minecraft.trident
# Repeating
/execute as @e[type=minecraft:trident,nbt={inGround:1b}] at @s on origin facing entity @s eyes run tp @s[scores={useTrident=1},distance=5..] ^ ^ ^.5
# Chain, non conditional
/execute as @e[type=minecraft:trident,nbt={inGround:1b}] on origin as @s[scores={useTrident=1}] run scoreboard players reset @s useTrident
This will teleport a player only once if they are more than 5 blocks away. This also solves the problem of teleporting into blocks when you throw the trident at a wall.
You can add special tags or anything else if you desire.
Dear all,
I am working on a trident that tps the player who threw it to itself. It works pretty well, but I would like it to target only players who are at least five blocks away. The point of this is to be able to tp the player next to the trident (where it would not be picked up immediately) without causing a loop.
I tried using this command, but it does not work. It tps the player to itself regardless of distance.
execute as @e[type=minecraft:trident,nbt={inGround: 1b,CustomName: '{"text":"test"}'}] at @a[distance=5..] if score @p player_id = @s player_id run tp @p @s
Can anyone see what I am missing?
Regards!
P.S.: the problem with teleporting to the trident's exact position is that if you throw it at a wall, you will spawn inside it and suffocate.
Hello, not sure what version you are in, but here is something in 1.19.4
First give the player the trident with a custom tag, using the name to target things can often break.
Next set up some scores:
A repeating command to assign all players an id if they don't already have one
Lastly a repeating chain to teleport the player to their trident if it is in the ground and more than 5 blocks away:
1: Copy the players ID to the nearest trident that doesn't have an ID, if that player has just thrown a tagged trident.
2: Teleport the player to any trident that is in the ground and has the same ID as the player.
3: Reset the players score.
This may not be exactly what you want, but hopefully it will help a bit.
Hello,
There is actually an even easier and more performant way to do this.
This will teleport a player only once if they are more than 5 blocks away. This also solves the problem of teleporting into blocks when you throw the trident at a wall.
You can add special tags or anything else if you desire.
Hope this helps!
-TechnoBro03