Jump to content

[Help] Adding new fueltype


Recommended Posts

Thanks. Tried to see if I could be helped by that thread but:

I want my new building to use an already existing item as a new fueltype, an Item that is currently not a fuel - like the cut stone. I don't want to make a new item out of cut stone.

Edit:

Also trying to understand how it works in this thread:

Maybe also this one will help me - will check it out:
https://steamcommunity.com/sharedfiles/filedetails/?id=179602497

Edited by EldVarg
Link to comment
Share on other sites

Hm cant understand how to get it to work. BigMommaWolf, could you show an example please?

 

Im not interested how to increase what items can be used as fuel for an existing fueltype, but to make a completely new type.

Edited by EldVarg
Link to comment
Share on other sites

Define your new fuel type in your modmain.lua:

GLOBAL.FUELTYPE.CUTSTONE = "CUTSTONE"

Then add the fuel type to the prefab you want to use as fuel. For example, if you want to use cutstone as fuel, you need to call AddPrefabPostInit from your modmain.lua:

local function cutstonefuel(inst)
	if not GLOBAL.TheWorld.ismastersim then
		return
	end
	
	inst:AddComponent("fuel")
	inst.components.fuel.fueltype = GLOBAL.FUELTYPE.CUTSTONE	-- assign fuel type
	inst.components.fuel.fuelvalue = GLOBAL.TUNING.MED_LARGE_FUEL	-- assign fuel value, see tuning.lua
end

AddPrefabPostInit("cutstone", cutstonefuel)

Alternatively, if you are making a new item that should be a fuel, place this in your master_postinit for that prefab:

	inst:AddComponent("fuel")
	inst.components.fuel.fueltype = FUELTYPE.CUTSTONE
	inst.components.fuel.fuelvalue = TUNING.MED_LARGE_FUEL

Finally, you'll want a prefab to take this fuel, add this to its master_postinit:

	inst:AddComponent("fueled")
	inst.components.fueled.maxfuel = TUNING.FIREPIT_FUEL_MAX	-- see tuning.lua
	inst.components.fueled.fueltype = FUELTYPE.CUTSTONE
	inst.components.fueled.accepting = true				-- so it takes fuel

or similar code in your modmain.lua if you want to add the fueled component to an existing prefab.

Notes:

  • Both fuel's and fueled's fueltype are initialised to FUELTYPE.BURNABLE, that is, if you don't define fueltype for either of them, it defaults to FUELTYPE.BURNABLE.
  • Prefabs that are used as fuel can only have one fueltype. However, fueled prefabs can take up to two fueltypes, assigning the second type via inst.components.fueled.secondaryfueltype.
  • The fueled component has a certain complexity. Check out the prefab files for Campfires (campfire.lua), Fire Pits (firepit.lua) and endothermic fires (coldfire.lua, coldfirepit.lua) for examples of its usage.
  • All code untested.
Link to comment
Share on other sites

In your mod folder, go to scripts and create a new folder named tools. Download Rezecib's UpvalueHacker tool, save it to a file named upvaluehacker.lua in tools. Add this to your modmain.lua after GLOBAL.FUELTYPE.CUTSTONE = "CUTSTONE":

local UpvalueHacker = GLOBAL.require("tools/upvaluehacker")

local function fuel(inst, doer, target, actions)
	if not (doer.replica.rider ~= nil and doer.replica.rider:IsRiding())
	or (target.replica.inventoryitem ~= nil and target.replica.inventoryitem:IsGrandOwner(doer)) then
		for k, v in pairs(GLOBAL.FUELTYPE) do
			if inst:HasTag(v.."_fuel") then
				if target:HasTag(v.."_fueled") then
					table.insert(actions, inst.prefab == "custone" and GLOBAL.ACTIONS.ADDCUTSTONEFUEL or inst:GetIsWet() and GLOBAL.ACTIONS.ADDWETFUEL or GLOBAL.ACTIONS.ADDFUEL)
				end
				return
			end
		end
	end
end


local COMPONENT_ACTIONS = UpvalueHacker.GetUpvalue(
	GLOBAL.EntityScript.CollectActions,
	"COMPONENT_ACTIONS"
)

COMPONENT_ACTIONS.USEITEM.fuel = fuel



local tp_action = AddAction("ADDCUTSTONEFUEL", "Add cut stone", function(act)
    if act.doer.components.inventory then
        local fuel = act.doer.components.inventory:RemoveItem(act.invobject)
        if fuel then
            if act.target.components.fueled:TakeFuelItem(fuel) then
                return true
            else
                act.doer.components.inventory:GiveItem(fuel)
            end
        end
    end
end)
	
function SetupAddCutstoneFuelActions(inst, doer, actions)
	table.insert(actions, GLOBAL.ACTIONS.ADDCUTSTONEFUEL)
end
AddComponentAction("USEITEM", "ADDCUTSTONEFUEL", SetupAddCutstoneFuelActions)

local ah = GLOBAL.ActionHandler( GLOBAL.ACTIONS.ADDCUTSTONEFUEL, "doshortaction" )
AddStategraphActionHandler("wilson", ah)
AddStategraphActionHandler("wilson_client", ah)

I tried it with logs instead of cut stone while hosting a non-dedicated server and it seemed to work, so if I didn't mess up changing everything to cut stone/cutstone/Cutstone/CUTSTONE, it should work.

Imo definitely not worth the effort.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...