So what you're doing is:
> Finding the nearest yak
> checking if the chosen yak exists
> checking if the chosen yak isn't fighting
> checking if the chosen yak isn't under attack
what happens if it's fighting, or it's under attack? it will just wait/repeat cycle
INSTEAD,
you need to FILTER the yaks, and find the closest one which fits certain criteria: (the above conditions), and NOT find the closest yak, and check if it meets criteria
As for the two questions;
1. check if the npc's health is above 0, and to make it faster, use the filter I mentioned above
2. you need to check if your character is interacting or being interacted, if it is, don't attack