ID:446325
 
(See the best response by Neimo.)
hi i would like to know how i can make a shop that will take the money format i have from the money stat
statpanel("money")
stat("money","[G]G,[S]S,[C]C")


var/
G = 5
S = 60
C = 99
proc/Money()
if(usr.C > 99)
usr.S += 1
usr.C -= 100
if(usr.S > 99)
usr.G += 1
usr.S -=100


once again im new at this and i cant find reference to anything usefull. only thing i figured how to do was if id put a price=50 but when i try to make it
obj
var
price=[G],[S],[C]

(partial code thought it too long)i keep getting errors if someone could help me with the "formula" to have a shop work with this id be thankfull
You could store money as an integer and convert it to gold, silver, copper just to display it and update it once you gain or loose money. I haven't programmed in DM in so long and I was never any good when I did, so I'm not sure how to go about implementing that.

[EDIT]
You could do a loop that divides money by 100 and as long as it's greater then 1, add 1 to silver and subtract 100 from copper. Then while you do that check if silver is 100 or more and if it is, add 1 to gold and subtract 100 from silver.
Best response
There is probably a far better way you can do this, but this is all that came to mind:

mob/var/list/money = list("gold" = 1, "silver" = 2, "copper" = 3)

mob/Stat()
stat("Gold: [money["gold"]]")
stat("Silver: [money["silver"]]")
stat("Copper: [money["copper"]]")
..()

mob/proc/deductmoney(list/price)
// compare the lists to make sure you have enough
if(money["gold"] >= price["gold"] && money["silver"] >= price["silver"] && money["copper"] >= price["copper"])
// deduct the amount
money["gold"] -= price["gold"]
money["silver"] -= price["silver"]
money["copper"] -= price["copper"]
// update the list with the correct setup
if(money["silver"] >= 100)
// set the silver to 99
money["silver"] -= 100
// add one gold
money["gold"] ++

// you can call the deductmoney() proc like:
src.deductmoney(list("gold" = 10, "silver" = 69, "copper" = 1))
With the loop from DisturbedSixx's post:

mob/proc/moneyloop()
money["silver"] = 353
money["copper"] = 532
// loop through your money and set it accordingly
while(money["silver"] | money["copper"] >= 100)
sleep(1)
// check for silver then copper
if(money["silver"] >= 100)
money["silver"] -= 100
money["gold"] ++
// check for copper now
if(money["copper"] >= 100)
money["copper"] -= 100
money["silver"] ++
In response to Neimo
so then if i use this code i would call the deductmoney() proc from within the shop right? but do i do that for each item or should i make a variable for gold,silver and copper to add in the price[]? because i really need to know how to make the shop itself function and im kind of a noob to programming (this is my initiation to the programming world :S )
If you are still looking for help here is an example of how i would do it it.
see below comment.

If you have any questions about the demo please ask me.
ya i cant open the file would it be possible to send it as a wordpad format or somethin? would be apreciated thanks
okay for some reason it made into an odd file but i've fixed it here ya go:

http://www.sendspace.com/file/gjft9c
In response to Natasdrol
You would call it like so:

// set the price manually
usr.deductmoney(list("gold" = 2, "silver" = 1, "copper" = 0))
// or create a list which would save more time
obj/var/list/myprice = list("gold" = 0, "silver" = 0, "copper" = 0)
obj/item/sword
myprice = list("gold" = 10, "silver" = 50, "copper" = 0)
// and it would be called like:
usr.deductmoney(myprice)
thanks abunch everyone got a working code now :P