2

I have a set of command blocks that do the following:

  1. Test that all players have a skull in their inventory
  2. if not, give all players a skull
  3. kill all players

basicly, if someone drops the skull they are given another and then killed. (a way of getting back to their spawn point).

obviously, in multilayer this causes some problems.

  1. if one player does not have the skull, the test runs positive even if others do have it.
  2. all players are then given another skull, leaving those who did not drop it with more than one.
  3. all players are then killed.

is there a way where i can store the player's name who dropped the skull, then only take the following actions on them?

basicly, i want to be able to dynamicly replace @a with a player name.

also, is there a way that i can detect if a player has right clicked the item in their hot bar rather than if they have dropped it?

  • Have you tried the 'If this guy has the skull, set the score of [something] for him to 1' trick? Then command blocks that affects them would just be /[something] @a[score_name_min=1] or something like that? – aytimothy Nov 22 '14 at 7:08
  • @aytimothy no, but could you provide a more detailed example/explanation? im mostly new to advanced command block usage. – Thedudxo Nov 22 '14 at 7:53
  • Could you please do research into your question rather than asking us to do it for you. If you understand what I said: I'll clarify. But if you don't know how to "How do I make a counter?" - RESEARCH IT YOURSELF. – aytimothy Nov 23 '14 at 5:11
  • @aytimothy i have done research. your answer simply confused me, how was i to know to make a counter? the way you put it it looked like a single command. if you don't beleive i have done researh, i have made it work dynamicly (one button does all) up to 4 players. please don't auto assume and perhaps make your answers clearer, like you did in your edit. i have done research before asking this question, learning about /clear to test for an item. otherwise, my question would be more like "how to kill a player when they drop an item". – Thedudxo Nov 23 '14 at 5:36
3

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?

enter image description here
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)

  • i'm having trouble with the following: /scoreboard players set @p playerID [1,2,3]. i have set it up so that each player must pass through an area (which activates this) before starting. the game gives me the error: '[1,2,3]' is not a valid number. it works with just the number 1, but then every player is going to get 1. i don't think i'm doing it right. – Thedudxo Nov 23 '14 at 4:30
  • @Thedudxo, you can't give players numbers with a single command. You'll need to make multiple gates, or a dynamic gate that gives each player a number, different to the other players. The square bracket simple means 'Replace this with any number between 1 and java's 32/64-bit value limit'. – aytimothy Nov 23 '14 at 5:01
  • 1
    Actually it's possible to store command's output(result) to scoreboard. minecraft.gamepedia.com/Commands#stats – QbsidianH20 Nov 23 '14 at 20:08
0

In that snapshot, you probably couldn't do it, but now the /execute command really helps out ;)

/execute @p ~ ~ ~ clear @p minecraft::Skull 0 0 to check if he has a skull (as @aytimothy said)

Wired up to a comparator and redstone repeater to a next command block :

/execute @p ~ ~ ~ give @p minecraft:skull 1

This way you don't need to depend on creating UIDs to each player.

  • Use @s rather than @p after the /execute – pppery Sep 6 '18 at 11:23
0

This answer is based on the answer above.

You can give IDs with one single pressure plate by doing as follows:

  • Put a comparator to the command block with tp, where you attach a command block which places a command block with the next command set exactly where the previous command block was (with a repeater if necessary so you have enough delay for the new command block not to trigger immediately).
  • In the same way, you can replace the command of the second command block with one that makes it replace the first command with one giving the ID 3.
  • By chaining command blocks in this fashion (can be annoying depending on how many players you want to allow) you can have the command blocks update their commands with each ID.
  • In the end of the chain you make a command block that sets a command that sets a command that sets a command... and so on, that changes the first command into giving the player spectator mode.

And of course, you attach the tp command block to the ID setting command block and keep it unchanged all the time.

To illustrate what happens when this is running, I wrote the commands for a chain of three command blocks.

Assumptions (it should be clear what to change depending on the actual situation, if not could someone who gets it clarify in the comments, I'm too tired right now):

  • The first command block is on the coords 0, 10, 0.
  • The chain is oriented towards positive X.
  • There is exactly one repeater after each comparator.
  • The spawn of the game itself is at 100, 100, 100.

Commands:

scoreboard players set @p playerID 1
tp @p 100 100 100
setblock 0 10 0 minecraft:command_block 0 replace {Command:scoreboard players set @p playerID 2,TrackOutput:0}
setblock 3 10 0 minecraft:command_block 0 replace {Command:setblock 0 10 0 minecraft:command_block 0 replace {Command:scoreboard players set @p playerID 3,TrackOutput:0},TrackOutput:0}
setblock 6 10 0 minecraft:command_block 0 replace {Command:setblock 3 10 0 minecraft:command_block 0 replace {Command:setblock 0 10 0 minecraft:command_block 0 replace {Command:gamemode 3 @p,TrackOutput:0},TrackOutput:0},TrackOutput:0}

Remarks:

  • The commands are generated with MCStacker.
  • The TrackOutput parameter might need to be removed, as it's possibly 1.9-specific.
  • This chain is not tested, as I can't work on multiplayer.

What should happen:

  • The first player steps on the pressure plate.
  • The player gets the ID 1.
  • The player is teleported to the game spawn.
  • The command scoreboard players set @p playerID 2 is set for the first command block.
  • The command setblock 0 10 0 minecraft:command_block 0 replace {Command:scoreboard players set @p playerID 3,TrackOutput:0} is set for the second command block (or the third, if you count the tp command block).
  • The command setblock 3 10 0 minecraft:command_block 0 replace {Command:setblock 0 10 0 minecraft:command_block 0 replace {Command:gamemode 3 @p,TrackOutput:0},TrackOutput:0} is set for the third command block.
  • The second player steps on the pressure plate.
  • The player gets the ID 2.
  • The player is teleported.
  • First command block gets scoreboard players set @p playerID 3.
  • Second command block gets setblock 0 10 0 minecraft:command_block 0 replace {Command:gamemode 3 @p,TrackOutput:0}.
  • Third command block gets what it has.
  • Third player gets ID 3 and gets teleported.
  • First command block gets gamemode 3 @p.
  • Second and third command blocks get what they have.
  • Any future player goes into Spectator Mode, gets teleportedd, and all command blocks get the commands they already have.

This scheme can be extended. If someone likes it, and is good at webapp coding, feel free to write a generator.

Also, in the new snapshots for 1.9, things get a lot easier: You can directly check for players dropping skulls using scoreboard.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.