how to get and store player name?

how to get and store player name? - From above crop person holding red vinyl disc with inscription cover in music shop

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?



Best Answer

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.




Pictures about "how to get and store player name?"

how to get and store player name? - Woman Buying a Drink
how to get and store player name? - Assorted yummy sweets and bakery products places on counter of confectionery shop in daytime
how to get and store player name? - Grayscale Photography of Farmacia Store Front



How do you make a player name?

How do I create a player name and avatar on Facebook?
  • Open the game you want to play.
  • Tap Create Player Name.
  • Tap to choose an avatar.
  • Enter a name to represent yourself in-game.
  • Tap Save.




  • IShowSpeed Pronouncing FIFA Players Names Wrong COMPILATION 😂💀




    More answers regarding how to get and store player name?

    Answer 2

    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.

    Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

    Images: Erik Mclean, Robert Nagy, Maria Orlova, Juan Pablo Serrano Arenas