Craft Pro

by Red Hall Dev
The definitive crafting demo.
ID:1886656
 
Craft Pro Description

Craft Pro is a freely available resource that makes crafting as easy as possible. There's a lot of documentation but the basics are very simple and there's a nice demo of everything so you can see how it all works.

Post any questions you have in Discussion.

It's made of 3 parts:

    Crafting Code (Crafting.dm)
Inventory Code (Inventory.dm)
Demo Files (/Demo)


You may wish to substitute in your own inventory code but you may very well find that you just want to use this inventory code instead.

Documentation

Crafting:
/*

atom
- components
A list of each component required to make the atom


- craftedAt
A list of each station a player must be within 1 tile of to
craft the atom

- tools
A list of each tool required to be in the inventory of the
player to craft the atom

obj/Item

- list/componentof
A list of everything you can create with this.
Leave it blank if you don't want to be able to craft an
item from your inventory

- Craft()
This is a proc that will be used as a verb if the item can
be crafted into something within the inventory. In other
words when componentof contains something

- New()
Add the ability to craft from the inventory if they are the
component of something

mob
- craft(atom/SOMETHING)
Attempt to craft said atom. Works when called from anywhere

atom
- canCraft()
On it's own will check for tools and crafting stations.
You can refine it and add your own skill checks or
whatever you like

- whileCrafting()
Redefine this to whatever you like. It will be called the
moment before successfully crafting something

- findComponents()
You won't ever need this or need to edit it. It finds all
components a player has which are needed and then returns
a list of each item associated with how much of it will be
used. It's a helper method for craft(SOMETHING)
*/

Inventory:
/*
mob
- inventorySlots
- inventorySlotsUsed

- spaceError()
The typical error message for when max space is reached. Used by
Inventory.dm and Crafting.dm

- spaceLeft()
Returns how much space is left in the inventory

- spaceFor(OBJECT)
Returns yes if there's enough space in the inventory for an object.
Including if the object is a stack.

- getObject(OBJECT, AMOUNT)
Probably one of the most important aspects of inventories is
controlling what happens when you attempt to get something (add it
to your inventory).

This lets you get some AMOUNT of some OBJECT. You may not pick it all
up if it stacks. But it will do its best to get what you ask without
breaking any stacking rules.

- loseObject(OBJECT, AMOUNT)
Probably one of the most important aspects of inventories is
controlling what happens when you attempt to drop something (remove it
from your inventory to move it to another location).

This lets you lose some AMOUNT of some OBJECT and move it to some
LOCATION. You may not pick it all up if it stacks. But it will do its
best to get what you ask without breaking any stacking rules.

obj/Item

An item is anything that can be picked up.

- amount
The number of units of this item. (50 stones)

- stackable
This object can represent more than 1 unit at
a time.

- stackSize
The maximum number of units that an object can
represent

- New()
Update suffix alteration made to default New()

- Del()
Make sure to update the inventory of whatever this Item is in
when it's deleted.

- setAmount()
Directly set the amount (updates the suffix)

- addAmount()
Add to this item's amount (Use carefully, you can accidently
add more units than the item can represent. You might be
looking for getObject() loseObject() instead which will
never let you add more than is available

- removeAmount()
Remove from this item's amount (Use carefully, you can accidently
add more units than the item can represent. You might be
looking for getObject() loseObject() instead which will
never let you add more than is available

- updateSuffix()
Set the suffix equal to the amount of units the item has. This
is what makes the inventory display the amount

- Pick_Up()
A verb to pick up all units of the object

- Drop()
A verb to drop all units of the object

- Pick_Up_Amount(AMOUNT)
A verb to pick up only AMOUNT units of the item

- Drop_Amount(AMOUNT)
A verb to drop only AMOUNT units of the item
*/
Awesome!!!
Great stuff now i can finally have a good crafting system
Just wanted to note that the popcorn can be made without standing within one tile of the microwave. Is that a bug or intentional?
In response to Ubiquity Entertainment
Ubiquity Entertainment wrote:
Just wanted to note that the popcorn can be made without standing within one tile of the microwave. Is that a bug or intentional?

Hmm, I tried it and I wasn't able to. How exactly were you doing this?
Okay, now I understand how I can explain this further. After playing around with it a little more I've realized that there is a verb named "Make Popcorn" when you rightclick the microwave while standing next to it. This works fine as it should.

The problem lies in the verb "Craft" which is attached to the Kernals object. By rightclicking the object in my inventory I can change the Kernals into Popcorn using "Craft" bypassing the need for the Microwave object.

**Edit**

Looks like you forgot to add:

craftedAt = list(/obj/Station/Microwave)

To the bottom of the Popcorn obj code.

Popcorn
icon_state = "Popcorn"
components = list(/obj/Item/Kernals = 1)
In response to Ubiquity Entertainment
Thank you! Easy fix.

    Kernals
icon_state = "Kernals"
stackable = 1
stackSize = 20
componentof = list(/obj/Item/Popcorn)

becomes

    Kernals
icon_state = "Kernals"
stackable = 1
stackSize = 20


My bad. Componetof is only there if you want to be able to craft from you inventory. Otherwise there's no need for an object to know what it can be crafted into.
In response to Ubiquity Entertainment
I will update it in a moment.