I don't believe it's possible to check all those conditions. I think it's the same problem as shred that you can't detect if you're behind the target.
I would suggest something like the following:
Code:
/run n = UnitName("target"); if n ~= _G["disarmTarget"] then _G["disarmTarget"] = n; _G["disarmAble"] = 0; c = UnitCreatureType("target"); if c=="Humanoid" or c=="Demon" then _G["disarmTry"] = 1 else _G["disarmTry"] = 0 end; end
/run if UnitName("target") == _G["disarmTarget"] and (UnitDebuff("target", "Dismantle") or UnitDebuff("target", "Disarm")) then _G["disarmAble"] = 1 end
/run if GetSpellCooldown("Dismantle")==0 and IsUsableSpell("Dismantle") and (_G["disarmAble"]==1 OR _G["disarmTry"]==1) and not (UnitDebuff("target", "Dismantle") or UnitDebuff("target", "Disarm")) then CastSpellByName("Dismantle"); _G["disarmTry"] = 0; end
/run if UnitName("target") == _G["disarmTarget"] and (UnitDebuff("target", "Dismantle") or UnitDebuff("target", "Disarm")) then _G["disarmAble"] = 1 end
So basically this works with 3 global variables to keep track of whether or not the mob can be disarmed.
Lines are like this:
1) If we have a new target (because our target is not disarmTarget), then reset all of the variables. We assume it cannot be disarmed (disarmAble = 0). If it's Humanoid or Demon, we set flag so we'll attempt to disarm (disarmTry = 1).
2) If we're still targetting disarmTarget and that target has either a Disarm or a Dismantle debuff (from us or someone else), we now know they can be disarmed...so set disarmAble = 1.
3) If Dismantle is ready, then we try to use it if either we know it can be disarmed (disarmAble==1) or we still need to try (disarmTry==1). It also checks it's not currently disarmed.
So basically if you or any other rogue/warrior dismantles/disarms your target, it will detect that and know it can. If not, you will try once anyway because of the disarmTry. If your dismantle is successful, it will trigger your own flag. So you will only try to dismantle something once. It will reset if you switch targets though which is unfortunate in some situations. With an addon you could save a list of creatures that can be successfully disarmed.