Sorry for the late reply.
This is something that this plugin does, but do keep in mind your action sequence might look a little wonky (crossbow shot in melee) if it's in the offhand, unless you add a bunch of logic to reposition the battler before a ranged hit.