You could do this through events, without resorting to a script.
On the shopkeeper event, ask the player if they want to buy the sword for ? gold coins. Give them a yes/no choice. If they say yes, check that they have enough money, deduct the money, and give them the sword. Then set a self switch so the offer is not made again.
This means it isn't done through the normal shop processing, so you don't get the same screens. If you really want it to be done using the same shop screens, then I don't think it would be difficult to modify the shop processing script to handle it.