this will take too long to try to do in GUI~Editor instructions for you, so hopefully you can figure out how to do this code stuff with the GUI~Editor's capabilities. If not, just ask, and, I or others, can help you.
you could add in some simple coding, to check if you got the item in your inventory, and then prevent you from buying it, if you do, to keep you from getting two of the same items in your inventory.
I don't know how you got your code set up, but hopefully you can take this general guideline, and apply it to your own code:
<command name="buy_command">
<pattern>buy #text#</pattern>
<script>
if (GetBoolean(game.pov.parent, "shop")) {
item=GetObject(text)
if (item=null) {
foreach (obj,ScopeVisibleNotHeldForRoom(game.pov.parent)) {
if (obj.alias=text) {
item=obj
} else {
msg ("Seemingly " + text + "isn't an item that you can buy.")
}
}
}
foreach (inv_obj,ScopeInventory()) {
if (not inv_obj.alias=item.alias) {
if (HasInt(item, "price")) {
if (item.price < game.pov.cash) {
msg ("You bought the " + item.alias +".")
item.take=true
item.scenery=false
item.parent=game.pov
game.pov.cash = game.pov.cash - item.price
} else {
msg ("Sorry, but you can't afford it.")
}
} else {
msg ("Sorry, but it's not for sale.")
}
} else {
msg ("You already have " + item.article +".")
}
}
} else {
msg ("You're not in a shop, so you can't buy anything.")
}
</script>
</command>
you'll need to add in all the needed attributes and stuff of course.
---------
P.S.
I'm working on a full code for what you wanted in your OP, but it's very extensive of what you ask, and will take me a very long time to complete, if I can even do so. I didn't realize how massive and complex a project it was at the time, so don't expect any code from me on it for quite a long while, if at all. Though, I'll try to work on it, as I've got the time to do so, but don't be waiting around for me, or you'll be waiting a very long time.