Thanks to Firekings demo, i made a shopkeeper code.
Here's part of it:
mob
shopkeeper
verb
Buy()
set src in oview(1)
var/list/L = new
for(var/obj/O in src)
L += O
L += "Cancel"
var/obj/answer = input("Buy?","Buy") in L
if(answer == "Cancel")
alert("Good bye sir!","Bye")
return 0
if(usr.gold >= answer.price)
usr.gold -= answer.price
usr.contents += new answer.type
alert("THX!","Thanks!")
else
alert("Not enough gold!","Sorry")
mob/shopkeeper/Bill
icon = 'mob.dmi'
icon_state = "bill"
contents = newlist(\
/obj/sword/Blade)
It works, but all you see on the list are the names of the
items. I would like to add the price of each of these item
beside them. Something like a [src.price].
Any ideas ???
THX.
ID:179648
Nov 24 2001, 2:34 pm
|
|
In response to FIREking
|
|
There's this weird bug after putting that small code.
Each time i visit the shopkeeper, a new price tag appears. First time: Blade 95 Second time: Blade 95 95 Third: Blade 95 95 95 ... I'm pretty sure the code is at the right place. mob shopkeeper verb Buy() set src in oview(1) var/list/L = new for(var/obj/O in src) O.name = "[O.name] [O.price]" L += O L += "Cancel" ... Can you help me ? THX. |
In response to Cravens
|
|
Cravens wrote:
There's this weird bug after putting that small code. oops, lets put that in new mob shopkeeper New() for(var/obj/O in src) O.name = "[O.name] [O.price]" //rest of code here FIREking |
In response to FIREking
|
|
I tried putting a "Sell" option, but it's a bit complicated with your code.
I added a switch that works fine, but i'm stuck after. Here's what I have: mob shopkeeper New() for(var/obj/O in src) O.name = "[O.name]---[O.price] gold" verb Deal() //Changed Buy() with Deal() set src in oview(1) switch(input("Welcome!","Shop") in list ("Buy","Sell","Leave")) if ("Buy") //Buy code here (previous post). if ("Sell") //I need some help here !!! if ("Leave") alert("Please come again!","Bye") return 0 THX. |
In response to Cravens
|
|
Cravens wrote:
I tried putting a "Sell" option, but it's a bit complicated with your code.for(var/obj/O in usr) stuff += O stuff += "Cancel" var/answer = input("Sell?") in stuff if(answer == "Cancel") alert("Bye!") return 0 usr.gold += answer.price / 2 del(answer) alert("Thanks!") if ("Leave") |
In response to FIREking
|
|
I can sell now, but the selling prices still doesn't
appear. I added another code just like the first one you gave me: mob shopkeeper New() for(var/obj/O in src) O.name = "[O.name]---[O.price] gold" for(var/obj/O in usr) O.name = "[O.name]---[O.price / 2] gold" It compiles fine, but the prices aren't there. |
In response to Cravens
|
|
Cravens wrote:
I can sell now, but the selling prices still doesn't the reason why, is this all happens when the MOB is made, meaning there IS NO usr yet, so you will probaly have to call it in side the sell proc, but then again, you will run into the last problem you had where it keep showing the prices over and over, each time you came back. you are probably going to want to add a Look() verb to all your obj's, and it will simply tell its name, and its price, and other things if you wish. FIREking |
In response to Cravens
|
|
You could do what i do
mob verb buy switch(input("What do you want")in list("Gun 200") if("Gun 200") that works but it looks lame |
In response to Gouku
|
|
Gouku wrote:
You could do what i do um, we are FAR byond this.... the code ive given him allows to buy and sell ANY OBJECT IN THE GAME, WITHOUT switches. and its less than 40 lines or so |
In response to FIREking
|
|
I thought of doing that, and i guess i will.
I already have a Look(), so i'll add the selling price for each items. Thx for the rest. |
Cravens wrote:
It works, but all you see on the list are the names of the Having read through the responses so far on this thread, I really dislike FIREking's approach to editing the object list in the shopkeeper's New() proc. I think this is a much better way, that will also help with Sell(): mob/shopkeeper/verb Associative lists can be quite handy, as you see. Lummox JR |
In response to Lummox JR
|
|
i havent gotten that far with lists yet, which is why i didnt think of that!
FIREking |
In response to FIREking
|
|
FIREking wrote:
i havent gotten that far with lists yet, which is why i didnt think of that! Associative lists are definitely worth playing with. I find them extremely helpful at dealing with some of the more difficult coding situations. Lummox JR |
In response to Lummox JR
|
|
Lummox JR wrote:
Associative lists are definitely worth playing with. I find them extremely helpful at dealing with some of the more difficult coding situations. I agree with that totaly I myself am still a bit new to using them but I'm learning how quickly. |
In response to Lummox JR
|
|
I tried some of these changes and it works pretty well.
mob/shopkeeper/verb Sell() set src in oview(1) var/list/L = new var/obj/O2 for(var/obj/O in src) for(O2 in usr) if(O2.type==O.type) // only buy items of the exact same type break if(O2) L["[O] --- [round(O.price/2,1)]"]=O2 //rest of code... If i want the usr to be able to sell all of his items, do i have to remove those parts of the codes ? |
In response to Cravens
|
|
Cravens wrote:
I tried some of these changes and it works pretty well. I suggest this instead: mob/shopkeeper/verb The sell code I gave you was more complicated because for most games, the shopkeeper will only buy certain types of items from you. There is a little interesting dilemma here: With my code, modified in this way, the item you sell is deleted, not added to the shopkeeper's inventory. This means if the shopkeeper doesn't sell potions but you sell one to him anyway, you won't be able to buy it back from him. If you were to change this so the item moved into the shopkeeper's inventory (provided he didn't already have one of the same type), he'd then be able to sell an unlimited number of that item. Lummox JR |
O.name = "[O.name] [O.price]"
do this before the menus is shown.
and since the shope keeper code makes a NEW obj of what they buy, you wont have to worry about changing the name back to normal.
FIREking