Actions

Difference between revisions of "Using carrot on a sticks as triggers"

From Zedwiki

Line 37: Line 37:
  
 
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.
 
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."]}}}}'''
 
'''{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.
 
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.
+
The second command is the same as the first command with Mage swapped for Tank, the second class in this example.
 +
 
 +
The third command, which adds the MagicWand tag to players holding a carrot on a stick with the lore "This is a magic wand!", does not depend on the tag AbilityCooldown or the players class tag and so can be used at any time, unlike the other two which will be on a cooldown.
 +
 
 +
With those 3 commands we can now tag players who right clicked thier carrot on a stick, and detect which kind of stick they used and what class tag they have. Now, with a number of players tagged to identify which thing should be done to them, the effects of the abilities can be made.
 +
 
 +
===Reset the objective===
 +
Before we do anything else it is important to set the objective UseStick for all players back to zero, as otherwise thier stick will only work once which would be a bit rubbish. We do this using the following command.
 +
 
 +
 
 +
'''/scoreboard players set @a[score_UseStick_min=1] UseStick 0'''
 +
 
 +
 
 +
===Mages Ability===
 +
The MageAbility tag marks players using thier class ability as a mage. In Dungeon Dash this summons an iron golem, as well as making lots of particles and sound effects. In this example we will just summon an iron golem, as the particles really are not that important. We will also announce use of thier ability in chat using say. This is done by executing on players with the MageAbility tag. Once thier ability is activated, a cooldown time is set and the MageAbility tag removed. Make sure to remove the MageAbility tag or you will constantly summon iron golems on anyone who uses the stick in a situation that is both embaressing and difficult to fix.
 +
 
 +
'''/execute @a[tag=MageAbility] ~ ~ ~ say I summoned a Rusty!'''
 +
 
 +
 
 +
'''/execute @a[tag=MageAbility] ~ ~ ~ /summon minecraft:villager_golem ~ ~ ~ {CustomName:Rusty}'''
 +
 
 +
 
 +
'''/scoreboard players set @a[tag=MageAbility] AbilityCooldown 400'''
 +
 
  
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.
+
'''/scoreboard players tag @a[tag=MageAbility] remove MageAbility'''

Revision as of 16:01, 14 July 2017

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 this example.

The third command, which adds the MagicWand tag to players holding a carrot on a stick with the lore "This is a magic wand!", does not depend on the tag AbilityCooldown or the players class tag and so can be used at any time, unlike the other two which will be on a cooldown.

With those 3 commands we can now tag players who right clicked thier carrot on a stick, and detect which kind of stick they used and what class tag they have. Now, with a number of players tagged to identify which thing should be done to them, the effects of the abilities can be made.

Reset the objective

Before we do anything else it is important to set the objective UseStick for all players back to zero, as otherwise thier stick will only work once which would be a bit rubbish. We do this using the following command.


/scoreboard players set @a[score_UseStick_min=1] UseStick 0


Mages Ability

The MageAbility tag marks players using thier class ability as a mage. In Dungeon Dash this summons an iron golem, as well as making lots of particles and sound effects. In this example we will just summon an iron golem, as the particles really are not that important. We will also announce use of thier ability in chat using say. This is done by executing on players with the MageAbility tag. Once thier ability is activated, a cooldown time is set and the MageAbility tag removed. Make sure to remove the MageAbility tag or you will constantly summon iron golems on anyone who uses the stick in a situation that is both embaressing and difficult to fix.

/execute @a[tag=MageAbility] ~ ~ ~ say I summoned a Rusty!


/execute @a[tag=MageAbility] ~ ~ ~ /summon minecraft:villager_golem ~ ~ ~ {CustomName:Rusty}


/scoreboard players set @a[tag=MageAbility] AbilityCooldown 400


/scoreboard players tag @a[tag=MageAbility] remove MageAbility