ID:161453
 
I would just like to know how to make currency. I know it stupid, but I am stupid ... For instance, I want to buy Cheese for 50 gold.
mob
var
gold=100

npc
Cheeseseller
icon='cheeseller.dmi'
density=1
verb

buy_cheese()
if(usr.gold >= 50) //if user has 50 gold or more
usr.gold -= 50 //take 50 gold
var/obj/cheese/C = new/obj/cheese // make a new cheese obj
C.loc=usr // cheese location = user location
else // if they have less than 50 gold
usr<<"You need 50 gold to buy cheese"


obviously you will need to make cheese obj and cheeseseller icon but that is how you can sell items.
In response to VVi11i4m
Thank you very much!!
In response to VVi11i4m
The correct term is "cheesemonger" or, alternatively, "cheesesmith".
In response to Jujitsubb777
How do I make it were I can actually to talk him lol... I can't get him to talk...
(show the goods is what i meen by talk)
In response to Jujitsubb777
Hm? Like...
verb/Talk()
usr << "[src] says: I have a good bargain on cheese today, [usr]!"
In response to Jujitsubb777
Ok combining all of the things said here is the verb with talking and cheesemonger
mob
var
gold=100

npc
Cheesemonger
icon='cheesmonger.dmi'
density=1
verb

talk()
usr << "[src] says: I have a good bargain on cheese today, [usr]!"
switch(input("Would you like to buy some?") in list ("Yes", "No"))
if("Yes")
if(usr.gold >= 50) //if user has 50 gold or more
usr.gold -= 50 //take 50 gold
var/obj/cheese/C = new/obj/cheese // make a new cheese obj
C.loc=usr // cheese location = user location
else // if they have less than 50 gold
usr<<"You need 50 gold to buy cheese"
if("No")
usr<<"Fine, buy your cheese from the cheesesmith across the street!"
Those others are just simple examples. You need to take into account inflation, demand & availability of products, the fact that the local rulers of the land will want to nab your money in exchange for the town guards to protect you from thiefs (whom are not doing a very good job at that).

item
parent_type = /obj
currency
suffix = " (1 left)"
var
amount = 1
verb/gather()
for(var/item/currency/I in usr.contents)
if(I.type != src.type) continue //you can only gather one particular form of currency
amount += I.amount
del I
suffix = " ([amount] left)"
cran
lukio
clothing
pants
...

npc
parent_type = /obj //alternative: /mob, but I tend to refrain from using it unless you can possess the NPCs\
and control them like puppets.

currency_exchange
name = "bank teller"
verb/talk()
set src in view(2) //the teller is behind a counter
var/list/currencies = list("Cran" = /item/currency/cran, "Lukio" = /item/currency/lukio)

var/from = input(usr, "Which currency would you like to transfer here?", "Bank Teller")\
as null|anything in currencies
if(!from || !(src in view(2,usr))) return
var/from_type = currencies[from]
var/item/currency/I = locate(from_type) in usr.contents
if(!I)
alert(usr, "How do you expect to transfer from [lowertext(from)] if you do not have any?", "Bank Teller")
return

var/get = input(usr, "Which currency would you like to receive in return?", "Bank Teller")\
as null|anything in currencies - from
if(!get || !(src in view(2,usr))) return
var/get_type = currencies[get]

var/amount = input(usr, "How many [lowertext(from)] would you like to give to turn into [lowertext(get)]?\n\
The current exchange rate is at 1
[lowertext(from)] for 0.50 [lowertext(get)].") as null|num
if(!amount || amount <= 0 || amount != round(amount) || !(src in view(2,usr))) return

var/real_amount = 0
for(I in usr.contents)
if(amount <= 0) break
if(I.type != from_type) continue
if(I.amount >= amount)
I.amount -= amount
real_amount += amount
else
amount -= I.amount
real_amount += I.amount
if(I.amount <= 0) del I

var/item/currency/O = new get_type(usr)
O.amount = real_amount
if(!amount)
alert(usr,"I have successfully transferred your money, sir.", "Bank Teller")
else
alert(usr,"I couldn't transfer some of it, sir. I only managed to transfer [real_amount] before your money ran out. Next time, bring more [lowertext(from)]!", "Bank Teller")
clothes_shop
name = "Shopkeeper"
verb/talk()
set src in view(2)
switch(alert(usr,"I sell pants. Would you like to buy a pair?", "Shopkeeper", "Yes", "No"))
if("Yes")
var/item/currency/lukio/I = locate() in usr.contents
if(!I)
I = locate(/item/currency) in usr.contents
if(I) alert(usr, "Take your fancy [lowertext(I.name)] elsewhere. I have no use for it.", "Shopkeeper")
else alert(usr, "You don't have any money at all!", "Shopkeeper")
else
var
total_amount = 0
amount = 250
for(I in usr.contents) total_amount += I.amount

if(total_amount >= amount)
for(I in usr.contents)
if(amount <= 0) break
if(I.amount >= amount)
I.amount -= amount
amount = 0
else
amount -= I.amount
I.amount = 0
if(I.amount <= 0) del I
usr.contents += new/item/clothing/pants
if("No")
alert(usr,"Very well then.")


And here we have our little world. There are two countries, the Cran and the Lukio, each with their own currency.
Each country has a Bank Teller around somewhere (usually in a bank) which will trade one currency for another.
Lukio also has a clothes shoppe, with a shopkeeper who hates Cran and will not accept their money.

Exercise #1: The bank teller is pretty static. Try to make the exchange rate dynamic depending on the amount of gold bars the Cran and Lukio lands possess.

Exercise #2: The clothes shop should have a similar aspect to it. Depending on how many pants the shopkeeper has available, increase or lower the price. If the shopkeeper has 100 pairs of pants, the price would be lower than if the shopkeeper only had 5.

-- Data
In response to Android Data
You might also want to take into account the possibility of the cheesemonger being out of cheese, the cheese rotting, and so forth. Or, you might want to just do what the thread creator asked for and leave it at that.
In response to Android Data
wow i had never thought of using supply and demand, that is actually pretty cool a little currency rate built into a game.