Foxrai Posted February 12, 2015 Share Posted February 12, 2015 Hello, The thing I need is simple for many of you I guess. But I checked campfire.lua, torch.lua and I'm not really sure WHAT exactly I need - they just look complicated :/ Goal is: Item, which is placed on the ground. And after sometime it's burning out and turning into ash. No cooker option, no ignite. Just it's standing on the ground and after sometime it's gone. I guess it's something to do with extinguish option.. But can't really figure out what. Also how do I know how long it will last before it's gone? Link to comment Share on other sites More sharing options...
Corrosive Posted February 12, 2015 Share Posted February 12, 2015 Check out burnable.lua. The reason that it's difficult to figure out how campfire extinguishes is because it's also fueled, and so it wont necessarily burn for a set amount of time. Instead, it needs to check for when it runs out of fuel and THEN extinguish. When it extinguishes, it has to remove a few components, play the extinguish animation, then remove itself. Yours is much more simple. All you should need to do is add the burnable component, and specify the features you want. There's some built-in functions to automatically add the basics to burnable objects: MakeSmallBurnable/MakeMediumBurnable/MakeLargeBurnable. Here's what those do, for reference (note: you do not need to include this in your code, this is already in standard_components.lua)function MakeMediumBurnable(inst, time, offset, structure) inst:AddComponent("burnable") inst.components.burnable:SetFXLevel(3) inst.components.burnable:SetBurnTime(time or 10) inst.components.burnable:AddBurnFX(burnfx.generic, offset or Vector3(0, 0, 0) ) inst.components.burnable:SetOnIgniteFn(DefaultBurnFn) inst.components.burnable:SetOnExtinguishFn(DefaultExtinguishFn) if structure then inst.components.burnable:SetOnBurntFn(DefaultBurntStructureFn) inst.components.burnable:MakeDragonflyBait(2) else inst.components.burnable:SetOnBurntFn(DefaultBurntFn) endendThe MakeBurnable functions automatically add a few generic features to your prefab, such as self-removal and spawning ash when the fire is complete. Whether or not you choose to use the MakeBurnable functions is up to you. In either case, you'll still have to add the additional functionality that you desire. One last note-- extinguish differs from onburnt in that onburnt is triggered when the item burns to completion. If you had, for example, an ice flingomatic nearby, it would extinguish the item before it was completely burnt. It's also up to you to decide how to handle what happens in this situation. (programming sure teaches lessons in being thorough Link to comment Share on other sites More sharing options...
Foxrai Posted February 12, 2015 Author Share Posted February 12, 2015 One last note-- extinguish differs from onburnt in that onburnt is triggered when the item burns to completion. If you had, for example, an ice flingomatic nearby, it would extinguish the item before it was completely burnt. It's also up to you to decide how to handle what happens in this situation. (programming sure teaches lessons in being thorough So I take it as I only add something like: function MakeMediumBurnable(inst, time, offset, structure)(or small or large). And it will add the "life time" to my item and that it will burn into ash after the timer is up. So this: function MakeMediumBurnable(inst, time, offset, structure) Adds this to my item: inst:AddComponent("burnable")inst.components.burnable:SetFXLevel(3)inst.components.burnable:SetBurnTime(time or 10)inst.components.burnable:AddBurnFX(burnfx.generic, offset or Vector3(0, 0, 0) )inst.components.burnable:SetOnIgniteFn(DefaultBurnFn)inst.components.burnable:SetOnExtinguishFn(DefaultExtinguishFn)if structure theninst.components.burnable:SetOnBurntFn(DefaultBurntStructureFn)inst.components.burnable:MakeDragonflyBait(2)elseinst.components.burnable:SetOnBurntFn(DefaultBurntFn)endend So the question is - How can I change the SetBurnTime if I don't rewrite all of this to the code? (I guess it's something with SMALL and LARGE). But is there any way to set time in manually? Link to comment Share on other sites More sharing options...
Corrosive Posted February 12, 2015 Share Posted February 12, 2015 So I take it as I only add something like: function MakeMediumBurnable(inst, time, offset, structure) Not exactly. (note: you do not need to include this in your code, this is already in standard_components.lua) This use of functions seems like a common point of confusion, cause it keeps popping up here. Essentially, the function keyword tells the lua engine that what is about to follow is a function definition. A function definition creates a variable with the name of the function, and stores your function in it. This would define a function with 4 parameters:function a_cool_function(parameter1, parameter2, parameter3, parameter4) --function bodyendNote that the words "parameter" and "argument" are often used interchangeably, however, strictly defined, a parameter is what a function is defined to accept, while an argument is what actually gets passed to the function. This would call(fancy word for "use") that function:argument1 = "I'm just a string"a_cool_function(argument1, 30, "another string")We have just sent our function 3 arguments. When our function is called like this, lua automatically sets the function's parameter# variables behind the scene. Although you don't see it directly, it internally changes your function to look something like this*: local parameter1 = argument1 local parameter2 = 30 local parameter3 = "another string" local parameter4 = nil --function body* This isn't exactly what's happening, but that's far beyond the scope of this explanation. I hope this clears up functions for you at least a little bit. Anyway, back on track! As I mentioned, you don't have to add the function, since it is already defined in standardcomponents.lua. You only need to call it and pass your prefab as an argument. Your prefab's initialization function might contain the following:-- I normally like to name this function something a bit more descriptive than "fn" but that seems to-- be the standard, so I don't want to cause confusion.local function fn(Sim) local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() ...(etc, etc)... -- THIS IS NOT A COMPLETE PREFAB! You still need to configure your animations and such. -- Add some basic burnable functionality. This passes "30" as the burn time. MakeMediumBurnable(inst, 30, nil, true) -- Makes the item "uncontrolled" when burning, and able to catch other items on fire MakeSmallPropagator(inst) -- Anything you wish to tweak in the burnable or propagator components, -- you may do from this point on. inst.components.burnable.SetFXLevel(3) -- MORE FIRE! FX level recommended by Willow. return instend Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.