ID:144541
 
Code:shop
mob
weapon
Short_sword
name="short sword"
isweapon=1
equipped=0
var/obj/weapon/SS
Long_sword
name="long sword"
isweapon=1
equipped=0
var/obj/weapon/LS
helm
Leather_helm
name="Leather Helm"
ishelm=1
helm=1

Iron_helm
name="Iron Helm"
ishelm=1
helm=1
chest
Leather_chest
name="Leather Helm"
ischest=1
chest2=1

Iron_chest
name="Iron Helm"
ischest=1
chest2=1
legs
Leather_leggings
name="Leather Leggings"
islegs=1
legs2=1
Iron_leggings
name="Iron Leggings"
islegs=1
legs2=1
gloves
Leather_gloves
name="Leather Gloves"
islegs=1
legs2=1
Iron_gloves
name="Iron Gloves"
isgloves=1
gloves2=1
boots
Leather_boots
name="Leather Boots"
isboots=1
boots2=1
Iron_boots
name="Iron Boots"
isboots=1
boots2=1

mob
verb
Shop()
src<<"You browse the items for sale."
src.shop = input("Which item would you like to buy?.","Buy",src.shop) in list("short_sword - 50","long_sword - 100","leather_helm - 50","iron_helm - 100","leather_chest - 50","iron_chest - 100","leather_leggings - 50","iron_leggings - 100","leather_gloves - 50","iron_gloves - 100","leather_boots - 50","iron_boots - 100","Cancel")
if(src.shop=="short_sword - 50" && src.gold>=50)
src.gold-=50
src.contents+=SS
src<<"You buy a Short Sword."
return
if(src.shop=="long_sword - 100" && src.gold>=100)
src.gold-=50
src.contents+=LS
src<<"You buy a Long Sword."
return
if(src.shop=="leather_helm - 50" && src.gold>=50)
src.gold-=50
src.contents+=LH
src<<"You buy a Leather Helmet."
return
if(src.shop=="iron_helm - 100" && src.gold>=100)
src.gold-=50
src.contents+=IH
src<<"You buy a Iron Helmet."
return
if(src.shop=="leather_chest - 50" && src.gold>=50)
src.gold-=50
src.contents+=LC
src<<"You buy a Leather Chest peice."
return
if(src.shop=="iron_chest - 100" && src.gold>=100)
src.gold-=100
src.contents+=IC
src<<"You buy a Iron Chest peice."
return
if(src.shop=="leather_leggings - 50" && src.gold>=50)
src.gold-=50
src.contents+=LL
src<<"You buy Leather leggings."
return
if(src.shop=="iron_leggings - 100" && src.gold>=100)
src.gold-=100
src.contents+=IL
src<<"You buy Iron leggings."
return
if(src.shop=="leather_gloves - 50" && src.gold>=50)
src.gold-=50
src.contents+=LG
src<<"You buy Leather gloves."
return
if(src.shop=="iron_gloves - 100" && src.gold>=100)
src.gold-=100
src.contents+=IG
src<<"You buy Iron gloves."
return
if(src.shop=="leather_boots - 50" && src.gold>=50)
src.gold-=50
src.contents+=LB
src<<"You buy Leather boots."
return
if(src.shop=="iron_boots - 100" && src.gold>=100)
src.gold-=100
src.contents+=IB
src<<"You buy Iron boots."
return
if(src.shop=="Cancel")
return

mob/var/short_sword=0
mob/var/long_sword=0
var/mob/weapon/SS = /mob/weapon/Short_sword
var/mob/weapon/LS = /mob/weapon/Long_sword
var/mob/helm/LH = /mob/helm/Leather_helm
var/mob/helm/IH = /mob/helm/Iron_helm
var/mob/chest/LC = /mob/chest/Leather_chest
var/mob/chest/IC = /mob/chest/Iron_chest
var/mob/legs/LL = /mob/legs/Leather_leggings
var/mob/legs/IL = /mob/legs/Iron_leggings
var/mob/gloves/LG = /mob/gloves/Leather_gloves
var/mob/gloves/IG = /mob/gloves/Iron_gloves
var/mob/boots/LB = /mob/boots/Leather_boots
var/mob/boots/IB = /mob/boots/Iron_boots


Problem description:You browse the items for sale.
runtime error: cannot append to list
proc name: Shop (/mob/verb/Shop)
usr: VolksBlade (/mob)
src: VolksBlade (/mob)
call stack:
VolksBlade (/mob): Shop()

when i try to buy something i have the money yet the error poped up.


It gives you that error because you can't add type paths (such as /mob/weapon/Short_sword) into the contents list. You probably want to create a new instance of the object, and add it to the player's inventory. In that case, you will have to use new to create the object.

However, your shopping system has many flaws. If you wanted to change the prices of a weapon, you would have to change the price in your shop code, change the text, and modify your conditions. A much easier and flexible way to do a shop system is to define a variable to the weapon, which is it's cost, and loop through a list of weapons that the players can buy. By using associative lists (having the weapon's name and price as the element, and the reference of the weapon as the association) you can easily make your shopping code much more flexible, dynamic, and robust.

I also see some potential flaws for your equipment system. Weapons shouldn't be mobs, as a starter, since they don't need to be controlled. (as in having a player move the weapon around) You have defined a variable for your weapon (equipped), which makes me think that you're relying on the weapon's variable to check if it's equipped. What you should be doing is defining a variable for your player that holds what weapon you have equipped. It is much safer and reliable to use this method instead of your own right now.
In response to Unknown Person
fist off the equipped var isnt really used, i intended to use it, then i just added vars for the left and right hand the head chest legs hands and feet, but i never got around to fixing it, anyways about the shop, id need an example (im a bit slowish and cant follow well).
In response to VolksBlade
In order to do this type of shop system, you'll have to familiarize yourself with associative lists. If you don't already know them, you can read Lummox JR's BYONDscape article about them. (http://www.byondscape.com/ascape.dmb/LummoxJR.2002-0103/)

First, you'll have to organize all of your items into one path type so you can define your item cost in that type of object (all weapons, armours, shields, etc will have a cost). A good straightforward name would be /obj/item.

obj/item
var/cost = 0
// insert your weapon/armour/shield/item types below


After that, you'll have to define a list for all the items that your shopkeeper will hold. If you intend shopping to be done anywhere without any shopkeepers, then you can define this list in a global scope (as a global variable). Otherwise, you can define this in list in a shopkeeper list if you want different shopkeepers to be able to sell different things. My example will show a 'global' shopkeeper system, the same of what you have.

var/list/shopitems = newlist(/obj/item/weapon/short_sword, /obj/item/armor/leather_shield, ...)


For your actual shopping function, you will have to build another list which will actually be your associative list. The associative list's basic outline will look like this:

var/list/data = list ( "<name_of_item> - <price> gold" = reference_of_item_being_sold, ... )

In order to build the list, you will have to loop through all the items in the 'shopitems' list, and add the information text. You will then have to associate the reference of the object to it.

var/list/data = list()
for(var/obj/item/I in shopitems)
data["[I.name] - [I.cost] gold"] = I
// this essentially adds the text, and associates it all in one statement


After you built the list, you'll have the player input what he or she wants to pick. In order to do this, you have to define a variable for what the player picks (the text representing the item), and the value associated to what the player picks (the item).

var/obj/item/picked_item
var/select = input(src, "What would you like to buy?") as null|anything in data
if(!select) return // exit out if the player pressed "Cancel"
picked_item = data[select] // grab the association from the data list


Now, you will have to check if the player has enough money to buy the item. In order to do so, you compare the player's money with the picked_item's cost.

if(picked_item.cost > src.gold)
src << "You don't have enough money to buy the [picked_item.name]!"


If the player has enough money, you will have to create a new instance of the object by looking at the picked_item's type. You will use new to create the instance.

else
src << "Thank you for your patronage."
src.gold -= picked_item.cost
new picked_item.type (src) // create a new instance of the item you want to buy, and place it in the player (src)'s contents (inventory


If you have any questions, feel free to ask.