ID:146480
 
Code:
mob/npc/buying_npc
icon = 'buying-npcs.dmi'
density = 1
maxHealth = 100000
health = 100000
defense = 2
strength = 4
name = "Dealer"
exp = 15
verb/shop() //this verb still needs a lot of work, get the items in a list to make it easier
set src in view(1)
usr << "You enter the shop."
var/choice = input(usr,"Select your deal type?","Shop") in list ("Buy","Sell","Leave")
if(choice == "Buy")
var/buying_choice = input(usr,"What would you like to buy?","Shop") in list ("Sword","Shield","Nothing")
if(buying_choice == "Sword")
var/item_and_cost = input(usr,"This item cost 30 gold, will you still buy it?","Shop") in list ("Yes","No")
if(item_and_cost == "Yes" && usr.gold >= 30)
usr.gold -= 30
usr.contents += new /obj/Sword
//missing the shield
if(item_and_cost == "No")
usr << "You decide to buy nothing."
return
if(buying_choice == "Nothing")
usr << "You decide to buy nothing."
return
//there is still more, the shied, you need to find out how to make the items in a list
if(choice == "Sell")
var/selling_choice = input(usr,"What would you like to sell?","Shop") in list (src in usr.contents,"Nothing")
if(selling_choice == src in usr.contents)
var/next_selling_choice = input(usr,"Will you sell this for [src.selling_gold]?") in list ("Yes","No")
if(next_selling_choice == "Yes" && usr.gold >= src.selling_gold)
usr.gold -= src.selling_gold
usr.contents += src
else
usr << "You do not have enough gold."
return
if(next_selling_choice == "No")
var/next_choice = input(usr,"Would you like to leave the shop?","Shop") in list ("Yes","No")
if(next_choice == "Yes")
usr << "You leave the shop."
return
if(selling_choice == "Nothing")
usr << "You decide not to sell."
return
if(choice == "Leave")
usr << "You leave the shop."
return


Problem description:Ok, now the problem with this code is that at the buying part, where it shows the choices "Sword","Shield", I want it so I can have a list of the items that are available (I don't care, as long as it is a better way to store items), that way I can use src and if usr.gold >= src.gold then they can buy it. Also, at the selling part, I need it to list the usr.contents some kinda way or show what they have in their contents available to sell (any object). I've tried a few things.

mob/npc/buying_npc
icon = 'buying-npcs.dmi'
density = 1
maxHealth = 100000
health = 100000
defense = 2
strength = 4
name = "Dealer"
exp = 15
New()
src.contents += new /obj/sword
src.contetns += new /obj/shield
verb/shop() //this verb still needs a lot of work, get the items in a list to make it easier
set src in oview(1)
usr << "You enter the shop."
var/choice = input(usr,"Select your deal type?","Shop") in list("Buy","Sell","Leave")
switch(choice)
if(choice == "Buy")
var/obj/buying_choice = input(usr,"What would you like to buy?","Shop") in src.contents
var/item_and_cost = input(usr,"This item cost [buying_choice.cost] gold, will you still buy it?","Shop") in list ("Yes","No")
if(item_and_cost == "Yes")
if(usr.gold >= buying_choice.cost)
usr.gold -= buying_choice.cost
buying_choice.Move(usr)
//missing the shield
if(item_and_cost == "No")
usr << "You decide to buy nothing."
return
//there is still more, the shied, you need to find out how to make the items in a list
if(choice == "Sell")
var/obj/item = input(usr,"What would you like to sell?","Shop") in usr.contents
var/next_selling_choice = input(usr,"Will you sell this for [item.selling_gold]?") in list ("Yes","No")
switch(next_selling_choice)
if(next_selling_choice == "Yes")
if(usr.gold >= item.selling_gold)
usr.gold -= item.selling_gold
item.Move(src)
else
usr << "You do not have enough gold."
return
if(next_selling_choice == "No")
var/next_choice = input(usr,"Would you like to leave the shop?","Shop") in list ("Yes","No")
switch(next_choice)
if(next_choice == "Yes")
usr << "You leave the shop."
return
if(choice == "Leave")
usr << "You leave the shop."
return

I think this may be what you want...
In response to XxDragonFlarexX
Hey man, thanks o.o. This really helped me out.
In response to DragonMasterGod
mob/npc/buying_npc
icon = 'buying-npcs.dmi'
density = 1
maxHealth = 100000
health = 100000
defense = 2
strength = 4
name = "Dealer"
exp = 15
New()
src.contents += new /obj/Sword //we could chage this to a typesof(/obj/Weapons), but make 1
src.contents += new /obj/Shield
verb/shop()
set src in view(1)
usr << "You enter the shop."
var/choice = input(usr,"Select your deal type?","Shop") in list ("Buy","Sell","Leave")
if(choice == "Buy")
var/obj/buying_choice = input(usr,"What would you like to buy?","Shop") in src.contents
var/item_and_cost = input(usr,"This item cost [buying_choice.cost] gold, will you still buy it?","Shop") in list ("Yes","No")
if(item_and_cost == "Yes" && usr.gold >= buying_choice.cost)
usr.gold -= buying_choice.cost
usr.contents += buying_choice
usr << "You bought [buying_choice]."
usr.has_items += 1
else
if(item_and_cost == "Yes" && usr.gold <= buying_choice.cost)
usr << "You do not have enough gold to buy this item."
return
if(item_and_cost == "No")
usr << "You decide to buy nothing."
return
if(buying_choice == "Nothing")
usr << "You decide to buy nothing."
return
if(choice == "Sell" && usr.has_items == 0)
usr << "You don't even have any items to sell."
return
if(choice == "Sell" && usr.has_items != 0)
var/obj/selling_choice = input(usr,"What would you like to sell?","Shop") in usr.contents
var/next_selling_choice = input(usr,"Will you sell [selling_choice] for [selling_choice.selling_gold]?") in list ("Yes","No")
if(next_selling_choice == "Yes" && selling_choice.usage == "None")
usr.gold += selling_choice.selling_gold
usr.contents -= selling_choice
usr << "You sold [selling_choice] for [selling_choice.cost]."
usr.has_items -= 1
//else
if(next_selling_choice == "Yes" && selling_choice.usage == "Equip")
usr << "You can not sell an item that is equip remove it first."
return
if(next_selling_choice == "No")
var/next_choice = input(usr,"Would you like to leave the shop?","Shop") in list ("Yes","No")
if(next_choice == "Yes")
usr << "You leave the shop."
return
if(choice == "Leave")
usr << "You leave the shop."
return

Now the problem is that I need it so their are like 5,000,000 of the same item in the src.contents. I don't know how to multiply the factor.
In response to XxDragonFlarexX
Yea but now there is a problem that if you buy the item, the item is taken away fromt he src.contents. How could I make it so the item stays in the src.contents (or just someplace) while you get a new one?
In response to DragonMasterGod
Wouldn't it be better to add about 5 to his contents and make a restock proc?
In response to XxDragonFlarexX
Well, you could just have a little text list and a few if procs. That way, you need no restock proc and you have an unlimited supply of items.

Just have the if procs relate to the items you are reffering to using the text list.
mob/npc/buying_npc
icon = 'buying-npcs.dmi'
density = 1
maxHealth = 100000
health = 100000
defense = 2
strength = 4
name = "Dealer"
exp = 15
New()
src.contents += new /obj/Sword //we could chage this to a typesof(/obj/Weapons), but make 1
src.contents += new /obj/Shield
verb/shop()
set src in view(1)
usr << "You enter the shop."
var/choice = input(usr,"Select your deal type?","Shop") in list ("Buy","Sell","Leave")
if(choice == "Buy")
var/obj/buying_choice = input(usr,"What would you like to buy?","Shop") in src.contents
var/item_and_cost = input(usr,"This item cost [buying_choice.cost] gold, will you still buy it?","Shop") in list ("Yes","No")
if(item_and_cost == "Yes" && usr.gold >= buying_choice.cost)
usr.gold -= buying_choice.cost
usr.contents += new buying_choice.type
usr << "You bought [buying_choice]."
usr.has_items += 1
else
if(item_and_cost == "Yes" && usr.gold <= buying_choice.cost)
usr << "You do not have enough gold to buy this item."
return
if(item_and_cost == "No")
usr << "You decide to buy nothing."
return
if(buying_choice == "Nothing")
usr << "You decide to buy nothing."
return
if(choice == "Sell" && usr.has_items == 0)
usr << "You don't even have any items to sell."
return
if(choice == "Sell" && usr.has_items != 0)
var/obj/selling_choice = input(usr,"What would you like to sell?","Shop") in usr.contents
var/next_selling_choice = input(usr,"Will you sell [selling_choice] for [selling_choice.selling_gold]?") in list ("Yes","No")
if(next_selling_choice == "Yes" && selling_choice.usage == "None")
usr.gold += selling_choice.selling_gold
usr.contents -= selling_choice
usr << "You sold [selling_choice] for [selling_choice.cost]."
usr.has_items -= 1
//else
if(next_selling_choice == "Yes" && selling_choice.usage == "Equip")
usr << "You can not sell an item that is equip remove it first."
return
if(next_selling_choice == "No")
var/next_choice = input(usr,"Would you like to leave the shop?","Shop") in list ("Yes","No")
if(next_choice == "Yes")
usr << "You leave the shop."
return
if(choice == "Leave")
usr << "You leave the shop."
return


That should fix all problems, I think