Jump to content

  • Curse Sites
Become a Premium Member! Help
Latest News Article

Command Blocks tutorial.

command blocks custom map

  • Please log in to reply
5 replies to this topic

#1

acialwip
    acialwip

    Out of the Water

  • Members
  • 2 posts

Posted 19 July 2013 - 06:20 PM

Hey guys, when I first got into building little custom maps on servers for people to go through and explore I realised how hard it was to move people from place to place easily and quickly. I then explored command blocks. If any of you out there are thinking of making a custom map then command blocks are a must so here's a tutorial about them.

Command Basics
@p = Closest Player
@a = All Players
@r = Random Player

Game Rules

commandBlockOutput - Enables/disables text output of command block commands to console.
doFireTick - Enables/disables fire spread.
doMobLoot - Enables/disables mob drops.
doMobSpawning - Enables/disables the spawning of mobs unless you want them to ex: eggs and mob spawners will still spawn mobs.
doTileDrops - Enables/disables blocks dropping items when broken (includes TNT destroying blocks)
keepInventory - Enables/disables keeping inventory on death.
mobGriefing - Enables/disables creepers, ghasts, and Wither blowing up blocks, endermen picking up blocks and zombies breaking doors.

Type /gamerule <GAMERULE> to change the selected game rule.

Scoreboard:

Display Slots:

list - Lists the players killcount in the (TAB) menu.
sidebar - Shows the players killcount on a scoreboard on the right side of the screen.
belowname - Lists the players killcount below their name label.

Criteria:

dummy - Score is only changed by commands, and not by game events such as death. This is useful for event flags, state mappings, and currencies.
deathCount - Counts the number of times a player has died.
playerKillCount - Counts how many PLAYER kills a player has obtained.
totalKillCount - Counts the TOTAL number of kills a player has obtained.
health - Counts how much health a player has left.

Arguments:

score_NAME=# - Maximum experience level for the player
score_NAME_min=# - Minimum experience level for the player

Targeting Arguments:

x=# - X-coordinate
y=# - Y-coordinate
z=# - Z-coordinate

r=# - Maximum search radius
rm=# - Minimum search radius
c=# - Number of players. If negative, uses players from the end of the list first. When outputting through a comparator, the signal strength is equal to the number of players it locates
team=? - Targets players in that specific team
m=# - Targets players in that specific gamemode
name=? - Checks for players with this name. Inserting an '!' before the name checks only for players who do not have this name

Example: /tp @p[r=10,team=Black,m=2] 23 64 53

This would cause the CLOSEST PLAYER (@p) on the BLACK TEAM (team=Black), within a 10 BLOCK RADIUS (r=10), and the ADVENTURE GAMEMODE (m=2) to be TELEPORTED (tp) to the coordinates 23 64 53.

In another situation: /tp @a[x=23,y=64,z=53,r=20,m=1,team=Black] 32 98 13

In this case, ALL PLAYERS (@a) on the BLACK TEAM (team=Black) within a 20 BLOCK RADIUS (r=20) of the coordinates 23 64 53 and in the GAMEMODE CREATIVE (m=1) would be TELEPORTED (tp) to the coordinates 32 98 13.

Other:

l=# - Maximum number of experience levels for the player
lm=# - Minimum number of experience levels for the player

Base Commands

List of commands for use on the Command Block:

/testfor ~ Tests if a player/s has a certain item, is in a certain area, or has a specific amount of Experience Orbs/Levels or Score.

/clear ~ Is used to clear a players inventory, or to remove ALL of one item.

/difficulty ~ Changes the difficulty to that of which is specified after the initial command.

/effect ~ Adds an certain effect to a player for a specified amount of time.

/enchant ~ Enchants the item the player/s is/are currently holding.

/gamemode ~ Changes the player/s to the specified gamemode.

/gamerule ~ Changes the gamerule specified to either true or false.

/give ~ Gives a player/s a certain item.

/say ~ Broadcasts the message displayed in the Command Block. Player arguements (@a,@p,@r) can be
used to display a name in the broadcast.

/scoreboard ~ Uses arguements from the Scoreboard.

/spawnpoint ~ Sets the spawnpoint at the current location. If followed by X Y Z coordinates, this will set the player/s at a certain block.

/time ~ Argument "set" (/time set) <number | day | night> .

/toggledownfall ~ Toggles rain/snow.

/tp @# x y z~ Teleports specified player/s to a set of X Y Z coordinates.

/weather <clear | rain | thunder> [seconds] ~ Used to change the weather, and set it's duration.

/xp <amount> [playername] ~ Gives the player/s a specified number of Experience Orbs.

/xp <amount>L [playername] ~ Gives the player/s a specified number of Experience Levels.

Broadcasting Messages across the world and to individuals
World Messages
Command Block: /say Message Here.

Broadcasts a world-wide message.

Player Messages
Command Block: /tell @p Message Here.

Sends the CLOSEST PLAYER (@p) a message.

Spawnpoint
As you probably know, using /spawnpoint makes a wide-based spawn.

Instead, use the command /spawnpoint x y z and it will pinpoint the spawn. If this doesn't work, run it through a command block on a loop.

Giving Items
Have the player hit a button.

Command Block: /give @p 267

This will give the CLOSEST (@p) player an IRON SWORD (267).

NOTE: Item ID and player variable will change based on your map.

Giving Potions
Command: /give @p 373 1 8259

This will give the CLOSEST PLAYER (@p) one POTION OF FIRE RESISTANCE (8259) lasting 8 minutes. The Potion ID is 373, but the Potion DV is always different.
As you can see, the ID comes first, then the quantity, then the DV.
The Potion DV list can be found here on the Minecraft Wiki!

Giving Enchanted Items
The player MUST be holding the item they are going to enchant. This means selecting the first FREE slot on their equipment bar.

Have the player hit a button.

Command Block One: /give @p 267

Gives the NEAREST PLAYER (@p) an IRON SWORD (267).

Command Block Two: /enchant @p 16 2

Enchants the item the nearest player is holding. In this case, it would give a sword Sharpness II enchantment.

To make sure the player CANNOT obtain ANOTHER enchanted item, have a piston cut off the curcuit by breaking a line of redstone.

More on Enchantments can be found here on the Minecraft Wiki!

Potion Effects
Using Nausea as an example.

This is easiest done if the player hits a button, or walks over a pressure plate.

Command Block One: /effect @p 9 30

This will cause the player to have NAUSEA (9) of 30 SECONDS (30).

More on Potion Effects can be found here on the Minecraft Wiki!

Teleportation To Set Coordinates
This is best done with a timed redstone clock, or some other mechanism depending on your purposes.

Command Block: /tp @p x y z

The variables coloured in Purple are the coordinates, and will be different for everyone.

Relative Teleportation
I'm not sure what this mechanism would be used for, but there'd sure be some way of implementing it into your map.

Command Block: /tp @p ~x ~y ~z

The variables coloured in Purple indicate how far the player will travel along each axis.

Example:

Command Block: /tp @p ~5 ~10 ~15

This command will TELEPORT (tp) the CLOSEST PLAYER (@p) 5 block along the X axis (sideways), 10 blocks along the Y axis (up/down) and 15 blocks along the Z axis (front/back).

Experience Shops
You can change the item by using a different Item ID. Google search it.

Lower Command Block: /give @p[lm=5] 267

This will give the nearest player an IRON SWORD (267) for a MINIMUM (lm) of 5 EXPERIENCE LEVELS (=5)

Upper Command Block: /xp -5L @p[lm=5]

This will SUBTRACT 5 EXPERIENCE LEVELS (-5L) from the nearest player, if that player has a MINIMUM (lm) of 5 EXPERIENCE LEVELS (=5).

When giving potions, you must use the command like this:

Command Block: /give @p[lm=5] 373 3 16373

This would give the CLOSEST PLAYER (@p) 3 (3) POTIONS (373) of INSTANT HEALTH (16373). The Potion ID comes first, then the amount, then the Potion value.

Scoreboard
This can be done as a regular command. Not compatible with Bukkit servers.

Type /scoreboard objectives add Points totalKillCount Points

Next, type /scoreboard objectives setdisplay sidebar Points

Note: The words coloured in Purple can be whatever you wish them to be, just make sure they are the same.

Now, when you kill something, or someone, your kill count will show on a sidebar to the right side of the screen.

The argument "sidebar" can be changed to any of the following:

list - Lists the players killcount in the (TAB) menu.
sidebar - Shows the players killcount on a scoreboard on the right side of the screen.
belowname - Lists the players killcount below their name label.

The argument "totalKillCount" can be changed to any of the following, depending on your purposes:

dummy - Score is only changed by commands, and not by game events such as death. This is useful for event flags, state mappings, and currencies.
deathCount - Counts the number of times a player has died.
playerKillCount - Counts how many PLAYER kills a player has obtained.
totalKillCount - Count the TOTAL number of kills a player has obtained.
health - Counts how much health a player has left.

Point Shops

Scoreboard must be in use for this to work!

Lower Command Block Command: /scoreboard players remove @p[score_Points_min=5] Points 5

This will SUBTRACT 5 POINTS (remove Points 5) from the CLOSEST PLAYER (@p) if the player has a MINIMUM (score_Points_min) of 5 Points.

Upper Command Block Command: /give @p[score_Points_min=5] 267

This will give the CLOSEST PLAYER (@p) an IRON SWORD (267) if the player has a MINIMUM (score_Points_min) of 5 Points.

How to make doors that cost experience levels to open
When making this, make sure you do not have any experience levels. Same goes for resetting the system.

THIS METHOD IS NOT YET PERFECTED, BUT IT DOES WORK FOR THE MOST PART.


Command Block One: /testfor @p[lm=5]

This will run a TEST (testfor) on the CLOSEST PLAYER (@p) to see if they have a MINIMUM LEVEL (lm) of 5 EXPERIENCE LEVELS.

Behind this command block, place a redstone comparator. If the player tests positive (meaning the player has a minimum of 5 xp levels) the command block will output a signal to the comparator. MAKE SURE THE COMPARATOR IS NOT IN SUBTRACTION MODE.

Have this comparator facing another command block.

Command Block Two (with this comparator): /tp @p[lm=5] x y z

If the player tests positive to what we did earlier, the player will be teleported to our coordinates and active a pressure plate. That pressure plate will activate a signal and do the following:
  • /xp -5L @p[lm=5]
Player has 5 EXPERIENCE LEVELS TAKEN FROM THEM (-5L) if player has a MINIMUM OF 5 LEVELS (lm=5)

2. /say Door Opened!

Broadcasts a message across the map telling all players that a door has been opened.

3. /tp @p x y z

This will teleport the CLOSEST PLAYER (@p) to the coordinates of your choice. I suggest teleporting the player to a block in front of the button.

Also, for the door, when the player teleports to the coordinates of the pressure plate, run a wire to an inverter to switch it off. This will deactivate a redstone torch, and make the pistons retract, releasing sand. This means the door has fallen, and is open. If you don't want to use sand, you can use an Iron door and wiring the pressure plate up to a T-Flip Flop, which will be wired up to the door.

Coming off the same line of redstone we were first using, make a new section.

Command Block One: /testfor @p[l=4]

This will run a TEST (testfor) to see if the player has a MAXIMUM (l) of 4 EXPERIENCE LEVELS. This means the player has 4 levels or LESS.

If the player tests positive to this test, he has tested negative to the other.

Now, to show the player he doesn't have enough xp, we will do the following:

Place down a redstone comparator branching off the command block, then place another command block in front of the comparator. Have it run this message:

/tell @p You do not have the required amount of funds to perform that action.

If this message appears, the player needs more XP to open the door.

The above can also be done with points from the scoreboard. Just change the @p[lm=5] to @p[score_Points_min] and the @p[l=4] to @p[score_Points=4]

"Rounds" System

Firstly, you want to run the following commands in order:

1. /scoreboard objectives add Rounds dummy Rounds:

2. /scoreboard objectives add showRounds dummy Rounds

3. /scoreboard objectives setdisplay sidebar showRounds

Posted ImagePosted Image




The comparator that extends off the hopper powers a command block running the command /scoreboard players add Rounds showRounds 1
This will add 1 Round to the scoreboard. I'd also suggest making another command block off the hopper run the command /say A new round has begun! to inform the player of a new round.

Set that up, link it to your map circuitry and enjoy!



Information gained from a few different sources mainly the minecraftforums sources.

Yours faithfully,

Acialwip

Register or log in to remove.

#2

SuperB15
    SuperB15

    Out of the Water

  • Members
  • 7 posts

Posted 01 December 2013 - 01:37 AM

Dear acialwip,
    I am trying to give people with a total kill amount of 5 a gold ingot, I have already created an objective called KillMoney that records total kills. What command would I use? Is it "/give @a[score_KillMoney=5] gold_ingot"

#3

deadbuilder1
  • Minecraft: Deadbuilder

Posted 01 December 2013 - 03:58 AM

Great tutorial dude.

#4

James9270
  • Location: United States of America
  • Minecraft: James9270

Posted 04 December 2013 - 05:12 AM

View PostSuperB15, on 01 December 2013 - 01:37 AM, said:

Dear acialwip,
I am trying to give people with a total kill amount of 5 a gold ingot, I have already created an objective called KillMoney that records total kills. What command would I use? Is it "/give @a[score_KillMoney=5] gold_ingot"
Change your already existing command to "/give @a[score_KillMoney_min=5] gold_ingot", but you need more than just that, have a redstone clock set up to a command block with that command, and have a comparator facing outwards from that, into another command block that has the command: "/scoreboard players remove @a[score_KillMoney_min=5] 5" and that should work.

However this will make it reusable, if you want to make it only usable once than just ask.
"Everything is Mime-owned. The end of that unknown." -Windows speech recognition.

#5

FlazeOfAges
  • Minecraft: FireArceus64

Posted 21 December 2013 - 10:21 PM

Great run-down on command blocks and command block systems. :Diamond:
Posted Image

#6

CarbonCoach
  • Location: Bahrain
  • Minecraft: CarbonCoach

Posted 17 April 2014 - 02:29 PM

I bookmarked this page because I will definitely be coming back here to check up some commands. I'm a map builder and I usually get lost with command blocks but can you tell me if there is a method to not show any commands, like Giving <Player> 5 Golden_Apple because I want my maps to be decent and more official! :)

Check my topics out if you like ice cream.

I make fun maps and texture packs!