What you could do to test if you left-click the sword is have some mob (ex. an slime) that is made invisible, then teleported constantly to your head. For example, you could use this command:
summon Slime ~ ~1.4 ~ {NoAI:1,CustomName:"LeftClick",CustomNameVisible:0,Size:0,ActiveEffects:[{Id:14,Duration:1000000,Ambient:1}],Attributes:[{Name:generic.maxHealth,Base:1}]}
Basically, this command summons a Slime named LeftClick which is invisible and has half a heart of health. Then, you want to make a redstone clock attached to this command:
execute @p[score_IsHolding_min=1] ~ ~ ~ tp @e[name=LeftClick] ~ ~1.4 ~
This will constantly teleport that slime to your head. So, whenever you left click, you will hit the slime, which will add one to your InfinityBlade objective score count. Additionally, remember that you have to set up some sort of command to spawn a new LeftClick slime every time you left-click, since the previous one will be killed.
The only problem with this system is that you can't actually hit anything else with the sword, since the slime is constantly being teleported to you, so whenever you left-click, you hit the slime. Unfortunately, there's no way to get around this, so if this isn't what you want, you have to find another way to detect when you want to shoot a fireball.
However, if this idea works for you, you then have to be able to detect which way the player is facing to summon a fireball in that direction. To do this, you have to use an MCEdit filter called CPDirections. This video explains how to use the filter in great detail.
Hopefully I answered all of your questions.
You should use a dummy variable and target selector arguments.
Run once
Have a dummy score, call it healthDif
.
/scoreboard objectives add healthDif dummy
Run every tick, in order
Set each players healthDif
score to their own health score:
/execute @a ~ ~ ~ scoreboard players operation @a[c=1] healthDif = @a[c=1] health
Subtract the other player's healthDif
score from your own:
/execute @a ~ ~ ~ scoreboard players operation @a[c=1] healthDif -= @a[rm=0] health
Now players with a positive healthDif
score will have more health than the other player. Target with @a[score_healthDif=1]
Note this will only work for two players. In order for it to work with more, you have to take a few extra steps.
Run once
First you'll need a dummy variable to store miscellaneous variables. Call it vars
. Note: If you already have a variable for this (you likely do), you can skip this step.
/scoreboard objectives add vars dummy
Run every tick, in order
Put these between the two commands from before.
First, set the #nplayers
to 0:
/scoreboard players set #nplayers vars -1
Now, have each player increment #nplayers
:
/execute @a ~ ~ ~ scoreboard players add #nplayers vars 1
Finally, multiply each players healthDif
score by this number
/scoreboard players operation @a healthDif *= #nplayers vars
This way, you can have any amount of players, and the system automatically adapts!
Best Answer
You need a death Counter first
I recommend functions but you can use a repeat command block and a chain command block, too