1
How to TP player who has a specific item?
Okay, so I can't figure out how to do this. I'm making a map where a bunch of players are racing towards a specific item (a diamond) and, I want the single person who removes the item from the chest to be teleported to a specific location. I can't figure out a command (or combination of commands) to plug into a command block that could help me.
Testing for the closest player won't work either.
If anyone has any solutions, they are much appreciated! Thank you in advance!
-SW
Testing for the closest player won't work either.
If anyone has any solutions, they are much appreciated! Thank you in advance!
-SW
Create an account or sign in to comment.
13
Awesome! Thank you, ToadieOdie and Jmal116! Working like a charm!
Sorry, I forgot to mention that. Jmal116 is right. You can name your objectives whatever it is you wish them to be.
And thank you, Jmal116, for explaining what the "b" means inside the tag. This code isn't intuitive for me, so I feel like I'm working blind with it and the wikis I have found explain it like it is expected that you already understand most of it.
And thank you, Jmal116, for explaining what the "b" means inside the tag. This code isn't intuitive for me, so I feel like I'm working blind with it and the wikis I have found explain it like it is expected that you already understand most of it.
Sweet! Typing "Count:#b" into the code works. But why? What does the "b" mean inside the data tag?
The 'b' is short for byte, and it's the data type for that tag. Basically there's a small bug in the game where sometimes you have to specify that (like in this case). There are others like floats (f), shorts (s), strings, and probably a few others that I'm forgetting about.
Also just one more note about the scoreboard thing, you can have more than one objective with different names other than Science. Just change the name of the objective in the command ToadieOdie gave to whatever you want (no spaces) and it should work beautifully.
Also just one more note about the scoreboard thing, you can have more than one objective with different names other than Science. Just change the name of the objective in the command ToadieOdie gave to whatever you want (no spaces) and it should work beautifully.
it should be /testfor @a {...}
replace {...} with the data displayed in my previous message.
Also... for both commands (testfor and scoreboard) you might need to put a "b" behind the number to indicate the data type...
so instead of Count:5, use Count:5b
replace {...} with the data displayed in my previous message.
Also... for both commands (testfor and scoreboard) you might need to put a "b" behind the number to indicate the data type...
so instead of Count:5, use Count:5b
I tried doing that with the /testfor command, but it returns the error that the player is not found. Is the syntax different for the /testfor command?
in the command:
scoreboard players set @a Science 1 {Inventory:[{id:"minecraft:diamond"}]}
change
{Inventory:[{id:"minecraft:diamond"}]}
into
{Inventory:[{id:"minecraft:diamond",Count:#}]}
e.g:
{Inventory:[{id:"minecraft:diamond",Count:5}]}
scoreboard players set @a Science 1 {Inventory:[{id:"minecraft:diamond"}]}
change
{Inventory:[{id:"minecraft:diamond"}]}
into
{Inventory:[{id:"minecraft:diamond",Count:#}]}
e.g:
{Inventory:[{id:"minecraft:diamond",Count:5}]}
seriouswarriorHow would one create a scoreboard objective? I've implemented the commands into the map, and I get the error message: No objective was found by the name 'Science'. All I need is a command to set one of those up, and then if everything is right, it should work, right?
Type in the chat window:
/scoreboard objectives add Science dummy Science
to add this objective. Making it a "dummy" objective means that it can only be affected by commands.The first "Science" will be be your in system name for the objective while the second "Science" is the name that is displayed in whatever lists you have it displayed in if you choose to display it at all.
My only question that I would like to add to yours is how do you get it to test to see if the player is carrying a set number of items - say 5 diamonds instead of just at least 1?
SoulOfShadows23What he means by "continually target them with the selector @a[score_Science_min=1] is, when every time you place a command like a testfor or set player objective, you add the selector with it.
Ahh, okay. Just one last thing:
Jmal116Assuming you have a scoreboard objective already created . . .
How would one create a scoreboard objective? I've implemented the commands into the map, and I get the error message: No objective was found by the name 'Science'. All I need is a command to set one of those up, and then if everything is right, it should work, right?
What he means by "continually target them with the selector @a[score_Science_min=1] is, when every time you place a command like a testfor or set player objective, you add the selector with it.
Jmal116You can use NBT data to detect when a players has a diamond in their inventory.
That sounds really cool! I'm just not familiar with anything like scoreboards, so when you say:
Jmal116Just continue to target them with the selector @a[score_Science_min=1]
what would the full command for that be that I have to continually target them with?
You can use NBT data to detect when a players has a diamond in their inventory. You can use that to give them a score, and from there you can do pretty much whatever you want with them.
Assuming you have a scoreboard objective already created (I'll be calling mine 'Science', because I can), you can run commands like these:
Like I said, you can do pretty much anything once you get that score on there. Just continue to target them with the selector @a[score_Science_min=1], or whatever your objective is called. You can also add extra data to search for on the item if it has a custom name or something like that, but I'm not going to worry about that right now.
The other important thing is to remember to set everyone's score to 0 after each game:
Assuming you have a scoreboard objective already created (I'll be calling mine 'Science', because I can), you can run commands like these:
scoreboard players set @a Science 1 {Inventory:[{id:"minecraft:diamond"}]}
tp @a[score_Science_min=1] x y z
Like I said, you can do pretty much anything once you get that score on there. Just continue to target them with the selector @a[score_Science_min=1], or whatever your objective is called. You can also add extra data to search for on the item if it has a custom name or something like that, but I'm not going to worry about that right now.
The other important thing is to remember to set everyone's score to 0 after each game:
scoreboard players set @a Science 0