ID:166734
 
Below is my code for selling items, but you can only sell 1 at a time, which is kinda annoying if you multiple of the same item. How would i do this? How would I item stack in the inventory?
                if("Sell")
var/obj/o=input("What do you wish to sell?",src) as obj in null|usr

if(!o){usr<<"<font color =green><b>[src]:</font></b><font color=red><b> Stop waisting my time!</font></b>";return}
switch(alert("I'll give you [o.value] gold for that [o]. Sell?",src,"Yes","No"))
if("Yes")
usr.Gold+=o.value
o.Move(src)
usr<<"<b>You sold the [o] for [o.value] gold</b>"
usr<<"<font color=green><b>[src]:</font></b> Thank you." // Quicky mart!
if("No")
usr<<"<font color =green><b>[src]:</font></b><font color=red><b> Stop waisting my time!</font></b>"
var/sold=input("what sell?")as null|obj in usr
var/qu=input("sell how much of [sold]?")as null|num
muny+=sold.price*qu


In response to Shoe
Shoe wrote:
> var/sold=input("what sell?")as obj in usr
> var/qu=input("sell how much of [sold]?")as null|text
> muny+=sold.price*qu
>


it didnt work, it would do all let you chose the amount u wanted to sell but say the that the obj added up would be 0 gold. here is my code below:
                if("Sell")
var/obj/o=input("What do you wish to sell?",src) as obj in null|usr

if(!o){usr<<"<font color =green><b>[src]:</font></b><font color=red><b> Stop waisting my time!</font></b>";return}

var/r=input("How much of [o] would you like to sell?") as null|text
switch(alert("I'll give you [o.value*r] gold for [r] [o]. Sell?",src,"Yes","No"))
if("Yes")
usr.Gold+=o.value*r
o.Move(src) want.
usr<<"<b>You sold the [o] for [o.value] gold</b>"
usr<<"<font color=green><b>[src]:</font></b> Thank you."
if("No")
usr<<"<font color =green><b>[src]:</font></b><font color=red><b> Stop waisting my time!</font></b>"
In response to FriesOfDoom
i put text by mistake there, change it to num.
In response to Shoe
ok, got it to work, but how would i make it check to see if the player actually had that many of the item they were selling?? And how would i make it take that much out of their inventory?
In response to FriesOfDoom
//take out
for(o in usr)
del o

//check
var/a
for(o in usr)
a++
if(a<amount_bought)return
In response to Shoe
Shoe wrote:
> //take out
> for(o in usr)
> del o
>
> //check
> var/a
> for(o in usr)
> a++
> if(a<amount_bought)return
>


i got this error in the game when trying to sell.
<font color=red>runtime error: Cannot read null.value
proc name: Shop (/mob/NPC/Shopkeeper/verb/Shop)
source file: NPCs.dm,51
usr: FriesOfDoom the King Dragon (/mob/player)
src: Shopkeeper (/mob/NPC/Shopkeeper)
call stack:
Shopkeeper (/mob/NPC/Shopkeeper): Shop()
</font>
here is my current code:
                if("Sell")
var/obj/o=input("What do you wish to sell?",src) as obj in null|usr
if(!o){usr<<"<font color =green><b>[src]:</font></b><font color=red><b> Stop waisting my time!</font></b>";return}

var/r=input("How much of [o] would you like to sell?") as null|num
switch(alert("I'll give you [o.value*r] gold for [r] [o]. Sell?",src,"Yes","No"))
if("Yes")
var/a=usr.contents
for(o in usr)
a++
if(a<r)return
else
usr.Gold+=o.value*r
for(o in usr)
del o


usr<<"<b>You sold the [o] for [o.value] gold</b>"
usr<<"<font color=green><b>[src]:</font></b> Thank you."
if("No")
usr<<"<font color =green><b>[src]:</font></b><font color=red><b> Stop waisting my time!</font></b>"


thank you so much so far for your help :P
In response to FriesOfDoom
var/a=usr.contents

should be just var/a
In response to Shoe
Shoe wrote:
var/a=usr.contents

should be just var/a
yeah i tryed just var/a first and it gave me like the same error message
In response to FriesOfDoom
um.....anyone?
In response to FriesOfDoom
There are two problems I was aware of after skimming this code. The first is that for(o in usr)del(o) would delete ALL of the items in their contents, and not just the amount they sold(Check my post to your other thread in code problems to fix that). The second is the runtime problem.

                        if("Yes")
var/a=usr.contents
for(o in usr)
a++
if(a<r)return
else
usr.Gold+=o.value*r
for(o in usr)
del o


usr<<"<b>You sold the [o] for [o.value] gold</b>"
usr<<"<font color=green><b>[src]:</font></b> Thank you."


Notice the two messages to the player AFTER the object has been deleted? Since o has been deleted you no longer have access to it or it's variables. To get this to work, move the messages before the for(), like so.

                        if("Yes")
usr<<"<b>You sold the [o] for [o.value] gold</b>"
usr<<"<font color=green><b>[src]:</font></b> Thank you."
var/a=usr.contents
for(o in usr)
a++
if(a<r)return
else
usr.Gold+=o.value*r
for(o in usr)
del o


[edit]

                        if("Yes")
usr<<"<b>You sold the [o] for [o.value] gold</b>"
usr<<"<font color=green><b>[src]:</font></b> Thank you."
var/atom/t=new o.type
for(amountof,amountof>0,amountof--)
for(var/obj/O in usr.contents)
if(istype(O,t.type))
del(O)

I took the liberty of adding my code. I made atom/t because if I were checking to see if O were o.type, and o was deleted earlier in the check you would get a runtime. I am pretty sure it will work, and whatever else isn't in there that you wanted you can probably add yourself from your previous code.

-Exophus