Arqade Asked by jklw10 on April 26, 2021
I’ve been trying to get together a per player spawn setting mechanism and currently stuck on storing a position and player UUID together in a way where it’s easily queryable and thus teleportable.
This is what i’ve tried so far:
/data modify entity 6f88f8eb-cfa3-44bf-a621-52b3e7d753e7 Pos set from storage game:player Spawn{target:'[{"selector":"@p"}]'}.location
That selector block is what isn’t working. I need a way to get a selector working in that nbt search part.
if that’s impossible something that drives the same functionality.
Also using a temp data storage would be acceptable if it’s passable into that target based query 🙂
Storage game:player has the following contents:
{
Spawn:[
{
location: [-39.89557466099629d, 66.0d, 42.25176377238329d],
target: [I; -1155610777, -758824872, -1437747869, 728530035]
}
]
}
The way I solved this is, I copied the list of spawns to a new location. Then I iterated through them by copying the item in location 0 of the list to a temporary spot named Current
, then removing it from the list so that the next iteration can get a new item.
# list_find.mcfunction --
# Set current to null to check if list is empty in the next step
data modify storage tools:iteration Current set value {}
# Set current to first item in list and check if it was successfull. if not loop wil exit if it hits iteration_continue.
execute store success storage tools:iteration IterationSuccess int 1 run data modify storage tools:iteration Current set from storage tools:iteration List[0]
# Remove currently processed item from list.
data remove storage tools:iteration List[0]
# Lists should always come as [Indexer, Item] pair lists
data modify storage tools:compare A set from storage tools:iteration Current.Indexer
function tools:compare
# If list item is what we're searching for. run exit loop procedures.
execute if data storage tools:compare Success run function tools:iteration_exit
#if not continue iteration (until list is empty)
execute unless data storage tools:compare Success run function tools:iteration_continue
#iteration_exit.mcfunction --
data modify storage tools:iteration Result set from storage tools:iteration Current.Item
#tellraw @a [{"text":"iteration result: "},{"storage":"tools:iteration","nbt":"Result"}]
#iteration_continue.mcfunction --
#if list isn't empty run iterate again
execute if data storage tools:iteration IterationSuccess run function tools:list_find
#tellraw @a [{"text":"iter success: "},{"storage":"tools:iteration","nbt":"IterationSuccess"}]
Now, I just compare the Current.Indexer and the player UUID by writing over current with /data modify
. However, because we need the current values later, we must store Current.Indexer
in a temporary storage.
If they're different, /data modify
returns 1. If they're the same, /data modify
returns 0. Then, reverse the result with a scoreboard for later ease of use.
#compare.mcfunction --
#used by a vscode plugin for auto completion
#define storage tools:compare
# tellraw @a [{"text":"Compared: "},{"storage":"tools:compare","nbt":"A"},{"text":" and "},{"storage":"tools:compare","nbt":"B"}]
# If an overwrite happens, a 1 will be stored in Global(fake player)'s CTemp score. If values are the same, a 0 will be stored.
execute store success score CompFail Tools run data modify storage tools:compare A set from storage tools:compare B
# Reverse and set to storage tools:compare success
execute if score CompFail Tools matches 0 run data modify storage tools:compare Success set value 1
execute if score CompFail Tools matches 1 run data modify storage tools:compare Success set value 0
#tellraw @a [{"text":"A == B: "},{"storage":"tools:compare","nbt":"Success"}]
If the comparison returns true, we can exit the loop and use the Current.Indexer
to teleport a tagged armor stand to the location. aka we data modify the armor stand Pos to Current.Item. and then tp player -> tagged armor stand
#spawn.mcfunction --
#prepare to find from spawns and get spawning player's coordinate.
data modify storage tools:compare B set from storage player:spawning ID
data modify storage tools:iteration List set from storage player:spawns List
function tools:list_find
data modify entity @e[tag=TPTarget,limit=1,sort=nearest] Pos set from storage tools:iteration Result
Correct answer by jklw10 on April 26, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP