Basic commands

Teleport, kill, say, execute


Here are some basic commands that can be called by command blocks. Also, many commands have modifiers attached to them that narrow the scope of the command. Commands that modify items and inventory, summon entities and modify the environment will be covered in later lessons. You can generally check the syntax of a command by typing it in the console.

There are several parts of a command that are used frequently. They are:

  • Target selector: It tells you which entity the command will target. They are:
    • @p: the nearest player
    • @e: all entities
    • @s: the entity activating the command
    • @a: all players
    • @r: A random player
    • The specific name of a player or named entity.
  • Target selector argument: This can follow a target selector to narrow the scope of the target. (Example: @e[r=7] would be all entities within 7 blocks.) Target selector arguments can be put together, separated by commas also. (Example: @e[r=7,type=zombie] would be all zombies within 7 blocks.) A ! after the equals sign means "not". (Example: @e[type=!player] would be all entities that are not players).
    • [r=X] all entities within a radius of X.
    • [type=X] all entities of type X.
    • [x=X,y=Y,z=Z] entity at coordinates X,Y,Z
    • [name=X] entity with the name X
  • Coordinates: The position in the world is often included in commands. They come in threes. An X, Y and Z coordinate. You can choose to show your current coordinates by selecting the option in settings. Coordinates come in two forms:
    • Absolute: the position on the map. (X Y Z)
    • Relative: the position on the map in relation to what is calling the command (~X ~Y ~Z) or (^X ^Y ^Z) relative to direction they are facing

Teleport

This video shows the /teleport command being called by command blocks in a space facility. You can download the map here.

The /teleport or /tp command allows you to move a player, monster or other entity to another location. The command is /tp followed by X Y Z coordinates to teleport to a location (/tp 3 34 -12), /tp followed by a target selector and coordinates (/tp @a ~ ~ ~), or /tp followed by two target selectors to transport entities to another entity (/tp @e @s). You can't teleport to more than one entity though.

Syntax:
/teleport X Y Z
/teleport [target selector[argument=value]] X Y Z
/teleport [target selector[argument1=value1] [target selector 2[argument2=value2]]

You can also add a true or false to prevent it from telporting you into a block.
You can also add "facing" with a target (either entity or coordinate) to set the direction after teleporting.

Here are some examples:

/tp @e[type=zombie] Jeff

/tp Jeff ~ ~100 ~


Kill

Some times you just need to kill some things. This command makes it easy. The command is just "kill" followed by a target. Be careful though because some objects such as minecarts and armor stands are actually considered entities.

Syntax: /kill [target selector[argument=value]]

Here's some examples of kill commands:

/kill @e[type=zombie]

/kill @a[r=5,x=12,y=-5,z=34]


Say and tell

The say command makes an entity say a phrase. The tell command has one entity whisper text to another entity. They are a great way to tell players what is happening when they activate a command block.

Syntax:
/say [target selector[argument=value]] [phrase]
/tell [target selector[argument=value]] [phrase]

Here's some examples:

/say You are all going to die.

/tell @a[r=20] I triggered a trap!


Execute

The execute command is one of the most important commands. It allows you to create more complex actions by having entities be the ones who execute the commands. A command block can't modify its own inventory or enchant its own weapons. It uses the /execute command to call the commands on entities (or in relation to their positions in some cases). The format is /execute followed by XYZ coordinates and then the command.

Syntax:
/execute [target selector[argument=value]] X Y Z [command]

Here's some examples:

/execute @e[type=!player] ~ ~ ~ say Hello!

/execute @a ~ ~5 ~ summon tnt



Previous lesson: Chaining blocks   |   Next lesson: Summoning entities


Copyright 2020, Peacemaker Media Empire.   |