You can create a lightning stick using these commands in a command block:
/testfor @e[type=Player] {SelectedItemSlot:0}
/execute @e[type=*InsertMobNameHere*] ~ ~ ~ summon LightningBolt ~ ~ ~
You can also create lightning arrows:
/execute @e[type=Arrow,c11] ~ ~ ~ summon LightningBolt
/kill @e[type=Arrow]
To receive a command block, you can type in the command chat:
/give @p minecraft:command_block 64
In the source there are couple functions that attempt to obtain a target: one that selects players first (and if it fails, falls back to the other function), and one that does not have a bias towards any type. Every command must choose which one to use when it has a selector.
However, player bias will only occur if the selector itself is @p
or @r
(without c
being changed) or the c
parameter is set to value of exactly "1". If so, the selector won't be processed yet and the command class itself will use one of those functions to process it. Otherwise, the selector is processed first with no bias and then the command is processed for each target found, being handed the already-obtained target (and not a selector to process).
Almost all /scoreboard
commands use the player bias function, except for /scoreboard players tag ...
and /scoreboard teams join ...
. The stored selector for CommandStats also uses it.
The only way to prevent it from targeting players is to exclude players from selection:
/execute @e[type=ArmorStand] ~ ~ ~ detect ~ ~-1 ~ stone 0 scoreboard players set @e[type=!Player,c=1] myObj 1
This does mean that if you want a nested /scoreboard
command or CommandStats to still target all entities including players, you'd have to create two copies: one for players and one for non-player entities:
/execute @e[type=!Player] ~ ~ ~ /scoreboard players set @e[type=!Player,c=1] OBJ 1
/execute @a ~ ~ ~ /scoreboard players set @a[c=1] OBJ 1
Or:
/stats entity @e[type=!Player] set SuccessCount @e[type=!Player,c=1] OBJ
/stats entity @a set SuccessCount @a[c=1] OBJ
Best Answer
I figured it out with the above linked post as a guide. Thanks Fabian and AMJ! Ok so I have bedrock edition 1.16.200 and as we know the code is different etc. I used command blocks for everything. I created a battle arena that once you press the button it summons enemies, teleports you in. Then once the enemies are dead you teleport out. The last part was very hard to figure out in BE.
Here is the info for anyone who wants to do the same thing. I won't go over teleporting you in and summoning enemies. That is pretty straight forward and can be found easily.
Steps: Create your world. Setup scoreboard like this using chat first.
/scoreboard objectives add entityCount dummy
Place command chain block at end of your summon/teleport chain with this code. It will start the whole checking for bad guys chain by placing a redstone block in front of the second set / chain of command blocks.
/setblock -14 4 12 redstone_block
Places a block to wherever you need it (replace numbers with your own of course.)The second chain set starts as follows: First block type REPEAT, UNCONDITIONAL, NEEDS REDSTONE, DELAY IN TICKS 20 (so it won't be spamming, just checking once per second)
/scoreboard players set count entityCount 0
Second block: CHAIN, CONDITIONAL, ALWAYS ACTIVE, 0 TICKS
/execute @e[type=!player] ~~~ scoreboard players add count entityCount 1
Important note! type=!player will also count arrows etc. So you might want to specify zombie, vex or whatever you have. I don't allow bows, block drops, enemy drops etc.Third block: CHAIN, UNCONDITIONAL, ALWAYS ACTIVE, 0 TICKS
/scoreboard players test count entityCount 0 0
This checks that the number it has counted has now reached a range of 0. Range of 0 to 0.Fourth block: CHAIN, CONDITIONAL, ALWAYS ACTIVE, 0 TICKS
/tp @p -24 5 9
Teleports you to whatever numbers you put in there.Fifth block: CONDITIONAL, ALWAYS ACTIVE, 0 TICKS
/setblock -14 4 12 air 0
Replaces that redstone block you placed earlier with air. This stops the chain hence ends the cycle. It will start again when you hit your button and it places the redstone block at the beginning again.Sixth block: CHAIN, CONDITIONAL ALWAYS ACTIVE, 0 TICKS
/say YOU WON! YOU KILLED THEM ALL!
This is optional. You can make it give you experience or food or start another round, or move you to a harder area, or summon a new harder set of bosses. The sky is the limit!I hope it helps everyone. It sure opened up my possibilities and the way I thought about the coding.