OK, I got my simple melee/ranged switching script to work, not by referring to the weapons themselves, or their role (melee/ranged) but rather the slot which they occupy. So to get the throwing axe in slot0 to work right I did:
SelectWeaponAbility(SLOT_WEAPON0,RANGED)
and it works now.
Hooray, I win the special olympics scripter's medal, right!
No, but seriously, this behavior would be useful in monsters too. I know not all have ranged weapons, but in the case of my script, if I don't have a ranged weapon in a slot it just attacks with what I do have, so at worst the monsters will do what they do now.
I also noticed that Xyx's scripts don't have deterministic reactions to certain situations (for example, a kobold might melee but every few seconds there is a chance it will flee.) This sort if indeterminacy alone, it it were implemented more globally, would make cheesy combat more difficult. For example, there should always be a 20% chance that a monster will not Attack(NearestEnemy) but instead change to Attack(SecondNearestEnemy), or, maybe even better, Attack(MostDamagedEnemy) (I know that's not a command).
I also think it should not attack, or at least be less likely to attack, party members who are not targetting it or one of its friends. This way it wouldn't chase after decoys. About the problem of changing its mind too quickly about whom to attack, maybe the right command is
AttackReevaluate(LastAttackerOf(Myself),30)
This means, if I understand it right, that it would attack whomever filled that condition for 30 seconds. Well, I can already see problems with this, but hey, what do you expect from a guy who taught himself scripting yesterday?
By the way, Xyx, it's all because of some of the stuff you posted that I started messing around with scripts in the first place! You and your smart Beholders!