ID:272715
 
Sorry to totally spam up the forums with my item stacking issues, but I found a system that works for me, and is real simple. I avoided Entered() because the way it was being used was totally confusing to me. And honestly, I can't believe my new way even worked lol. It might not be the most efficient, but I'd still like improvement ideas. And please don't tell me to use some other way :\ I've gone through like 5 different item stacking methods >.<

obj
proc
addAmount(amt as num)
if(!stackable) return
src.Amount += amt
src.suffix = "([src.Amount])"
removeAmount(amt as num)
if(!stackable) return
src.Amount -= amt
if(!src.Amount) del(src)
else src.suffix = "([src.Amount])"
stackCheck(obj/O)
if(O.stackable)
var/obj/X = locate(O.type) in O.loc
if(X)
X.Amount += 1
X.suffix = "([X.Amount])"
del(O)
New()
..()
if(!stackable) src.suffix = null

obj
verb
Get()
set src in usr.loc
if(stackable)
var/obj/object = locate(text2path("[src.type]")) in usr.contents
if(object)
object.addAmount(src.Amount)
del(src)
else
usr.contents.Add(src)
else
usr.contents.Add(src)
Drop()
set src in usr.contents
if(Amount>1)
var/amt = input("How many would you like to drop?\n[src] Amount: [src.Amount]","Drop",src.Amount) as num
if(amt<1) return
if(amt>Amount) amt = Amount
if(amt == Amount) Move(usr.loc)
else
removeAmount(amt)
var/obj/object = new src.type
object.addAmount(amt)
object.Move(usr.loc)
else
Move(usr.loc)
Drop_All()
set src in usr.contents
Move(usr.loc)

obj/Veins
density = 1
Copper_Vein
name = "Copper Vein"
icon = 'Veins.dmi'
icon_state = "copper"
verb
Mine()
set category = "Utilities"
set src in oview(1)
if(src.Mined || usr.Mining) return
src.Mined = 1
usr.Mining = 1
usr.Mining()
usr.Mining = 0
src.Mined = 0
if(prob(usr.MiningProb))
usr<<output("<font size=1><font color=red>\[Failure!]</font> You mine nothing.","Events")
del(src)
return
var/obj/C = new/obj/Items/Ores/Copper_Ore(usr)
stackCheck(C)
usr<<output("<font size=1><font color=green>\[Success!]</font> You successfully mine some Copper Ore. It has been added to your inventory.","Events")
if(usr.MiningTime > 10)
if(prob(25))
usr.MiningTime -= 2
usr<<output("<font size=1>~ You become slightly faster at mining.","Events")
usr.MiningEXP += 5
usr.MiningLvlUp()
del(src)
Mizukouken Ketsu wrote:
I avoided Entered() because the way it was being used was totally confusing to me.

How was it confusing you? If you explain what you did not get, we can help you understand.

Personally, in my opinion, mob/Enter() and Exit() (not entered/exited) is the best place to deal with stacking items as they are called when objects (note this does not mean /obj solely) attempt to enter/leave the mob's content... which is called when the object is Move()d to the mob's content.

If you want to see an example of a stacking demo using Enter/Exit, you can check my inventory 4.1 zip hosted on my member page and see how it works.

Also, since src.type is a path, you can change

var/obj/object = locate(text2path("[src.type]")) in usr.contents

to

var/obj/object = locate(src.type) in usr.contents

Er I would make more comments but I'm gonna go sleep soon, I'll take a look later if I remember