ID:148032
 
Can anyone tell me why the sell verb in this doesnt work? I test it, and click what i want to sell, but nothing happens.

obj/npcs/Merchant
icon='npcs.dmi'
icon_state="14"
density=1
contents = newlist(/obj/Knife,/obj/Short_Sword,/obj/Broad_Sword,/obj/Pedal_Staff,/obj/Mace)
verb/Buy()
set src in oview(2)
alert("Hello, I sell weapons, what can I get for you?")
usr.buying = 1
usr.buycontents = src.contents
verb/Sell()
set src in oview(2)
alert("What would you like to sell?")
usr.selling = 1
usr.sellcontents = usr.contents
Click()
usr.gold+=src.sellamount
usr-=src
del(src)
mob/proc/createobjs()
var/item = pick(typesof(/obj))
new item(usr)


obj/Knife
icon = 'items.dmi'
icon_state = "1"
cost=100
sellcost=50
DblClick()
if(src in usr.buycontents)
if(usr.gold <= src.cost)
usr << "You can't afford it!"
else
switch(alert("Are you sure you wish to buy the [src] for [src.cost] gold?","Buy?","Yes","No"))
if("Yes")
usr.gold -= src.cost
new /obj/weapons/Knife(usr)
if("No")
return
if(src in usr.sellcontents)
src.loc = usr.buyer
switch(alert("Would you like to sell the [src] for [src.sellcost]?","Sell?","Yes","No"))
if("Yes")
usr.gold+=src.sellcost
usr.contents -= src
if("No")
return
else
return 0
Click()
usr<<"<B>This weapon,s strength is 6."
usr<<"<B>This weapon costs [src.cost] gold."


Please help.
Here is the culprit:

contents = newlist(/obj/Knife,/obj/Short_Sword,/obj/Broad_Sword,/obj/ Pedal_Staff,/obj/Mace)


You are not creating objects and putting them into the seller here, you are simply making a list of datum types. You need to have something like this:

var/obj/Knife/K = new(src)
var/obj/Short_Sword/S = new(src)

etc.
In response to Skysaw
Im kinda a noob i dont quite understand...
Skysaw, look up newlist(). That bit is fine. (I didn't know about it either until I checked in the reference! =) )

Tetra41 wrote:
verb/Sell()
set src in oview(2)
alert("What would you like to sell?")
usr.selling = 1
usr.sellcontents = usr.contents
Click()
usr.gold+=src.sellamount
usr-=src
del(src)

Well, this won't work. The alert() will just display a message saying "What would you like to sell?", with one button (the OK button)!

That Click() thing you have there is completely messed up. You can't define a proc within another proc. Instead, give objs a Click() proc that sells the object if usr.selling==1. Don't forget to set selling=0 when the mob moves:

<code>mob/Move() .=..() src.selling=0 //If we move, disable the selling mode.</code>

There's no need for usr.sellcontents, you can use usr.contents just fine. So get rid of that Click() line, the line above it, AND the three lines below it. Then make the changes I suggested above.