0

I need help figuring out what this command is supposed to be written with the new execute command syntax in Minecraft 1.17.1. I presume the code is supposed to set a player's spawnpoint randomly to positions having an armor stand with the tag 'Spawn' every time the player's dead, but I really need help figuring out the syntax.

/execute @r[type=Armor Stand,tag=Spawn] ~ ~ ~ /spawnpoint @r ~ ~ ~
2
  • This command alone is not enough to do all of that. It transaltes to "/execute at @r[type=armor_stand, tag=Spawn] /spawnpoint @r ~ ~ ~". This basically means "Choose a random armorstand with the tag spawn and set a random player's spawnpoint to the armor's pos".
    – BunnyMerz
    Oct 18, 2021 at 18:38
  • It'd be more practical to ask what you want to achieve instead of asking if this command will achieve that.
    – Joachim
    Oct 20, 2021 at 7:05

2 Answers 2

1

You put type=armor stand when it needs to be type=armor_stand

2
  • 1
    That is a principle of programmation that can be applied lots of places so good to learn! Most things in programming will be in one word, in CamelCase or split by underscores. Writing something in 2 words will often break the line of programming or make the program think you are referring to 2 different things (Like an Armor and a Stand, and not an Armor Stand)
    – Fredy31
    Oct 19, 2021 at 18:00
  • 1
    To add to what @Fredy31 is pointing out; it's also common practice to use single ' or double " quotes to wrap text that should be considered a single entry (e.g. type="armor stand"). Minecraft titles don't deviate from this, though it's more common with tags while entity IDs use the underscore to join words instead. Oct 19, 2021 at 18:39
1

Your command with the new syntax is:

/execute at @e[type=armor_stand,tag=Spawn] /spawnpoint @r ~ ~ ~

But why?

First, let's break this down into two separate commands, effectively allowing us to narrow our focus and understand how each works individually, with respect to the entire command, of course. Finally, after we understand both commands, we'll turn our attention to the target selectors being utilized so we can understand how they work in the grand scheme of things.

The spawnpoint Command

The spawnpoint command uses the following syntax:

/spawnpoint [targets] [pos]

This command enables you to reset the spawn point for a player to a new location. Here targets is replaced with your target selector and pos is replaced with the three components of the positional vector representing the desired spawn location.

The execute Command

The execute command, with respect to the original command you published uses the syntax:

/execute <entity> <x> <y> <z> <command>

This syntax is only available in Minecraft Java Edition (PC/Mac) versions 1.11 and 1.12, and it enables you to execute a command on behalf of an entity. Here entity is replaced with your target selector, x, y, and z are the individual components of your positional vector, and command is the command you wish to execute; in your case, spawnpoint.

The new syntax for this command is:

/execute at <targets> <secondExecuteCommand>
The @r Target Selector

This target selector is used to select a random player in the game. In the first portion of your command, you're selecting a random armor stand with a tag of spawn; however, you need to use @e which selects entities (an armor_stand is not a player but it is an entity). In the second portion, you're simply selecting a random player.

What is this command doing?

Well, it executes the spawnpoint command, targeting a random player, on behalf of a randomly selected armor stand with a tag of spawn. The selected player's spawn point is set to the position of the selected armor stand.

Let's Upgrade!

So you'll notice that the positional components are missing in the new syntax and we get a new keyword as. The as actually simplifies the command and sets the positional components to the location of the entity the command is being executed from. Additionally, since the spawnpoint command hasn't changed syntax, it stays the same in your new command. To upgrade it, we remove the positional components from the execute command and add the as keyword:

/execute at @e[type=armor_stand,tag=Spawn] /spawnpoint @r ~ ~ ~
4
  • as doesn't set the positional componets, at does. @r selects a random player. not entity; If you want a random entity, you should do: @e[sort=random,limit=1]. Even tho in practice this may not make a difference, the theory of the command is wrong, as it doesn't guaranteed that every player has their spawnpoint set, it also doesn't leave any room for making the command more efficient.
    – BunnyMerz
    Oct 19, 2021 at 17:49
  • @BunnyMerz perhaps misleading phrasing then; when you execute as an entity it'll use the position of the entity. Additionally, I mention @r uses player, not entity, but you can select an armor_stand using it with type. Oct 19, 2021 at 17:52
  • Open your game. Try @r[type=zombie]. You will get "Type is not applicable here". Then try /execute as @e[type=minecraft:zombie] run particle minecraft:witch ~ ~ ~. The particle will spawn at you (considering you typed in chat, not a command block), not at the zombie.
    – BunnyMerz
    Oct 19, 2021 at 18:05
  • @BunnyMerz I opened the wrong version... :facepalm: Oct 19, 2021 at 18:07

Not the answer you're looking for? Browse other questions tagged .