Buy()
set src in oview(2)
var/item = input("What would you like to buy?") in list ("Desert Armor- 20 Gold","Nevermind")
switch(item)
if("Desert Armor- 20 Gold")
new /obj/Desert_Armor(usr)
usr << "You are handed a fine piece of armor."
usr.gold -= 20
else
usr << "You do not have enough gold!"
if("Nevermind")
return
ID:261408
![]() Feb 22 2002, 7:35 pm
|
|
Im not sure where I would put the code so that if the usr does not have the amount of money needed it does not sell the item. Please help me, Ill post my buy verb.
|
Put it after the if("Desert Armor") part.
if("Desert Armor") if(usr.gold >= 20) //continnue selling else src << "You do not have enough gold." |
Here, I rebuilt it to use a simple HasGold() proc that'll check if src has enough gold to pay the number (defined in the ()'s of the proc). If not, return the "You do not have enough gold!" error and end the verb. Otherwise, keep going.
Buy() set src in oview(2) var/item = input("What would you like to buy?") in list ("Desert Armor- 20 Gold","Nevermind") switch(item) if("Desert Armor- 20 Gold") if(!HasGold(20)) usr << "You do not have enough gold!" return new /obj/Desert_Armor(usr) usr << "You are handed a fine piece of armor." usr.gold -= 20 if("Nevermind") return proc/HasGold(num) if(src.gold >= num) return 1 else return 0 |
No I typed it.
Buy() set src in oview(2) var/item = input("What would you like to buy?") in list ("Desert Armor- 20 Gold","Nevermind") switch(item) if("Desert Armor- 20 Gold") if(!HasGold(20)) new /obj/Desert_Armor(usr) usr << "You are handed a fine piece of armor." usr.gold -= 20 else usr << "You do not have enough gold!" if("Nevermind") return proc/HasGold(num) if(src.gold >= num) return 1 else return 0 |
I can copy the whole thing to DreamMaker and it works fine for me (assuming I have the appropriate items included), so I don't know why you'd be getting an error.
|
I think I found a problem. You put it so that if usr had that much gold it told them that they didn't have enough. Or maybe im looking at it wrong.
if(!HasGold(20)) |
This is my exact code for buy. The problem is when I try to buy the item and dont have enough gold it still lets me buy it an places my gold to a negitive number.
Buy() |
Oh, if that's the case, you're using HasGold() backwards. Change it to if(HasGold(20)), and get rid of the !, because that's the same as asking "if src does NOT have 20 gold"
|
E?? Whats all this nonsense?? Hey LS here is an easier way to just update ur original code and its should be easy to understand too!
LJR Modified code: <HE> Buy() set src in oview(2) var/item = input("What would you like to buy?") in list ("Desert Armor- 20 Gold","Nevermind") switch(item) if("Desert Armor- 20 Gold" && usr.gold > 19) new /obj/Desert_Armor(usr) usr << "You are handed a fine piece of armor." usr.gold -= 20 else usr << "You do not have enough gold!" if("Nevermind") return |
if(usr.gold <20)
usr<<"go away you bum"
something like that.