ID:172396
 
I have here a long standing problem for you guys now. The proverbial thorn in my side if you will.

This time I'm trying to use alerts for my shopkeepers, cutting some 10+- pages woth of code into less than 2. But I'm not really sure if this is the best way to do it or not.

If you would be so kind as to help me turn this.

   
Trading_Post
icon_state = "item"
DblClick()
var
weapons = input("What can i get for you today?","Items",) in list("Tonic","Fish Oil","Nothing")
switch(weapons)
if("Tonic")
var
confirm = input("Tonic, thats 30 gil please.","Confirmation",) in list("Yes","No")
switch(confirm)
if("Yes")
if(usr.gil<30)
usr << "Not enough gil."
else
usr.gil -= 30
usr.contents += new/obj/Item/Healing/Tonic
usr << "Enjoy your Tonic."
if("No")
usr << "Sorry thank you anyway."
if("Fish Oil")
var
confirm = input("Fish Oil, thats 60 gil please.","Confirmation",) in list("Yes","No")
switch(confirm)
if("Yes")
if(usr.gil<60)
usr << "Not enough gil."
else
usr.gil -= 60
usr.contents += new/obj/Item/Healing/Fish_Oil
usr << "Enjoy your Fish Oil."
if("No")
usr << "Sorry thank you anyway."
if("Nothing")
return
..()


Into something close to this.

        verb
Talk(mob/npc/n as mob in oview(2))
if(istype(n,/mob/npc/shop))
switch(alert("[n.shop]",,"buy","sell"))
if("buy")
var
a = input("What would you like?","Buying",) in n.stock
number = input("How many?","Buying") as num
var
value = a.value
var
total = (value*number)
alert("you want [number] [name](s) for [total] gil?",,"yes","no")
if("sell")
var
item = input("What would you like to sell?","Selling",) in usr.contents
if(istype(n,/mob/npc/town))
usr << n.speech



Or you could point out another way entirly. (How you spell that?) Or just call me a stupid n00b. But I sure would appriciate your help and so would the players.

Thank you.
Well, the way I did it before I started using browser popups and Topic() procs was similar to the following:
mob
Shop_Keeper
icon = 'Icons.dmi'
icon_state = "npcshopkeep"
density = 1
contents = list(new/obj/thing1,new/obj/thing2)
verb
Buy()
set src in oview(2)
if(length(usr.contents) >= usr.maxinven)
usr << "<b><font color=green>Your inventory is full."
return
var/A = input(usr,"What would you like to buy?","Shop Keeper") as null|anything in src.contents
if(!A) return
if(alert(usr,"The [A:name] costs $[A:cost]. Would you like to buy it?","Shop Keeper","Yes","No") == "Yes")
if(usr.money < A:cost)
usr << "<b><font color=green>You don't have enough money to buy this."
return
new A:type(usr)
usr.cash -= A:cost
else return
obj
thing1
icon='thing1.dmi'
cost = 10
thing2
icon='thing2.dmi'
cost = 15
In response to Enigmaster2002
Thanks, Ive been workin on that for around 6 months now. any who it works now, I appreciate it.
In response to Enigmaster2002
You should try to avoid using : whenever possible, in this case it should work as long as the items all have a cost variable. But based on the code you should just define A as being an obj and avoid using : altogether...

mob
Shop_Keeper
icon = 'Icons.dmi'
icon_state = "npcshopkeep"
density = 1
contents = list(new/obj/thing1,new/obj/thing2)
verb
Buy()
set src in oview(2)
if(length(usr.contents) >= usr.maxinven)
usr << "<b><font color=green>Your inventory is full."
return
var/obj/A = input(usr,"What would you like to buy?","Shop Keeper") as null|anything in src.contents
if(!A) return
if(alert(usr,"The [A.name] costs $[A.cost]. Would you like to buy it?","Shop Keeper","Yes","No") == "Yes")
if(usr.money < A.cost)
usr << "<b><font color=green>You don't have enough money to buy this."
return
new A.type(usr)
usr.cash -= A.cost
else return
obj
thing1
icon='thing1.dmi'
cost = 10
thing2
icon='thing2.dmi'
cost = 15
In response to Nick231
Well, in the case of the cost variable, I was planning on doing "var/cost = 10" in the objects themselves, but forgot once I got to it. And as for the "A:type", I never got it to work using a period.
In response to Enigmaster2002
To get it to work using a period you need to tell it what type it will be working with when you define the variable.

So instead of:

var/A and [A:cost]

You would do:

var/obj/A and [A.cost]

If cost was defined in obj/items, you would then have to do:

var/obj/items/A (and you would still use [A.cost]

This works for everything else (mobs, turfs, etc.)
In response to Nick231
Nick231 wrote:
To get it to work using a period you need to tell it what type it will be working with when you define the variable.

So instead of:

var/A and [A:cost]

You would do:

var/obj/A and [A.cost]

If cost was defined in obj/items, you would then have to do:

var/obj/items/A (and you would still use [A.cost]

This works for everything else (mobs, turfs, etc.)

And, to add onto what you just said. Make sure the object that you wish to manipulate is infact that type.