ID:179038
 
how do i make it so if u can't affored something at a store it will not let u buy it? in my game it just says it and gives u the thing anyway. it also makes the money go into the negatives. If someone could help me i'd appriciate it.

thanks


P.S.- were can i find code to allow GM's to make a Clan and let other people join them by me making them part of it??


Alienman

Use

if(usr.gold<=0)//if there gold is less then 0
usr<<"sorry too poor"
return

Remember change the gold var to your money var.
In response to Super16
when i used ur code it poped up w/ 2 errors

1: verbs.dm:130:error::expected a constant expression

2: verbs.dm:132:error::missing expression
I beleive this should work.
mob/var/cash = 100
NPC/Merchant
parent_type = /mob
proc/Buy()
switch(alert(usr,"What would you like to buy?","What Item?","Sword","Shield","Pants"))
if("Sword")
if(usr.cash < 50) goto CANNOT_BUY
else
usr.cash -= 50
new /Weapon/Sword (usr)
if("Shield")
if(usr.cash < 60) goto CANNOT_BUY
else
usr.cash -= 60
new /Armour/Shield (usr)
if("Pants")
if(usr.cash < 30) goto CANNOT_BUY
else
new /Armour/Pants (usr)
usr.cash -= 30
usr << "Thank you for buying!"
return
CANNOT_BUY
usr << "You do not have enough money for that!
PC/Player
parent_type = /mob
verb/Say(var/message = "" as text)
world << "[src.key]: [message]"
if(ckey(message) != "venderbuy") return
for(var/NPC/Merchant/M in hearers()) break
M.Buy()
Weapon/Sword
parent_type = /obj
Armour
parent_type = /obj
Shield
Pants
world/mob = /PC/Player
In response to Alienman22774
Please post the keeper code so I can implement it.
In response to Super16
all i really need is the code so if the amount of money is less then the cost of the object then it won't let u have it. here is my Bed code

turf
Inn_Bed
icon = 'bed.dmi'
verb
Sleep()
set src in oview(1)
switch(input("U look a little tired. Do u want to sleep for 100 dollers???","???")in list("Yes","No"))
if("Yes")
usr.Health = usr.MaxHealth
usr.gold -= 100
if("No")
usr<<"u don't feel like sleeping"
..()

i have it working it just puts u in the negatives if u have less then 100 gold
In response to Alienman22774
turf
Inn_Bed
icon = 'bed.dmi'
verb
Sleep()
set src in oview(1)
switch(input("U look a little tired. Do u want to sleep for 100 dollers???","???")in list("Yes","No"))
if("Yes")
if(usr.gold<=0)
return
else
usr.Health = usr.MaxHealth
usr.gold -= 100
if("No")
usr<<"u don't feel like sleeping"
..()
In response to Super16
now i'm poping up w/ an error on

usr<<"u don't feel like sleeping"

the error says

verbs.dm:135:error::expected "if" or "else"

what should i do??
In response to Super16
Here you go I typed you one up.

turf/Inn_Bed
icon='bed.dmi'
verb
Sleep()
set src in oview(1)
switch(alert("Would you like to sleep for 100 dollars?","Sleep","Yes","No"))
if("Yes")
if(usr.gold<=0 && usr.gold < 99)
return
else
usr.Health=usr.MaxHealth
usr.gold-=100
return
if("No")
return
In response to Super16
ok it finally didn't pop up w/ errors but now when i sleep it takes my gold still even though i only had 10 gold making it -90. it gave me the health too but now i'm in the negatives w/ money.
In response to Alienman22774
Take out the && usr.gold < 99
THen add another if under it that says

if(usr.gold < 99)
return
In response to Super16
so in the end what should it look like i got 9 errors they were all verbs.dm:129: Inconsistent indentation. but one wasverbs.dm:130:warning: empty 'else' clause.
In response to Alienman22774
Then you need to fix your indentation :o)
In response to Foomer
i know that but what about the verbs.dm:130:warning: empty 'else' clause i'm not as stupid that i wouldn't know what to do w/ a verbs.dm:128: Inconsistent indentation. error
In response to Alienman22774
turf
Inn_Bed
icon = 'bed.dmi'
verb
Sleep()
set src in oview(1)
switch(input("U look a little tired. Do u want to sleep for 100 dollers???","???")in list("Yes","No"))
if("Yes")
if(usr.gold<=0)
return
if(usr.gold<99)
return
if(usr.gold>=100)
usr.Health = usr.MaxHealth
usr.gold -= 100
return
if("No")
usr<<"u don't feel like sleeping"
return

There you go also I suggest you study DM more than what you have so you will be more independent than interdependent.
In response to Alienman22774
The other error means you have an 'else' statement without an 'if' statement.
In response to Super16
Super16 wrote:
if("Yes")
if(usr.gold<=0)
return
if(usr.gold<99)
return
if(usr.gold>=100)
usr.Health = usr.MaxHealth
usr.gold -= 100
return

Just as a side note, this is rather drawn out. If the users gold is under 99, it won't matter if its under 0. One if() statement removed.

And if it gets to if(usr.gold>=100) that means usr.gold is over 99 because it didnt exit the verb, so that if() statement is useless as well.

Too many useless if() statements can eventually lag up a game.

Alathon, effeciency is key.
In response to Alathon
if("Yes")
if(usr.gold<=0)
return
if(usr.gold<99)
return
if(usr.gold>=100)
usr.Health = usr.MaxHealth
usr.gold -= 100
return
if("Yes")
if(usr.gold>=100)
usr.Health = usr.MaxHealth
usr.gold -= 100
else src << "You don't have enough gold!"
return

Mmm...wonderful compactness.