How can I make this monster only be able to get attacked by range/mage attacks.

Where if you have a melee weapon on, you cannot attack the monster.