ID:166563
 
I want to make a money verb that the user can drop a certain amount of money. I also want to be able to store a number into an obj named money. I was thinking of having an obj/var/gold for the gold contained in the bag of money, then have a mob/var/amount and do gold = amount so that the bag contains the amount of gold. Is this the right way of doing this? Also, the topic is my main question :) (usr drops [amount] of money!) something like that.
mob/verb
dropgold()
var/amt = input("How much to drop") as num
usr.gold-=amt


That should get you started.
In response to Talion Knight
Although that's a start, you should also make sure of the following:

1) The amount isn't negative.
2) The player has enough gold to drop.
3) The player has the ability to cancel.

I'll leave you to figure out how to achieve points 1 and 2, as for point 3:

mob/verb
dropgold()
var/amt = input("How much to drop") as num|null //adds a cancel option
if(amt) //if the player chooses cancel, the code continues, but amt will be null.
//our if() will check that amt has a non-zero value.
usr.gold-=amt

In response to DeathAwaitsU
Good call there. Don't know how missed something as simple as that :\
In response to DeathAwaitsU
Don't forget if the player has enough gold to drop.

mob/verb
dropgold()
var/amt = input("How much to drop") as num|null //adds a cancel option
if((usr.gold - amt) > 0)
//our if() will check that amt has a non-zero value.
usr.gold-=amt
In response to BeyondPower
BeyondPower wrote:
Don't forget if the player has enough gold to drop.

> mob/verb
> dropgold()
> var/amt = input("How much to drop") as num|null //adds a cancel option
> if((usr.gold - amt) > 0)
> //our if() will check that amt has a non-zero value.
> usr.gold-=amt
>


I didn't forget. If you read my post more closely, you'll notice I said "I'll leave you to figure out points 1 and 2".

As for your example, you should actually do if(usr.gold - amt >= 0) so that the player can drop all his money.
In response to DeathAwaitsU
Ok, was just wondering if I was on the right track. I can do all that stuff. The problem I'm having is making a gold icon appear after the usr drops the gold and have that obj hold the amount specified. Can't get the variables right. Do I use atom, obj, mob? That's the part I can't figure out. Oh and I got the answer to everything else, thanks.

P.S. I have the code for the checking of 1,2,and 3. ;)

Well to summarize what I'm asking:
1)storing a value to obj/gold that will be accessible by mob/player. for ex:
obj/gold = 100
//mob uses get when one space away...
mob/player/gold += (src)

Something like that for picking up the gold bag and adding it to his money.

2)drawing a new obj/gold icon where the usr dropped gold

3)I can't remember what the third one was...>.<
In response to SuperSonicD
Make sure to round() too!
In response to SuperSonicD
You could do something like this:

obj
Gold_Bag
var/amount = 0
icon = 'goldbag.dmi'

mob/verb/Drop_Gold()
var/gold = input("How much do you want to drop?") as num|null
if(gold && gold>0 && gold<=usr.money)
var/obj/Gold_Bag/G = new(usr.loc) //creates a new Gold_Bag where the player is standing.
//the bag is now referenced as G.
G.amount = gold //set G's value to what we inputted
usr.money -= gold

mob/verb/Pick_Up_Gold()
for(var/obj/Gold_Bag/G in usr.loc) //search for any Gold_Bags underneath us
usr.money += G.amount //increase our own gold by G's amount
del(G) //delete the bag so that it can't be picked up again


*Edit*

And as Flame Sage suggests, you may want to round() some values so that we're not dealing with 10.0356 gold.
hub://Crashed.crashMoney :)