ID:1604794
 
Code:
obj/Inventory
Resources
verb
Drop(n as num)
usr.itemDrop(src,n)
usr << "You drop [n] [src]."
return


mob/proc
itemDrop(obj/Inventory/o, n as num)
if(o.canStack && o.contents.len)
for(.=n;.>0;.--)
var/obj/Inventory/theItem=pick(o.contents)
theItem.loc=get_step(usr,usr.dir)
if(o.contents.len)
o.suffix="x[o.contents.len+1]"
else
o.suffix="x1"
else
o.loc=src.loc
o.suffix=""


Problem description:
It works as intended, but it drops 4 instances of the dropped resource. How do I make it so it drops it all in one object?
Thanks for the help, very useful. Ended up changing grab/drop completely but it was for the better.
Is there a way to temporarily name an item? I had to create a new instance of the item to retain its original name after naming it something else as the player drops it. I rename it to reflect the amount that was dropped.

mob/proc
itemDrop(n)
for(var/obj/Inventory/s in contents)
if(n > s.stack_count)
n = s.stack_count
var/obj/Inventory/w = new s.type()
w.stack_count = 0
s.stack_count-= n
w.stack_count+= n
if(s.stack_count <= 0)
del(s)
else
s.suffix = "x[s.stack_count]"
w.name = "[w.stack_count] [w.name]"
view(usr) << "[usr] drops [w]."
w.loc = get_step(usr,usr.dir)


itemAdd(obj/Inventory/i)
for(var/obj/Inventory/f in contents)
if(i.type == f.type)
f.stack_count += i.stack_count
f.suffix = "x[f.stack_count]"
view(src) << "[src] picks up [i]."
del i
return
var/obj/Inventory/s = new i.type()
i.name = s.name
del(s)
src.contents += i
view(src) << "[src] picks up [i]."
for(var/obj/Inventory/f in contents)
f.suffix = "x[f.stack_count]"
.-.

Took me a while to realize I could save old name in a var and then when I when I want to use it again I change the name back to the old name. This is definitely not my strong suit lol.