Good news! To provide faster support and grow the community, we'll be changing the forum to "Read Only" and turn to Discord instead for support.
Join here: https://discord.gg/zjNj5zZ

Crafting with fuel (coal)

User avatar
GamingProject
Posts: 15
Joined: Thu Apr 07, 2016 3:34 pm

Crafting with fuel (coal)

Postby GamingProject » Fri Sep 23, 2016 8:21 pm

Hey Devdog,

i was wondering how to craft items like we can do it in minecraft.

Take a campfire or else, putting some coal in to turn the fire on and than we can craft some meat.

how we can do that with inventory pro?

Greetings
;)

User avatar
jjahuijbregts
Site Admin
Posts: 2091
Joined: Wed Apr 22, 2015 7:25 pm
Contact:

Re: Crafting with fuel (coal)

Postby jjahuijbregts » Sat Sep 24, 2016 10:02 am

GamingProject wrote:Hey Devdog,

i was wondering how to craft items like we can do it in minecraft.

Take a campfire or else, putting some coal in to turn the fire on and than we can craft some meat.

how we can do that with inventory pro?

Greetings
;)


All crafting actions are validated using the ICraftingActionValidator; This takes care of checking if the crafting can begin (assume you have all the right items, fuel, etc). Then, there's RemoveRequiredCraftItemsAndCurrency, which obviously removes all items once the craft is completed.

By default the CraftingWindows are the validators, and all methods are marked virtual, so you can easily override these to add in the fuel behavior :)

User avatar
GamingProject
Posts: 15
Joined: Thu Apr 07, 2016 3:34 pm

Re: Crafting with fuel (coal)

Postby GamingProject » Mon Sep 26, 2016 1:14 pm

Great, thank you :)

Jimbob
Posts: 14
Joined: Mon Apr 11, 2016 11:58 pm

Re: Crafting with fuel (coal)

Postby Jimbob » Tue Jul 18, 2017 2:10 pm

This needs to be added, all modern games require fuel for certain crafting stations (ie.. campfire, furnace...)

Jimbob
Posts: 14
Joined: Mon Apr 11, 2016 11:58 pm

Re: Crafting with fuel (coal)

Postby Jimbob » Sun Jul 23, 2017 2:14 pm

Hi first off I must say this system is getting better and better the more I learn about it, for a very long time i've been worried and didn't know how to use a different craft window for different storage boxes or campfires etc... but recently this week found how easy it is, I went thru this forum to find info and happily saw a post from explaining how it works, so simple yet so powerful :D

I'm wondering how to go about adding fuel to a crafting station, I have started to write a script which I hope you or someone can help to make it work, i'm sure it might help a lot of people out too.

Code: Select all

using System;
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
using Devdog.General.ThirdParty.UniLinq;
using Devdog.General;
using Devdog.General.UI;
using Devdog.InventoryPro.UI;
using Devdog.InventoryPro;
using UnityEngine.Assertions;

public partial class Jims_CraftingFuel : CraftingWindowStandardUI
{
   [Header("Craft Station Require Fuel?")]
   public bool RequireFuel = false;

//   [Header("Fuel Settings")]
//   public InventoryItemBase m_FuelType = null; //(item to be used as fuel type, eg.. wood, gas... etc)
//   public InventoryItemBase m_FuelDeposit = null; //(eg.. burning wood will leave charcol)
//   public float FualBurnTime = 30f; //(seconds before fuel depletes)


   protected override void OnCraftButtonClicked()
   {
      if (RequireFuel == false) {
         CraftCurrentlySelectedBlueprint (GetCraftInputFieldAmount ());
      }
      else if (RequireFuel == true) {

         //Debug.Log ("Called Jims On Craft Button, ADD FUEL HERE");

         CraftCurrentlySelectedBlueprint (GetCraftInputFieldAmount ());
      }
   }

}



I've commented out parts which could be included unless you know a better way of doing it :D

Thank you Jim

Jimbob
Posts: 14
Joined: Mon Apr 11, 2016 11:58 pm

Re: Crafting with fuel (coal)

Postby Jimbob » Mon Jul 24, 2017 1:06 am

I MADE IT WORK :D

The way this works is it will enable a bool if you have fuel, and with the bool you can enable the craft button.

The fuel script will remove the fuel item you selected over time (fuelBurnTime) and also add a new item from the depleted fuel (e.g.. burning wood as fuel could give you charcol back)

You can also add particle fx and audio easily.

Code: Select all

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Devdog.General;
using Devdog.InventoryPro;

public class Jims_CraftWithFuel : MonoBehaviour
{
   //Item to be used as a Fuel
   public InventoryItemBase fuelItem = null;
   //e.g.. If wood if the fuel than charcol would be the depleted item
   public InventoryItemBase fuelDepletedItem = null;
   //Collection belongs to
   public ItemCollectionBase m_Collection = null;

   //Temp list to store the total amount of fuel
   //[HideInInspector]
   public int m_fuelItemAmount;

   //Time 1 fuel item lasts for
   public float fuelBurnTime = 10f;
   private float m_fuelBurnTime;

   //If we have fuel then CanCraft = true; //This will be moved to the Crafting Window UI once its working
   [HideInInspector]
   public bool CanCraft = false;


   protected void Awake ()
   {
      m_fuelBurnTime = fuelBurnTime;
   }

   protected void Update ()
   {
      //Check to see if the collection has fuel
      m_fuelItemAmount = m_Collection.FindAll (fuelItem.ID).Length;

      //If we have have fuel than we can craft
      if (fuelItem != null && m_fuelItemAmount >= 1 && fuelBurnTime > 0) {

//         //Start the timer to deplete the fuel over time
         fuelBurnTime -= 1 * Time.deltaTime;

         if (fuelBurnTime <= 0)
            RemoveSomeFuel ();

         //It's true, we can now craft :)
         CanCraft = true;

      } else {

         //We dont have any fuel so we can craft anything :( //Also that particle system you spent ages making can't be seen, come on get some more fuel man!
         CanCraft = false;
      }
   }

   protected void RemoveSomeFuel ()
   {
      //Remove some fuel from the collection
      if (fuelItem != null) {
         uint FuelItemToRemove = m_Collection.RemoveItem (fuelItem.ID, 1);
      }

      //Adds the depleted item burnt from the fuel
      if (fuelDepletedItem != null) {
         m_Collection.AddItem (fuelDepletedItem);
      }

      //Reset Timer
      fuelBurnTime = m_fuelBurnTime;
   }


}

User avatar
PeterBibinin
Posts: 194
Joined: Mon Oct 24, 2016 10:55 pm
Location: Poland
Contact:

Re: Crafting with fuel (coal)

Postby PeterBibinin » Thu Jul 27, 2017 1:08 pm

Nice work :) I need to test this :)

Can you explain how to use this?
Waiting for sunrise
-------------------------------------------
Try make world beter ;]

My Advanced Save System tutorial with screen capture like in The Forest !
Advanced Save System
-------------------------------------------
BAZINGA !



Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest