Jump to content

Recommended Posts

Hello, i am trying to make a mod which makes you able to use torches as fuel for campfires but i don't really know what i'm doing. I tried something but it just crashes the game so i'm wondering if anyone could help me. The lines i have ''written'' (copy & pasted from the game files and some other mods and editted a little) in the modmain file are as following : 

local fire_prefab = { 
    --Standard game firepits
    'firepit', 
    'campfire', 
    'coldfire', 
    'coldfirepit',
function ignite
	    inst.replica.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
		if item and item.prefab=="torch" then
			inst:AddComponent("fuel")
    inst.components.fuel.fueltype = "TORCH"
    inst.components.fuel.fuelvalue = TUNING.SMALL_FUEL

--item to be fueled:--
local function
inst:AddComponent("fueled")
    inst.components.fueled.accepting = true
    inst.components.fueled.fueltype = "TORCH"
    inst.components.fueled:InitializeFuelLevel(TUNING.CAMPFIRE_FUEL)
			return
		end
	end

Thanks in advance.
 

Lots of things wrong here. Normally I'd list the things, but there are just too many. The syntax is all up in flames on this one, and half the code is about making the torch fueled, not make it work as a burnable fuel. From your code and by your own admission, you have no idea how LUA works, so it wouldn't really help, anyway. Sorry if that sounds harsh, but it's just the truth, m8 :)

But I will help you, because that's what we do here. If you want to get into modding, I suggest you meticulously go through my newcomer post, and spend some time studying the simple mods in there, AFTER taking the LUA Crash Course.

What you're trying to do is really simple, so I'll leave the complete code in a spoiler here, so you can either just copy/paste it and never look back, or you can look at the newcomer post and learn how to do it yourself, and then check the spoiler to see if you got to the same solution as I did.

Good luck in your ventures, m8 :D Modding is fun and rewarding, so I hope you take the long road, and join us on the other side. We'll be here if you need us.

Spoiler

Simplest version:


AddPrefabPostInit("torch", function(inst)
	if not inst.components.fuel then
		inst:AddComponent("fuel")
		inst.components.fuel.fuelvalue = TUNING.SMALL_FUEL
	end
end)

This next version will allow you to make more non-fuel items into fuel, by simply adding the prefab name to the list.


local prefabs_to_make_into_firepit_fuel = { 
    'torch',
}

for i, v in ipairs(prefabs_to_make_into_firepit_fuel) do
	AddPrefabPostInit(v, function(inst)
		if not inst.components.fuel then
			inst:AddComponent("fuel")
			inst.components.fuel.fuelvalue = TUNING.SMALL_FUEL
		end
	end)
end

 

 

Edited by Ultroman

I read the LUA crash course but i still have some questions.
1. What does "inst" mean? (install?)

2. What does "init" mean? (initialize?)

3. How do i make it so you can only use the torch as fuel when you are holding a specific item? (preferably another torch)

Thanks in advance.
 

  1. inst <=> instance
    The game has prefabs. There is a "torch" prefab, which defines a torch. When you spawn a torch, you create an "instance" of the torch using the prefab. Think of prefab as a blueprint and instance as the product of building a thing using that blueprint.
  2. Yes
  3. That's a bit more difficult, because having the fuel component on an item automatically makes it always be fuel for anyone holding it. You'd have to do something like extending the TakeFuelItem function on the fueled component of all the things accepting the BURNABLE fueltype, and do a check on the doer's HANDS equipslot to see if they are holding a torch, and if not, you return false immediately, without running the original function.

thanks again.

I have one more question.

I tried to make it possbile to ignite a firepit with a torch, but it doesn't seem to work ingame. I was wondering if you could maybe check it out.

AddPrefabPostInit("firepit", function(inst)
	if not inst.components.burnable then
	    inst:MakeSmallBurnable(inst, TUNING.SMALL_BURNTIME)
	
	    
	end
end)

Thanks in advance (again),

If you'd want a torch to ignite the firepit, you wouldn't want to change the firepit, you'd change the torch. Try this:

AddPrefabPostInit("torch", function(inst)
    inst.components.burnable.canlight = true
end)

 

Edited the code. This should work.

Edited by Ultroman

Yeah, I see. Let me see. It should be enough just to make it fuel. All the ignite-stuff is on the firepit...

I don't know what the problem is. Torches can ignite my firepit when I use the original code here

AddPrefabPostInit("torch", function(inst)
	if not inst.components.fuel then
		inst:AddComponent("fuel")
		inst.components.fuel.fuelvalue = TUNING.SMALL_FUEL
	end
end)

 

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
×
  • Create New...