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." |
In response to Scoobert
|
|
I got it now thank you both.:P
|
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 |
In response to Little Sally
|
|
welcome
|
In response to Foomer
|
|
Foomer I tryed using your code but its now saying.
Armorer.dm:35:error:num :undefined argument type |
In response to Little Sally
|
|
Weird, I don't.
|
In response to Foomer
|
|
Do I have to define num?
|
In response to Little Sally
|
|
Did you copy the code strait from my post?
|
In response to Foomer
|
|
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 |
In response to Little Sally
|
|
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.
|
In response to Foomer
|
|
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)) |
In response to Foomer
|
|
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() |
In response to Little Sally
|
|
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"
|
In response to Foomer
|
|
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 |
In response to Little Sally
|
|
! means not so its saying they dont have enuff
|
In response to LordJR
|
|
That is easy! Thank you LJR :P
|
if(usr.gold <20)
usr<<"go away you bum"
something like that.