TEMPLATE NAME: Czinczar's Crafting Component
CORE VERSION: 1.10.3
TEMPLATE VERSION: 1.0.0
This component gives the players of your game the possibility to combine up to 6 different elements and up to 3 different tools in order to produce anything you want. Whether you want your players to combine elements to make a potion, an explosive grenade, or a sandwich, everything is possible !
I am open to suggestions.
I am thinking about :
- a history of what the player has combined, resources used and resources awarded
- better looking UI
TEMPLATE VERSION NOTES:
1.0.0 - Initial release
share your screenshots and/or videos from your template here
If you update this component from CC and you have already made some changes (created your own elements, blueprints, etc..), don't forget to save them before updating !
Don't hesitate to comment if you have used it in your game, or if you plan to use it in your game and you have questions, or if you need help adapting the component to your particular needs.
The READ_ME file that can be found inside the Crafting folder contains all the information you need in order to get started making your own elements and blueprints.
Here is a copy of it :
Czinczar's Crafting Component v1.0
Welcome ! This crafting component is made by Czinczar. If you have questions or suggestions, find me on the discord.
(To avoid getting an error about persistent storage not being enabled, select the "Game Settings" object in your hierarchy and check "Enable Player Storage" in the properties panel)
This crafting component is made up of 3 important categories : elements, tools and blueprints.
A blueprint is a list of at least 1 element and 1 tool that are needed to make the result of a blueprint. A maximum of 3 tools can be required and a maximum of 6 crafting elements. Thus you can have a blueprint that combines just 2 crafting elements together without any tool, or you can have 1 crafting element and 1 tool that can be combined.
This component comes with a workbench that is made of a trigger, some scripts and a geometry folder. Feel free to modify the appearance of the workbench or to replace it totally. In the workbench root, there are custom properties to help you adjust the position and the rotation of the camera if you need it. You can take out the Workbench folder outside of the Crafting folder then duplicate it and place the copies wherever you want in your game.
Usually, you would want the players to discover the blueprints by themselves, by combining elements together(or you can just give them the information through other means, as a quest reward for example), but if you want your players to know blueprints at the start of the game, that is to say, for the blueprints to appear in the known blueprints panel when they join the game, you can check the "Known_at_Start" checkbox in the properties of your blueprint.
This component works for multiplayer. For now, only one player can use a workbench at a time. This might change in the future.
Persistent player storage is enabled by default. You can disable it by selecting the root folder of the component and unchecking the corresponding checkbox. It saves 3 things : elements, tools, and a list of known blueprints. I have tried as much as I can to reduce the size of saved data. While testing and working on your game, it might help you to disable persistent player storage as you will never run out of ingredients given by "Starting Resources Server Script".
Icons are optional. If you don't provide an icon, the element or tool will just be represented by its name on the crafting ui.
This component uses player resources to store elements and tools. Elements start with "Crafting_" and tools start with "Tool_", so make sure you don't have other player resources unrelated to this crafting component which might have these words in their name.
To give elements or tools to players, just type "player:AddResource("Crafting_Your Element", 5)" in any of your server scripts.
You can, if you want, totally ignore the tools part of this component : make sure none of the blueprints require a tool then find "Tools UI Panel" and hide it. Don't delete it as this would mess with the script. Hide it then resize the rest of the UI so that only elements and blueprints panels are displayed.
Many default sounds can be changed. Look into the "Audio" folder in the client context, there you will find folders which contain multiple
sound assets. These sound assets are all played at the same time. This makes it easy to create a sound which is made of many different sounds/layers.
Quick combine guide for the example blueprints :
- hammer + metal scraps = 2 nails
- hammer + nails + wood = wooden barricade
- hammer + screwdriver + wood + nails + metal scraps + screws = reinforced barricade
To add a new element, follow these steps.
- Open the "Elements" folder and inside it, pick any already existing element and duplicate it.
- Give it a unique name, for example "Crafting_Bolts".
- Look into the custom properties of this newly created element.
- In the "UniqueElementID" custom property, give it a unique ID number.
- Find an icon that you like and drag&drop it to replace the asset in the "ImageIcon" custom field.
- Add a 3d asset to represent the ingredient. Just drag&drop a template into the "3dAsset" custom field.
- In the "ScaleOf3dAsset" field, type a float number by which the scale of the 3d asset will be multiplied.
You will have to test in preview mode to find the best value for your particular 3d asset so that it fits
well on the workbench and isn't too big or too small.
- If you wish, you can provide a sound asset in the "UseSound" custom field that will be played when
this element is put on the workbench. If no sound asset is provided, the default sound will be played.
To add a new tool to the system, follow these steps:
- Open the "Tools" folder and inside it, pick any already existing tool and duplicate it.
- Give it a unique name, for example "Tool_Pliers"
- Look into the custom properties of this newly created tool
- Give it a unique Id in "UniqueToolID" field.
- Choose an asset icon that will be displayed in the UI and drag&drop it in the "ImageIcon" field
- Choose a sound asset that will be played when this tool is selected on the crafting UI.
To create a new blueprint, follow these steps :
- Open the "Blueprints" folder and inside it, pick any already existing blueprint and duplicate it.
- Give it a unique name, starting with "Blueprint_".
- Look into the custom properties of this newly created blueprint and give it a unique ID.
If you want your blueprint to be known by the player when he/she joins the game, check
the "Known_at_Start" checkbox.
- Decide how many elements this blueprint requires and if it also requires tools or not.
- If this blueprint doesn't require any tool, set "NumberOfToolsRequired" to zero.
- If it requires one or more tools, set "NumberOfToolsRequired" accordingly then add custom fields
named "ToolRequired" with a number at the end : "ToolRequired1", etc..
- For the elements, set "NumberOfElementsRequired" to the number of elements this blueprint will require.
- Add custom fields named "NeededElement" with a number at the end : "NeededElement1", etc..
- In the "ResultResource" custom field, you need to type the name of the player resource
that will be rewarded to the player when this blueprint is completed. This can be anything you
want to give to the player. For example if in your game there are grenades and this blueprint
is about making grenades, then type here the name of the resource that is used in your game to
represent grenades. But this can also be just another crafting element starting with "Crafting_".
Look at "Blueprint_Nails" for an example : it gives 2 "Crafting_Nails".
- In the "ResultResourceAmount" field, type the amount of the player resource given to the player.
- In the case this blueprint just gives another Crafting_ element, its 3dAsset
will be fetched from the Elements folder. Otherwise, you need to provide a 3dAsset and a scale factor.
Just drag&drop a template in the 3dAsset custom field and type a float number in "ScaleOf3dAsset".
Then preview the game and adjust the scale factor as needed.
You can give starting resources to every player that joins your game for the first time. If persistent player storage is not enabled, these resources will be given every time a player joins the game. If persistent player storage is enabled, these resources
will be given to every player that joins the game but only once.
- Find "Starting Resources Server Script" inside the "Server Stuff" folder and look at the custom properties.
- You can add here any number of INT custom properties to give starting crafting elements or tools to the joining player.
Since custom properties here do not accept blank spaces, replace blank spaces by "XYZ".
- If you do not want to give any starting resources to joining players, just uncheck "Enabled".
Persistent player storage works as it is, but since storage is limited to 16k, having tons of different elements and tools and a pretty long list of known blueprints could eat these 16k pretty quickly. Everything is saved as a string but even then it grows fast enough.
I think it would become a real problem with a loooot of things to save and also if your game also saves a lot of its own data.
- Don't forget to check "Enable Player Storage" on the "Game Settings" object to enable persistent storage for your game.
- Improve the UI
- Improve the display of 3d templates
Thanks to Nicholas Foreman for EaseUI.
I have taken some models from the survival kit, so thanks to whoever did those.