ID:261593
 
Hi, i was wondering how can i make a shopkeeper sell more than one thing, i have it so that a bartender only sells beer, but i'd like him to be able to sell ale, beer and vodka. IF YOU KNOW HOW TO DO THIS PLEASE ANSWERE. So far the code i have for 1 item being selled is...





mob
Bartender
icon = 'bartender.dmi'
density = 1
verb
Talk_To_Bartender()
set src in oview(1)
switch(input("Hey mate, wana buy a nice cold beer?, only 50 gold.","Bartender",text)in list("Sure","Na, I don't drink."))
if("Sure")
if(usr.gold<=49)
alert("You can't afford another beer mate!")

if(usr.gold>=50)
usr.gold-=50
usr.contents += new/obj/beer
alert("You buy a beer.")
if("Na, I don't drink")
alert("Alright, come again some other time...")


obj/beer
icon = 'beer.dmi'
The Conjuror wrote:
Hi, i was wondering how can i make a shopkeeper sell more than one thing, i have it so that a bartender only sells beer, but i'd like him to be able to sell ale, beer and vodka. IF YOU KNOW HOW TO DO THIS PLEASE ANSWERE. So far the code i have for 1 item being selled is...

The code is a little screwy, but your input() approach is perfectly extensible for this kind of thing.
However, a much better approach appears in my BYONDscape article on associative lists; you'll find it in the archives, as free content.

Lummox JR
In response to Lummox JR
heres how i do it, probably not what your goal is, though...

verb
sword()
set category = "Shop"
(does stuff like checking money + giving item)
shield()
set category = "Shop"
(does similar stuff)
magic_wand()
set category = "Shop"
(again, money check, gives item)

so every item in the shop is listed under "Shop" in the verb panel!
In response to Cybermattr
Cybermattr wrote:
heres how i do it, probably not what your goal is, though...

verb
sword()
set category = "Shop"
(does stuff like checking money + giving item)
shield()
set category = "Shop"
(does similar stuff)
magic_wand()
set category = "Shop"
(again, money check, gives item)

so every item in the shop is listed under "Shop" in the verb panel!

Here's another interesting way to do it:
mob
Stat()
var/mob/shopkeeper/SK=locate() in oview(1)
if(SK)
statpanel("Shop")
for(var/obj/O in SK.selling)
O.suffix="[SK.selling[O]] gold"
stat(O)

In this case, any /mob/shopkeeper will have a var/list/selling that's an associative list of all the items they sell.
The advantage of this approach is that the items don't have to be verbs. They can be the objects themselves, and all they have to do is respond to Click() and know that you're clicking them from a statpanel.
obj
Click()
if(loc && istype(loc,/mob/shopkeeper))
var/mob/shopkeeper/SK=loc
if(src in SK.selling) SK.Buy(src)

Lummox JR
In response to Lummox JR
i like that shop keeper idea, makes me think of MLAAS, what a great game.