bossbar add cadeyrn {"text":"Cadeyrn the Wretched fallen knight of Vortigryn al Mahgin The Blood Forsaken","color":"#FF9D0A"}
bossbar set minecraft:cadeyrn color red
bossbar set minecraft:cadeyrn players @a[tag=CadeyrnFightTag]

bossbar set minecraft:cadeyrn players @a[tag=aaaaaaaaaaaa]
bossbar set minecraft:cadeyrn players @a[tag=CadeyrnFightTag]


#reset the maxhp scoreboard
scoreboard players set @s CadeyrnMaxHP 900

#take cadeyrn's damage taken since last check
execute as @s store result score @s CadeyrnCurrentHP run data get entity @s Health 1
scoreboard players operation @s CadeyrnMaxHP -= @s CadeyrnCurrentHP
scoreboard players operation @s CadeyrnDamTaken = @s CadeyrnMaxHP

#take the horse's damage and add it to cadeyrn's damage taken
execute as @e[tag=CadeyrnTP,type=skeleton_horse] run function zzzzdonotuse:cadeyrn/gethorsedamage

#subtract the bossbar's health by Cadeyrn's damage taken since last check
scoreboard players operation @s CadeyrnBossBarHP -= @s CadeyrnDamTaken
execute store result bossbar minecraft:cadeyrn value run scoreboard players get @s CadeyrnBossBarHP

#heal cadeyrn
data merge entity @s {Health:900f}