I'm pretty sure that already exists... It would be done by using Conditional Branches, checking how much is in the coin case, and comparing it to the Pokémon/TM you are buying, so yeah, it would be done VIA long conditional branches, then using pbAddPokemon(PBSPecies::PORYGON,20) to the branch that allows the buying of a Pokémon, then use the script to reduce the amount of coins owned by how much the Pokémon is worth and same for TM's.
For each different branch you will want a check, the only other thing you could use is 1 check at the beggining of the event to check how much is owned, then show choices depending on the players coins... You will probably want to use <= and >= if it's this route you take, and not specifics like ==.
I have a lot of ideas for this, but with the basics, you can use your imagination, or just keep it like it is (there is nothing wrong with the way it is now or the way it was then).
I would however, use the Essentials built in choices menu as that can hold more than 4 choices, so the list of Pokémon you can buy will be endless, so to speak.
I can't give you the code for the coin case because I don't use this in my game, but, I'm pretty sure it should either be on the Wiki or part of the Essentials untouched kit.
Good luck and let us know how it turns out or if you need more help.