ID:261418
 
I have tryed a few things to try and come up with a shopkeeper sell code but have had no luck. I have also searched for one in the Demos and stuff and could not find one. If somone could get me started I would really appreciate it. Thank you
obj
var
value//use this for sell prices

mob
shopkeeper
verb/sell()
var/obj/item = input("What do you want to sell?")in usr.contents
switch(alert("I will buy that for [item.value].",,"Sell","Don't sell"))
if("Sell")
usr.money += item.value//change this to fit your needs
del(item)
else
return


Hope that helps you get started.
My code is a bit long winded, but heres how I do mine:

    Halls/ClericHall1/ArmorShop_1_Counter
Entered()
if (usr.client)
Choice=""
usr.CanWalk=0
while(Choice <> "Exit")
Choice = input("Avaiable Armor:","Cleric's Armor Shop") in list("Cleric Shield for 2500GOLD","Exit")
if(Choice=="Cleric Shield for 2500GOLD")
if(usr.GOLD>=2500)
usr.GOLD-=2500
new/obj/Equipment/ClericShield(usr)
usr << alert("You purchase a Cleric Shield for 2500GOLD!")
else
usr << alert("You do not have enough GOLD!","Alert!")
usr.CanWalk=1


That's basically how you do it (i'm sure you could optimize that with lists, as I may do). CanWalk is a user var that, when set to 0, prevents the player from walking, which keeps them from cheating by going to an inn or something, then going out again with the inn box still there, thus letting them sleep when they need it... Just a few pointers ^_^ Let me know if you don't understand that code ;)