Well, you can do this under the common events tab in the data base.
Use the conditional branch for when a weapon is equipped. Than set a conditional branch(called: ___ AP) and set it so that when the hero's AP is equal to a certain amount, he will learn a certain ability.
Than in the monster battles(im not sure if it works in common event), set it so that you gain AP depending on what attack you do(you can even set it to randomize between 2 numbers) and make it add to "___ AP"
It can than be reset for a new ability via con branch after an ability is set or if you switch weapons.
---
I hope this is what you mean. If it is, I will do a little demo with coding for you.