ID:155167
 
Hi again. I thought while I'm here, I could ask for help with this problem. I have a basic merchant who sells me items from his list. It's the same merchant from 'RPG starter'. I want to know if there is a way to put prices inside this list or alert the user of the price before they buy the item. Heres the code:

Edit: Also if someone can tell me how to get rid of the underscore in the output screen for the items, I would greatly appreciate it.
    Merchant
icon_state="merchant"
verb
Shop()

set src in oview(0)

var/list/ItemList=list( // [Item] = [Price]
"Health_Potion"=5,
"Iron_Dagger"=10,
"Iron_Short_Sword"=15,
"Leather_Breast_Plate"=15,
"Nothing"=0
)

var/Item2Buy=input("What would you like to buy?","Merchant's Items",) as anything in ItemList
var/Price=ItemList[Item2Buy]
if(Price) //if it has no price you cant buy it!
if(usr.Gold<Price)
usr<<"You need [ItemList[Item2Buy]] gold! You only have [usr.Gold]!"
else
usr<<"You Buy a [Item2Buy] for [ItemList[Item2Buy]] Gold"
var/obj/NewItem="/obj/Items/[Item2Buy]" //note: this only sells items of the obj/Items/ path
NewItem=new NewItem //creates the actual object
usr.contents+=NewItem;usr.Items+=NewItem //add it to both their contents and Items list
usr.Gold-=Price
usr<<"Please come again!"
Anything in a text string (AKA in double " " quotes) doesn't need an underscore. It takes what you type literally, and will display the underscore as an underscore. So, just replace it with a space. As for the prices, I would recommend making a variable attached to the items that contains their price.

usr<<"You Buy a [Item2Buy] for [Item2Buy.price] Gold"

For this to work, get rid of the variable that defines "Price" in the code.
Be sure to assign the price variable to each obj wherever it is in the code. So for example:
obj/var
price = 1 //the default price of everything is 1, so nothing comes free ;D
obj/item/Health_Potion
price = 5

//also at this part
if(usr.Gold<Price)
usr<<"You need [ItemList[Item2Buy]] gold! You only have [usr.Gold]!"
//change [ItemList[Item2Buy]] into [Item2Buy.price]