ID:156311
 
How would i go about making a crafting system that uses stackable items like when you get more then one carrot its says in the inventory carrot x3 and have the craft system rely on the number of items like if you have 3 carrots and 2 tomato's you make stew and if not it denies you.
By using locate() to find the object and - if it exists - checking its quantity to determine if you are allowed to create something.
In response to Garthor
obj
CItems
var/canStack=0

verb/Get()
set src in oview(1)
usr.itemAdd(src)
usr.contents.Add(src)

verb/Drop()
set src in usr
usr.itemDrop(src)

Oil
icon_state="Oil"
canStack=1

Meat
icon_state="Meat"
canStack=1

Crafting_Manual
icon_state="Manual" // The star is un stackable!
canStack=0

mob/proc

itemDrop(obj/CItems/o)
if(o.canStack && o.contents.len)
var/obj/CItems/theItem=pick(o.contents)
theItem.loc=src.loc
if(o.contents.len)
o.suffix="x[o.contents.len+1]"
else
o.suffix="x1"
else
o.loc=src.loc
o.suffix=""

itemAdd(obj/CItems/o)
var/list/items=list()

for(var/obj/i in src.contents)
items+=i.type

if(o.type in items) //if a similer item is found in the contents
if(o.canStack)
var/obj/CItems/theItem
for(var/obj/i in src.contents) if(i.type == o.type) theItem=i
if(theItem)
theItem.contents+=o
theItem.suffix="x[theItem.contents.len+1]"
else
src.contents+=o
o.suffix="x1"
else
src.contents+=o

else
src.contents+=o
o.suffix="[o.canStack ? "x1" : "[o.suffix]"]"

As you can see it uses a suffix or so and I can't really tell where to go on from here i made a test verb but don't know how to work in the quantity of items

mob/verb
Cook()
switch(input("What do you want to cook?") in list("Gears", "Chicken"))
if("Gears")
var/I
for(var/obj/CItems/Oil in usr.contents)
if(istype(Oil, /obj/CItems/Meat))
I++
if(I)
usr << "You start making Gears"
sleep(5)
usr << "You finish the Gears."
usr.contents += new /obj/CItems/Meat
usr.contents -= locate(/obj/CItems/Oil) in usr.contents
else
usr << "You don't have any meat for Rabbit Stew."

it only works if you have 1 of each item but after that i dunno how to make it do like if you have 5 gears and 1 carrot it then makes whatever.
In response to Mastergamerxxx
Give items a 'quantity' variable, and when the user gets more than one of a stackable object, increase the quantity of the first object.
In response to Warlord Fred
perhaps someone can give me a example
In response to Mastergamerxxx
Perhaps you can read what he wrote and implement it. It's very simple and almost identical to what you already have.
In response to Garthor
Where do i put it i have no clue how to implement it
In response to Mastergamerxxx
Ugh how annoying i got the thing finally to work but now i dunno how the hell to add the recipe part.
Like I got it to work if the amount is >=3 and what not but how do i now make it read the recipe
////example items////
obj
icon = 'Icons.dmi'
unstackable
name = "Unstackable Item"
icon_state = "unstackable"
stack
stackable
icon_state = "stackable"

stackable2
icon_state = "stackable"

////item stacking system////
obj
New(loc)
..()
src.loc = null
src.Move(loc)
verb
Grab()
set src in oview(1)
set category = "Loot"
src.Move(usr)
usr<<"You receive [src.name][istype(src,/obj/stack)? "(x[src:amount])":null]"
Drop()
set src in usr
set category = null
src.Move(usr.loc)
usr<<"You drop [src.name][istype(src,/obj/stack)? "(x[src:amount])":null]"
stack
var
amount = 1
quanity=0
proc
edit_amount(n)
src.amount += n
src.suffix = "(x[src.amount])"
src.quanity=src.amount
if(!src.amount)
del src
New(loc,amt=1)
..(loc)
src.amount = amt
Move(a)
if(ismob(a))
var/mob/m = a
var/obj/stack/o = locate(src) in m
if(o)
o.edit_amount(src.amount)
m<<"You receive [src.name] (x[src.amount])"
del src
return ..()
Grab()
var/obj/stack/s = locate(src) in usr
if(s)
s.edit_amount(src.amount)
usr<<"You receive [src.name] (x[src.amount])"
del src
else
return ..()
Drop()
var/n = input(usr,"Drop how many?","Drop: [src.name]",src.amount) as null|num
if(n)
new src.type(usr.loc,n)
src.edit_amount(-n)
verb/Drop_All()
set src in usr
set category = null
src.Move(usr.loc)
usr<<"You drop [src.name] (x[src.amount])"
verb/derp()
for(var/obj/stack/stackable in usr.contents)
if(src.quanity>=3)
usr<<"finally"
else
usr<<"T_T"


like where do i go from here
In response to Mastergamerxxx
For each requirement of the recipe, check if that requirement is met. If the requirement is not met, abort. Once you've checked off on every requirement, go through the requirements again, removing items this time. Then, create the new item.
In response to Garthor
I mean code wise i obviously know to do that but how do i do it in code
In response to Mastergamerxxx
Code:
////example items////
obj
icon = 'Icons.dmi'
unstackable
name = "Unstackable Item"
icon_state = "unstackable"
stack
stackable
icon_state = "stackable"

stackable2
icon_state = "stackable"

////item stacking system////
obj
New(loc)
..()
src.loc = null
src.Move(loc)
verb
Grab()
set src in oview(1)
set category = "Loot"
src.Move(usr)
usr<<"You receive [src.name][istype(src,/obj/stack)? "(x[src:amount])":null]"
Drop()
set src in usr
set category = null
src.Move(usr.loc)
usr<<"You drop [src.name][istype(src,/obj/stack)? "(x[src:amount])":null]"
stack
var
amount = 1
quanity=0
proc
edit_amount(n)
src.amount += n
src.suffix = "(x[src.amount])"
src.quanity=src.amount
if(!src.amount)
del src
New(loc,amt=1)
..(loc)
src.amount = amt
Move(a)
if(ismob(a))
var/mob/m = a
var/obj/stack/o = locate(src) in m
if(o)
o.edit_amount(src.amount)
m<<"You receive [src.name] (x[src.amount])"
del src
return ..()
Grab()
var/obj/stack/s = locate(src) in usr
if(s)
s.edit_amount(src.amount)
usr<<"You receive [src.name] (x[src.amount])"
del src
else
return ..()
Drop()
var/n = input(usr,"Drop how many?","Drop: [src.name]",src.amount) as null|num
if(n)
new src.type(usr.loc,n)
src.edit_amount(-n)
verb/Drop_All()
set src in usr
set category = null
src.Move(usr.loc)
usr<<"You drop [src.name] (x[src.amount])"
verb/derp()
for(var/obj/stack/stackable in usr.contents)
if(src.quanity>=3)
usr<<"finally"
else
usr<<"T_T"


Problem description:
I dunno how to add on more items to the thing so it can make a proper crafting system every time i tried to do a && then previous code it doesn't work so how do i make it so it like if you got 4 carrots and 2 oils you can amke stuff

In response to Mastergamerxxx
Check if you have 4 carrots. If you do, continue, if not, break.

If you do have 4 carrots, then check if you have 2 oils. If you do, continue, if not, break.

If you do have 2 oils, that means you have all the requirements for the recipe. Decrease 4 carrots from the carrots, and 2 oils from the oils, and then create a new 'carrot soup' object.


This can be altered to make any recipe you need.
In response to Warlord Fred
I need a code sample of this i do not comprehend how to do this i do not know exactly what format of coding to do this in with this code i have
In response to Mastergamerxxx
Use if() on the quantity variables of the objects involved in the recipe.
I think it would be better to give all items a "quantity" variable, and then decipher between stackable and non-stackable by the value of this variable.
obj/item/var/quantity

obj/item/armor/breast_plate
quantity = -1 //non-stackable

obj/item/weapon/throwing_knives
quantity = 4

Like this, any item with a value of -1 means that it does not stack, which means that all you have to do is check for a variable value rather than the item's type. Less resource intensive. Any items with a value 0 or greater means it stacks. Obviously if it has a 0 value, then it should be deleted, haha