This prefab is the log item obtained by chopping trees.
File: log.lua
Components & Utility Used
- stackable
- inspectable
- inventoryitem
- SoundEmitter
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
local assets= --a table listing the animations and sounds { Asset("ANIM", "anim/log.zip"), --the animation file } local function fn(Sim) --main function local inst = CreateEntity() --makes the instance inst.entity:AddTransform() --give it physical existance inst.entity:AddAnimState()--give it visual existance MakeInventoryPhysics(inst) --behaves like all items inst.AnimState:SetBank("log") --sets the position as in the anim file inst.AnimState:SetBuild("log") --sets the textures from the anim file inst.AnimState:PlayAnimation("idle") --look normal inst:AddComponent("stackable") --can be stacked inst:AddComponent("edible") --this can be eater inst.components.edible.foodtype = "WOOD" --but only by beavers inst.components.edible.woodiness = 10 --wood is quite woody inst:AddComponent("fuel") --it burns in the firepit inst.components.fuel.fuelvalue = TUNING.MED_FUEL --it's burning alright MakeSmallBurnable(inst, TUNING.MED_BURNTIME) --it can burn on its own MakeSmallPropagator(inst) --it spreads fire --------------------- inst:AddComponent("inspectable") --it can be described by the characters inst:AddComponent("inventoryitem") --it can go into containers and the inventory inst:AddComponent("repairer") --you can repair stuff with it inst.components.repairer.repairmaterial = "wood" --it's only good for wooden stuff inst.components.repairer.healthrepairvalue = TUNING.REPAIR_LOGS_HEALTH --it repairs by... that much --the following line has been commented out, probably because it's now handled by the burnable component --inst:ListenForEvent("burnt", function(inst) inst.entity:Retire() end) return inst --you need to pass on instances after making them end return Prefab( "common/inventory/log", fn, assets) --this function makes and shares the prefab |