I usually spam the Scripting Help topics faster than this, the isUnderAttack() and isFighting() methods are a bit vague in my opinion and they aren't exacly what scripters expect, same for getInteracting() as when you stop interacting you are still in combat. There is, however, a more reliable method, namely Character#getCombatTime(). You will have to work with client cycles instead of raw time and instead verify for a given diference in client cycles since last hitsplat which determines if a given Character (don't forget Player extends Character, not only NPC). I know this works for ranged and melee which always yield a hitsplat onhit therefore updating the combat time of that Character instance. For magic however (range too if you want maximum accuracy), you can rely on the Projectiles class. If a projectile is sent from a Character, means that Character is definately attacking someone and their target is locked in combat.