ID:178009
 
Okay here is my dilema I can create a code where a verb is connected to the shopkeeper. But the only way i can do it is to have the verbs "buy item 1" "buy item 2" etc.

What i want is a dialouge box to come up and list all the items i can buy. I would also like a dialogue box come up where it shows all the items you have and you can sell them for different values.

Any help would be great! thanks!:)
I have made a demo for it.. way before you asked.but i needa upload it to the hub(Which is not working!)
obj
items //sub-datum for items
var
value//var only used for objects under /obj/item
itemone
value = 100//worth 100

itemtwo
value = 40//worth 40

//now for the shopkeeper

mob
shopkeeper
icon = 'shopkeeper.dmi'

verb

buy()//to buy things
switch(input("What do you want to buy?")in list("Item one","Item two","Cancel"))//popup dialoge that asks if you want to buy Item one, or Item two.
if("Item one")//if Item one is selected
new/obj/items/itemone(usr)//creates a new item in usr's contents
if("Item two")
new/obj/items/itemtwo(usr)
if("Cancel")
return//stops the proc/verb

sell()//to sell items, this one is a bit more complex
var/obj/items/selling = input("What do you want to sell?")in usr.contents
if(!istype(selling,/obj/items))
return
else
usr.cash += selling.value
usr.contents.Remove(selling)

mob
var
cash = 20//20 cash


This isn't tested and it's 3:30 AM, so if it doesn't work, sorry.


In response to Nadrew
obj/Object2
icon = 'obj.dmi'
icon_state = "obj2"
sellamount = 30
verb
get()
set src in oview(1)
src.Move(usr)
drop()
src.Move(usr.loc)

obj/Object1
icon = 'obj.dmi'
icon_state = "obj1"
sellamount = 30
verb
get()
set src in oview(1)
src.Move(usr)
drop()
src.Move(usr.loc)

mob/var/gold = 100

mob/Stat()
stat("Gold: [usr.gold]")
statpanel("Items",usr.contents)
obj
var
sellamount = 0

mob/shopkeeper
icon = 'shopkeeper.dmi'
verb
Sell(var/obj/obj in usr)
set src in view(1)
switch(alert(usr,"Do you wanna sell [obj] for [obj.sellamount] Gold?"," ","Yes","No"))
if("Yes")
usr.gold += obj.sellamount
del obj
if("No")
usr <<"Fine."
Buy()
set src in view(1)
switch(alert(usr,"What do you wanna buy?"," ","object1","object2","nothing"))
if("object1")
if(usr.gold >= 50)
usr <<"You buy object1"
new/obj/Object1(usr)
usr.gold -= 50
else
usr <<"You need 50 gold"
if("object2")
if(usr.gold >= 50)
usr <<"You buy object2"
new/obj/Object2(usr)
usr.gold -= 50
else
usr <<"You need 50 gold"
usr <<"Fine."
if("nothing")
..()




Akarat wrote:
Okay here is my dilema I can create a code where a verb is connected to the shopkeeper. But the only way i can do it is to have the verbs "buy item 1" "buy item 2" etc.

What i want is a dialouge box to come up and list all the items i can buy. I would also like a dialogue box come up where it shows all the items you have and you can sell them for different values.

Ignore the previous examples; they're well-intentioned but a very bad way to go. Using switch() vs. an associative list means you'll have a lot of redundant code, and a lot more room for errors, without any flexibility.

To get you started on code to buy items, I recommend you check out my (free) BYONDscape article on associative lists, which includes complete code for a shopkeeper you can buy from.

http://www.byondscape.com/scape.dmb/content/000008/ index.html

Selling items is a slightly different matter, but by putting code in place for buying, you should be better able to figure it out.

Lummox JR