I would say Kaen's suggested method would be more accurate.
Pets only get targets when they're engaged in combat. So if the pet has a target, then the pet is engaged. No need for a bool that you have to manually track, either the pet is or is not engaged.
Since you have a pet window, the information about the pets target is always available (Unlike another player or NPCs target).
Have a look see as some examples of the Pet TLO.
docs.macroquest.org
and here is the listed members of the Pet TLO.
docs.macroquest.org
Fair warning, I don't
Lua. Pretend this is in
Lua or something.
Code:
CombatRoutine() {
if (!Pet.Target.ID) {
/pet attack
}
//Other combat things here!
}
I believe
Lua is mq.TLO.Pet.Target.ID or something like that.
With that said, there is a ton of information on the TLOs, their members, and what data type they return. In this case it's Pet TLO, it has a member Target, which has a return type of spawn.
spawn will then have it's own members. Spawn is generic information available about spawns in the game. Things such as their ID, if they're current casting, their cleanname. Some things in the Spawn TLO are not always available, but that distinction isn't made in the docs. Things like MaxHPs for another NPC would be 100, because the most they can have is 100%. But if you do ${Me.MaxHPs} it would likely return the actual health number. Things like MaxMana have a note that says it only updates when targeted/grouped with the spawn. etc.
Tons and tons of information in the documentation that can lead you down at least knowing what information you have available to you. It's still up to you to understand how to use that information.