Error_Dot_Exe

Sneak+Drop detection

Aug 20th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. Alright, in order to detect a player continuously sneaking, we're going to need two scoreboard objectives for this, a stat.sneakTime and a dummy objective:
  2. /scoreboard objectives add SneakTime stat.sneakTime
  3. /scoreboard objectives add Sneaking dummy
  4.  
  5. Now, run these commands in repeating and chain command blocks, or any other method you could use to constantly run a command:
  6. /scoreboard players set @a[score_SneakTime=1,score_SneakTime_min=1] SneakTime 4
  7. /scoreboard players remove @a[score_SneakTime_min=2] SneakTime 2
  8. /scoreboard players set @a[score_SneakTime_min=1] Sneaking 4
  9. /scoreboard players remove @a[score_Sneaking_min=1] Sneaking 1
  10.  
  11. To detect someone who is sneaking, use [score_Sneaking_min=1].
  12. The first two commands will reset the SneakTime objective to 0 after a few ticks so it doesn't stay above 1 even if the target stopped sneaking. The last two commands will use the Sneaking objective to give someone that is sneaking a consistent score of min=1. If you were to use the SneakTime objective instead, you wouldn't be able to test for someone consistently sneaking since it will reset back to 0 every few ticks, even if the target is sneaking.
  13.  
  14.  
  15.  
  16. To detect someone dropping the item, we will only need one objective:
  17. /scoreboard objectives add Drop stat.drop
  18.  
  19. Then, once more, run these commands constantly:
  20. /scoreboard players set @a[score_Drop=1,score_Drop_min=1] Drop 4
  21. /scoreboard players remove @a[score_Drop_min=2] Drop 2
  22. Just like with the SneakTime objective, these two commands will make sure the Drop objective gets reset back to 0 after a few ticks so it doesn't stay above 1.
  23.  
  24.  
  25. Now to detect someone dropping an item and sneaking simultaniously, use the following selector:
  26. @a[score_Sneaking_min=1,score_Drop_min=2]
  27.  
  28. And that's all there is to that.
  29. Here's some additional information about detecting when a player drops a custom item whilst sneaking;
  30. What I like to do is give the specific item a dummy objective score of 1, then use that item to give the target who dropped the item whilst sneaking also a dummy score. So this means we'd need two scoreboard objectives:
  31. /scoreboard objectives add CustomItem dummy
  32. /scoreboard objectives add Toggle dummy
  33. For this example we'll use a purple dye called 'Test'. The /give command for this would be:
  34. /give @p minecraft:dye 1 5 {display:{Name:"Test"}}
  35. And then run these commands consistently:
  36. /execute @a[score_Sneaking_min=1,score_Drop_min=2] ~ ~ ~ scoreboard players set @e[type=item,r=4] CustomItem 1 {Item:{id:"minecraft:dye",Damage:5s,tag:{display:{Name:"Test"}}}}
  37. /execute @e[score_CustomItem_min=1] ~ ~ ~ scoreboard players add @p[score_Sneaking_min=1,score_Drop_min=1] Toggle 1
  38. /entitydata @e[score_CustomItem_min=1] {PickupDelay:0}
  39. The first command will detect the item itself, and the second command uses that item to add a Toggle score of 1 to the target who dropped the item while sneaking. The last command simply lets you pick the item back up instantly.
  40. Now, everytime someone drops the Test item while sneaking, their Toggle score will increase with one. Ofcourse, this was an example. You can use this mechanism in any way that you want.
  41.  
  42. TL;DR:
  43. Add these scoreboard objectives:
  44. /scoreboard objectives add SneakTime stat.sneakTime
  45. /scoreboard objectives add Sneaking dummy
  46. /scoreboard objectives add Drop stat.drop
  47. Run these commands:
  48. /scoreboard players set @a[score_SneakTime=1,score_SneakTime_min=1] SneakTime 4
  49. /scoreboard players remove @a[score_SneakTime_min=2] SneakTime 2
  50. /scoreboard players set @a[score_SneakTime_min=1] Sneaking 4
  51. /scoreboard players remove @a[score_Sneaking_min=1] Sneaking 1
  52. /scoreboard players set @a[score_Drop=1,score_Drop_min=1] Drop 4
  53. /scoreboard players remove @a[score_Drop_min=2] Drop 2
  54. Then use @a[score_Sneaking_min=1,score_Drop_min=2] as the selector.
Add Comment
Please, Sign In to add comment