Context:
In the Minecraft 14w08a, a snapshot between 1.8 and 1.7, you can now test for an item in a player's inventory by clearing 0 items of that type, as in the snapshot, it added the ability to specify the number of items to remove.
/clear [Player] [Item] [Data] [Count] [NBT Tags]
Except, it means that we have to identify the person and there is no way that you can capture the person in this. So, we need to give the player an identifier.
How do we do it?
This is a module. Repeat this contraption as many times as the number of players you want to track. So, 50 players means making this 50 times, but substituting the playerID for a different number, preferably plus one to the previous one.
Step 1: Create an identifier.
Using command blocks, you'll have to assign each player you want to test a value in a dummy score. Let's make a score called playerID
that is a dummy value.
/scoreboard objectives add playerID dummy playerID
So, whenever you want to test for a player (if it's a PvP/command-block related map, all players have to be assigned a number when the connect/join the game; not spectating).
Step 1b.
Create a gate. All players have to go onto it when the game starts. When the first player steps on it, they are assigned a scoreboard value in the objective "playerID". This is what we'll be using to identify each player.
/scoreboard players set @p playerID 1
Now, the next player should either have to go onto another pressure plate, or you can make that same pressure plate give a different number (more complicated, not going to say how).
Based on your comments, make a second gate for the second player and so on.
This gate should have /scoreboard players set @p playerID 2
and so on.
Step 2: Now, we'll have to a /testfor
for each player.
Place a fast clock (at about 10Hz; turns on 10 times a second). You may go faster - But it will not work with repeaters/comparitors etc. That pulse goes into a command block with this command:
/clear @p[score_playerID=1,score_playerID_min=1] minecraft:Skull 0 0
This will clear the player with the playerID score of 1 zero Skulls.
If the player has a Skull in their inventory, it'll clear none of it and output 'true'.
If the player doesn't have a Skull in their inventory... (Although it's trying to clear no skulls, it checks if there are skulls. /clear
commands output false
if the item is not found, reguardless of how many needs to be removed.)
So, place a comparitor facing out of that /clear [blah blah blah]
command block outputting to another command block. Now, let's put the "Oh, this guy fits this citeria."
/scoreboard objectives create hasSkull dummy hasSkull
/scoreboard players set @p[score_playerID=1,score_playerID_min=1] hasSkull 1
If you want the score to automatically revert to 0 when the player loses the skull, just make a flip-flop gate (one that outputs to the left if the input is on, and to the right if the input is off etc.), with when the input is false, it outputs a signal to a command block that does:
/scoreboard players set @p[score_playerID=1,score_playerID_min=1] hasSkull 0
Step 3: The annoying bit.
Now, repeat as many modules as you need for players. This time, change the score you're testing for, for example:
/clear @p[score_playerID=2,score_playerID_min=2] minecraft:Skull 0 0
instead of /clear @p[score_playerID=1,score_playerID_min=1] minecraft:Skull 0 0
etcra.
Step 4: Doing something with them.
Now that you have an objective that gives a score of '1' to anyone with a skull in their inventory... Or '0' to those without one, you can just make a command block which does things to the players with the score of 1.
Create a command block that tests for this, on a 20Hz clock (refreshes 20 times a second, the fastest possible clock)... Or slower if you wish.
/[something] @p[score_hasSkull=1,score_hasSkull_min=1] [more parameters]
For example: /kill @a[score_hasSkull=1,score_hasSkull_min=1]
(Kills everyone who has a skull)
Best Answer
You can do this using a villager with no trades and a
stat.talkedToVillager
objective. This is because a villager without trades doesn't show the trade interface at all.Summon an invisible ArmorStand with an invisible, silent Villager as it's passenger, like this:
Copy-paste version of the command:
The armor stand serves purely as a way to hold the villager in place. Play around with
<x> <y> <z>
until you find a good position for the villager. I suggest temporarily removing the villager's invisibility effect for "alignment" by replacing2147483647
with0
.Now, create your objective
Use a repeat/chain command block line to run the following commands:
Replace
X
,Y
,Z
andR
with appropriate values. This is to prevent triggering your torch lever when interacting with any villagers.