Detecting if players totem was triggered by a mob hit

execute as @a at @s store result score @s hurtbytimestamp run data get entity @s HurtByTimestamp execute as @a at @s store result score @s hurttime run data get entity @s HurtTime execute as @a unless score @s lasthurtbytimestamp matches 0.. run scoreboard players set @s lasthurtbytimestamp 0 execute as @a if score @s lasthurtbytimestamp > @s hurtbytimestamp run scoreboard players set @s lasthurtbytimestamp 0 execute as @a if score @s lasthurtbytimestamp < @s hurtbytimestamp as @a unless score @s hurttime matches 0 run scoreboard players set @s recentlyhit 1 execute as @a if score @s lasthurtbytimestamp < @s hurtbytimestamp as @a if score @s hurttime matches 0 run scoreboard players operation @s lasthurtbytimestamp = @s hurtbytimestamp execute as @a if score @s lasthurtbytimestamp = @s hurtbytimestamp run scoreboard players set @s recentlyhit 0 is what i came up with but it seems like the totem is activated before recently hit is updated so im kind of stuck if this idea can be edited or if theres another method entirely
Continue to help post