Actions

Using carrot on a sticks as triggers

From Zedwiki

Revision as of 16:47, 14 July 2017 by Dax23333 (Talk | contribs)

Carrot on a sticks are often used as activators for tools in maps. The reason for this is that a scoreboard objective with the type stat.useItem.carrot_on_a_stick will increment whenever the item is right clicked, regardless of any kind of success condition as is common with other items. Blocks for example need to be placed, and food needs to be eaten. But the carrot on a stick becomes a right click detector with this objective set up, making it extremely useful.

This tutorial will cover the construction of a simplified version of the class ability system from dungeondash, which is far too unweildy to use as a useful tutorial. It will also feature the ability to have seperate carrot on a sticks that do different things depending on thier lore, creating vast numbers of possible uses for them in a single map. The dungeon dash class system is unfortunatly outdated, and the 1.12 addition of @s would help simplify some of the commands. Other aspects of it will likely be covered in future tutorials.

Commands

This tutorial uses 4 commands.

  • scoreboard (tagging, creating objectives, setting scores, testing scores)
  • execute
  • say
  • give

The Tutorial

Creating The Objective

Firstly we want to setup our objective to track players right clicking a carrot on a stick. There should only be one of these on the server, more are completly unnecessary.

/scoreboard objectives add UseStick stat.useItem.minecraft.carrot_on_a_stick


Set this objective to be displayed on the sidebar to see it working when you right click your carrot on a stick, then clear the sidebar.

/scoreboard objectives setdisplay sidebar UseStick to display our new objective.

/scoreboard objectives setdisplay sidebar to clear the sidebar.

Detecting Players Who Used The Stick

For our example system we are going to have two class abilities which depend on tags the players have, and a magic wand which does not. The carrot on a sticks for the class abilities are the same, but the magic wand is different. To do this we need 3 command blocks. The following commands should be in a chain together, with a repeat command block at the front.

/execute @a[score_UseStick_min=1,tag=!AbilityCooldown] ~ ~ ~ /scoreboard players tag @s[tag=MageClass] add MageAbility {SelectedItem:{id:"minecraft:carrot_on_a_stick",tag:{display:{Lore:["Right click to use your class ability."]}}}}


/execute @a[score_UseStick_min=1,tag=!AbilityCooldown] ~ ~ ~ /scoreboard players tag @s[tag=TankClass] add TankAbility {SelectedItem:{id:"minecraft:carrot_on_a_stick",tag:{display:{Lore:["Right click to use your class ability."]}}}}


/scoreboard players tag @a[score_UseStick_min=1] add MagicWand {SelectedItem:{id:"minecraft:carrot_on_a_stick",tag:{display:{Lore:["This is a magic wand!"]}}}}


The first command adds the MageAbility tag to players with the tag MageClass, a score in UseStick of 1 or more, and without the tag AbilityCooldown. The execute command is used so we can test for multiple tags at once, as selectors will not do this on thier own. For example, @e[tag=Apples,tag=Bananas] is equivilent to @e[tag=Bananas] as the later parts override the previos ones rather than combining with them in any useful way. At the end of the first command there is a data tag.

{SelectedItem:{id:"minecraft:carrot_on_a_stick",tag:{display:{Lore:["Right click to use your class ability."]}}}}

This is used to check the nbt data of the target of the scoreboard command, so that only players who match with get the tag. This data tag checks that thier selected item (main hand item) is a carrot on a stick with lore "Right click to use your class ability". This enables us to check for different lore on a different item to give another effect.

The second command is the same as the first command with Mage swapped for Tank, the second class in the example.

Notice the first two commands are the same except for @s[tag=MageClass] and adds the MageAbility tag in the first, but it is @s[tag=TankClass] and adds the TankAbility tag in the second.