Overreactedosbol Posted June 27, 2015 Share Posted June 27, 2015 Hi there, recently I've been having an issue concerning my custom 'furnace'. I wanted it to smelt ores and for this I created two new components similar to cooker and cookable, named smelter and smeltable. After that I added the components to the respective items and structure but in-game I dont have the option to 'smelt' my ores when standing close to the furnace. Any help on this problem? smelter.lua (located in scripts/components)local Smelter = Class(function(self, inst)self.inst = inst inst:AddTag("smelter")end) function Smelter:onremoveFromEntity()self.inst:Removetag("smelter")end function Smelter:isSmeltable(item, owner)return item ~= niland item.components.smeltable ~= nilend function Smelter:SmeltItem(item, owner)if self:isSmeltable(item, owner) thenlocal newitem = item.components.smeltable:Smelt(self.inst, owner) if self.onsmeltitem ~= nil then self.onsmeltitem(item, newitem) end if self.inst.SoundEmitter ~= nil then self.inst.SoundEmitter:PlaySound("dontstarve/wilson/cook") end if self.onsmeltfn ~= nil thenself.onsmeltfn(self.inst, newitem, owner)end item:Remove() return newitem endend return Smelter smeltable.lua (located in scripts/components)local Smeltable = Class(function(self, inst) self.inst = inst self.product = nil self.onsmelted = nil inst:AddTag("smeltable")end)function Smeltable:OnRemoveFromEntity() self.inst:RemoveTag("smeltable")endfunction Smeltable:SetOnSmeltedFn(fn) self.onsmelted = fnendfunction Smeltable:Smelt(smelter, owner) if self.onsmelted ~= nil then self.onsmelted(self.inst, smelter, owner) end if self.product ~= nil then local prod = SpawnPrefab( type(self.product) ~= "function" and self.product or self.product(self.inst, smelter, owner) ) if prod ~= nil then return prod end endendreturn Smeltable copperore.lua (one of the ores, located in scripts/prefabs)-- Asset defining (required)local Assets = { Asset("ANIM", "anim/copperore_anim.zip"), Asset("ATLAS", "images/inventoryimages/copperore.xml")}-- Prefab creation/customization (returns intsance)local function fn(Sim)-- Entity creation and transformations local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() MakeInventoryPhysics(inst) -- Animation handler? inst.AnimState:SetBank("copperore") inst.AnimState:SetBuild("copperore_anim") inst.AnimState:PlayAnimation("idle", true) inst:AddTag("smeltable") inst:AddTag("molebait") inst:AddTag("renewable") inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end inst:AddComponent("inventoryitem") inst.components.inventoryitem.atlasname = "images/inventoryimages/copperore.xml" inst:AddComponent("inspectable") inst:AddComponent("smeltable") inst.components.smeltable.product = "copperingot" inst:AddComponent("stackable") inst.components.stackable.maxsize = TUNING.STACK_SIZE_SMALLITEM return instend-- Name and descriptionSTRINGS.NAMES.COPPERORE = "Copper Ore"STRINGS.CHARACTERS.GENERIC.DESCRIBE.COPPERORE = "Maybe I can refine this."STRINGS.CHARACTERS.WOLFGANG.DESCRIBE.COPPERORE = "Is rock, but different."STRINGS.CHARACTERS.WAXWELL.DESCRIBE.COPPERORE = "Hmmm. Now what do I do with this?"STRINGS.CHARACTERS.WATHGRITHR.DESCRIBE.COPPERORE = "A pile of ancient gravel."STRINGS.CHARACTERS.WEBBER.DESCRIBE.COPPERORE = "What are we supposed to do with this?"STRINGS.CHARACTERS.WENDY.DESCRIBE.COPPERORE = "Oh, look what we got from mere destruction."STRINGS.CHARACTERS.WICKERBOTTOM.DESCRIBE.COPPERORE = "A pile of gravel, mixed with traces of metal."STRINGS.CHARACTERS.WILLOW.DESCRIBE.COPPERORE = "Maybe I can burn this."STRINGS.CHARACTERS.WOODIE.DESCRIBE.COPPERORE = "All busted up."STRINGS.CHARACTERS.WX78.DESCRIBE.COPPERORE = "I WILL REFINE THESE INTO HIGH TECHNOLOGY"-- Return prefab with costumization (ESSENTIAL)return Prefab("common/inventory/copperore", fn, Assets) furnace.lua (located in scripts/prefabs, NOTE: I know it doesnt accept fuel or behave like a campfire, im planning on implementing it.)require "prefabutil"require "recipe"require "modutil"local assets={ Asset("ANIM", "anim/furnace_anim.zip"), Asset("ATLAS", "images/inventoryimages/furnace.xml"), Asset("IMAGE", "images/inventoryimages/furnace.tex"),}local function onhammered(inst, worker) inst.components.lootdropper:DropLoot() inst.SoundEmitter:PlaySound("dontstarve/common/destroy_stone") inst:Remove()endlocal function ontakefuel(inst) inst.SoundEmitter:PlaySound("dontstarve/common/fireAddFuel")endlocal function onbuilt(inst) inst.AnimState:PlayAnimation("place") inst.AnimState:PushAnimation("idle", false) inst.SoundEmitter:PlaySound("dontstarve/common/fireAddFuel")endlocal function fn() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddSoundEmitter() inst.entity:AddMiniMapEntity() inst.entity:AddNetwork() MakeObstaclePhysics(inst, 1) inst.AnimState:SetBank("furnace") inst.AnimState:SetBuild("furnace_anim") inst.AnimState:PlayAnimation("idle", false) inst:AddTag("structure") local minimap = inst.entity:AddMiniMapEntity() minimap:SetIcon( "furnace.tex" ) minimap:SetPriority(1) inst:AddTag("smelter") inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end inst:AddComponent("smelter") inst:AddComponent("lootdropper") inst:AddComponent("inspectable") inst:AddComponent("workable") inst.components.workable:SetWorkAction(ACTIONS.HAMMER) inst.components.workable:SetWorkLeft(4) inst.components.workable:SetOnFinishCallback(onhammered) inst:ListenForEvent("onbuilt", onbuilt) return instendSTRINGS.NAMES.FURNACE = "Furnace"STRINGS.RECIPE_DESC.FURNACE = "Smelts ores."STRINGS.CHARACTERS.GENERIC.DESCRIBE.FURNACE = "I can't cook food in this one..."return Prefab( "common/furnace", fn, assets, prefabs), MakePlacer( "common/furnace_placer", "furnace", "furnace", "idle" ) PS: The furnace placer doesnt show a 'green outline' like the regular structures when you craft them, any idea to fix it?PS: Is there a way to make the furnace emit light based on its fuel level? (Campfire adds it with the flame particle based on its 'section') Help is greatly appreciated. Link to comment https://forums.kleientertainment.com/forums/topic/55708-custom-smelting-not-doing-anything/ Share on other sites More sharing options...
przemolsz Posted June 27, 2015 Share Posted June 27, 2015 @Overreactedosbol, For the green outline, change:MakePlacer( "common/furnace_placer", "furnace", "furnace", "idle" ) toMakePlacer( "common/furnace_placer", "furnace_anim", "furnace", "idle" ) The second argument of this function is animation bank name. For the smelting action, you need to add this in your modmain:local smeltable = function(inst, doer, target, actions) if target:HasTag("smelter") then table.insert(actions, ACTIONS.SMELT) end endAddComponentAction("USEITEM", "smeltable", smeltable)The "smeltable" function will be called every time you hover something with your cursor while holding a "smeltable" item. Link to comment https://forums.kleientertainment.com/forums/topic/55708-custom-smelting-not-doing-anything/#findComment-650392 Share on other sites More sharing options...
Overreactedosbol Posted June 28, 2015 Author Share Posted June 28, 2015 Thanks! I knew it had something to do with it having to be registered in the modmain.lua, but now it crashes.Seemingly, lua can't find ACTIONS.SMELT, do I need to define it somewhere? (This is my interpretation from the crash log.) 00:00:52]: [string "../mods/industrial/modmain.lua"]:59: attempt to index global 'ACTIONS' (a nil value)LUA ERROR stack traceback:../mods/industrial/modmain.lua:59 in (local) collector (Lua) <57-61>inst = 111587 - copperore(LIMBO) (valid:true)doer = 110988 - willow (valid:true)target = 108345 - furnace (valid:true)actions = table: 0CDC4338scripts/componentactions.lua:920 in (method) CollectActions (Lua) <897-929>self (valid:true) =modactioncomponents = table: 3950E598Transform = Transform (143A47B8)inlimbo = trueparent = 110988 - willow (valid:true)event_listening = table: 3950C770actioncomponents = table: 3950A290lower_components_shadow = table: 3950A330entity = Entity (390E90F0)AnimState = AnimState (143A47D8)prefab = copperorePhysics = Physics (143A47F8)event_listeners = table: 3950C450spawntime = 0.033333335071802name = Copper Orereplica = table: 3950A470GUID = 111587components = table: 3950A358persists = truetype = USEITEMarg = nilt = table: 0D4628A0modname = industrialmodtable = table: 3950E6B0i = 1v = 1collector = function - ../mods/industrial/modmain.lua:57scripts/components/playeractionpicker.lua:83 in (method) GetUseItemActions (Lua) <80-86>self =map = Map (2793B478)containers = table: 2C4C6068inst = 110988 - willow (valid:true)actionfilter = function - scripts/prefabs/player_common.lua:475target = 108345 - furnace (valid:true)useitem = 111587 - copperore(LIMBO) (valid:true)right = trueactions = table: 0CDC4338scripts/components/playercontroller.lua:2495 in (method) GetItemUseAction (Lua) <2486-2503>self =predictionsent = falsecontroller_target_age = 0draggingonground = falsehandler = table: 39A93D30highlight_guy = 108345 - furnace (valid:true)inst = 110988 - willow (valid:true)remote_vector = (0.00, 0.00, 0.00)classified = 110989 - player_classified (valid:true)controller_target = 108345 - furnace (valid:true)controller_attack_target = 111947 - robin (valid:true)map = Map (2793B478)directwalking = truelocomotor = table: 1F6E1338time_direct_walking = 0.066666670143604ismastersim = truepredictwalking = falsemousetimeout = 10dragwalking = falsedeploy_mode = falseremote_controls = table: 2C509A78active_item = 111587 - copperore(LIMBO) (valid:true)target = 108345 - furnace (valid:true)scripts/widgets/inventorybar.lua:643 in (method) UpdateCursorText (Lua) <601-775>self =hudcompass = Hud Compassshown = trueactionstringtitle = Text - Copper Orecursor = Image - images/hud.xml:slot_select.texrebuild_pending = falsebg = Image - images/hud.xml:inventory_bg.texenabled = truein_pos = (0.00, 102.00, 0.00)actionstringtime = 8.116608787328root = rootbgcover = Image - images/hud.xml:inventory_bg_cover.texinv = table: 39C2AAA0name = Inventoryfocus_flow = table: 2C656A20toprow = toprowout_pos = (0.00, 68.00, 0.00)autoanchor = WorldResetTimercallbacks = table: 2C655D50inst = 111055 - (valid:true)focus = falseequip = table: 39C2AAF0children = table: 2C655AD0current_list = table: 39C2AAA0focus_flow_args = table: 2C656BB0focus_target = falsereps = 0selected_scale = 0.8openhint = Text - Šowner = 110988 - willow (valid:true)actionstring = actionstringbottomrow = toprowequipslotinfo = table: 2C656F98parent = bottom_scale_rootbase_scale = 0.6active_slot = ItemSlotbackpackinv = table: 39C2AB18hint_update_check = 0.51661975495517repeat_time = 0actionstringbody = Text - Ž Inspect‹ Dropinv_item = 111587 - copperore(LIMBO) (valid:true)active_item = nilcontroller_id = 17is_e[00:00:52]: [string "../mods/industrial/modmain.lua"]:59: attempt to index global 'ACTIONS' (a nil value)LUA ERROR stack traceback:../mods/industrial/modmain.lua:59 in (local) collector (Lua) <57-61>scripts/componentactions.lua:920 in (method) CollectActions (Lua) <897-929>scripts/components/playeractionpicker.lua:83 in (method) GetUseItemActions (Lua) <80-86>scripts/components/playercontroller.lua:2495 in (method) GetItemUseAction (Lua) <2486-2503>scripts/widgets/inventorybar.lua:643 in (method) UpdateCursorText (Lua) <601-775>scripts/widgets/inventorybar.lua:859 in (method) UpdateCursor (Lua) <787-860>scripts/widgets/inventorybar.lua:322 in (method) OnUpdate (Lua) <271-352>scripts/frontend.lua:594 in (method) Update (Lua) <460-609>scripts/update.lua:93 in () ? (Lua) <39-123>[00:00:52]: SCRIPT ERROR! Showing error screen[00:00:53]: stack traceback:scripts/widgets/widget.lua:276 in (method) SetPosition (Lua) <271-280>scripts/widgets/followtext.lua:45 in (method) OnUpdate (Lua) <37-47>scripts/frontend.lua:594 in (method) Update (Lua) <460-609>scripts/frontend.lua:642 in (method) PushScreen (Lua) <620-647>scripts/frontend.lua:753 in (method) ShowScreen (Lua) <750-755>scripts/frontend.lua:808 in (method) DisplayError (Lua) <804-817>scripts/mainfunctions.lua:931 in () ? (Lua) <909-964>[00:00:58]: Force aborting... and here's line 59 of my modmain.lua:57: local smeltable = function(inst, doer, target, actions)58: if target:HasTag("smelter") then59: table.insert(actions, ACTIONS.SMELT)60: end61: end62: AddComponentAction("USEITEM", "smeltable", smeltable) Link to comment https://forums.kleientertainment.com/forums/topic/55708-custom-smelting-not-doing-anything/#findComment-650471 Share on other sites More sharing options...
Seiai Posted June 28, 2015 Share Posted June 28, 2015 @Overreactedosbol, GLOBAL.ACTIONS.SMELT Link to comment https://forums.kleientertainment.com/forums/topic/55708-custom-smelting-not-doing-anything/#findComment-650477 Share on other sites More sharing options...
Overreactedosbol Posted June 28, 2015 Author Share Posted June 28, 2015 Well, I don't think it's working, because I still only get the options 'inspect' and 'drop', no 'smelt' when i stand near my furnace, I really don't know what i did wrong. Link to comment https://forums.kleientertainment.com/forums/topic/55708-custom-smelting-not-doing-anything/#findComment-650483 Share on other sites More sharing options...
przemolsz Posted June 28, 2015 Share Posted June 28, 2015 Seemingly, lua can't find ACTIONS.SMELT, do I need to define it somewhere?You're right, I didn't notice you hadn't had it in the first place. That's how you do it:AddAction("SMELT", "Smelt", function(act) if act.target.components.smelter ~= nil then local smelt_pos = act.target:GetPosition() local ingredient = act.doer.components.inventory:RemoveItem(act.invobject) local product = act.target.components.smelter:SmeltItem(ingredient, act.doer) if product ~= nil then act.doer.components.inventory:GiveItem(product, nil, smelt_pos) return true elseif ingredient:IsValid() then act.doer.components.inventory:GiveItem(ingredient, nil, smelt_pos) end return false endend)Should work, but you know what to do if there are any problems. Link to comment https://forums.kleientertainment.com/forums/topic/55708-custom-smelting-not-doing-anything/#findComment-650488 Share on other sites More sharing options...
Overreactedosbol Posted June 28, 2015 Author Share Posted June 28, 2015 Okay, right now it gives me the option to smelt, but when I press left arrow to smelt(X-Box controller), it still doesn't do the action (I tried to make it print out strings to follow the exact progress, but it seems the action isnt even being activated.) Here's my current modmain.lua:SpawnPrefab = GLOBAL.SpawnPrefabRECIPETABS = GLOBAL.RECIPETABSTECH = GLOBAL.TECH-- Points to files in "scripts/prefabs"PrefabFiles = { "copperingot", "copperore", "ironingot", "ironore", "tiningot", "tinore", "furnace" } -- Structures minimap iconAddMinimapAtlas("images/inventoryimages/furnace.xml")-- Recipes local myrecipe = AddRecipe("furnace", -- name{Ingredient("boards", 2), Ingredient("rocks", 10)}, -- ingredientsRECIPETABS.LIGHT, -- tabTECH.SCIENCE_ONE, -- science level"furnace_placer", -- placernil, -- min_spacingnil, -- nounlocknil, -- numtogivenil, -- builder_tag"images/inventoryimages/furnace.xml", -- atlas"furnace.tex")-- Adding ore drops to the rocks. function Loot_rock1(inst) inst.components.lootdropper:AddChanceLoot("copperore", 0.2) inst.components.lootdropper:AddChanceLoot("ironore", 0.4) inst.components.lootdropper:AddChanceLoot("tinore", 0.15)endAddPrefabPostInit("rock1", Loot_rock1)function Loot_rock2(inst) inst.components.lootdropper:AddChanceLoot("copperore", 0.15) inst.components.lootdropper:AddChanceLoot("ironore", 0.2) inst.components.lootdropper:AddChanceLoot("tinore", 0.4)endAddPrefabPostInit("rock2", Loot_rock2)function Loot_rock_flint(inst) inst.components.lootdropper:AddChanceLoot("copperore", 0.4) inst.components.lootdropper:AddChanceLoot("ironore", 0.15) inst.components.lootdropper:AddChanceLoot("tinore", 0.2)endAddPrefabPostInit("rock_flintless", Loot_rock_flint)-- Making sure you can smelt the smeltable itemsAddAction("SMELT", "Smelt", function(act) if act.target.components.smelter ~= nil then local smelt_pos = act.target:GetPosition() local ingredient = act.doer.components.inventory:RemoveItem(act.invobject) local product = act.target.components.smelter:SmeltItem(ingredient, act.doer) if product ~= nil then act.doer.components.inventory:GiveItem(product, nil, smelt_pos) return true elseif ingredient:IsValid() then act.doer.components.inventory:GiveItem(ingredient, nil, smelt_pos) end return false endend)local smeltable = function(inst, doer, target, actions) if target:HasTag("smelter") then table.insert(actions, GLOBAL.ACTIONS.SMELT) end endAddComponentAction("USEITEM", "smeltable", smeltable) Link to comment https://forums.kleientertainment.com/forums/topic/55708-custom-smelting-not-doing-anything/#findComment-650513 Share on other sites More sharing options...
przemolsz Posted June 28, 2015 Share Posted June 28, 2015 (edited) local handler = GLOBAL.ActionHandler(GLOBAL.ACTIONS.SMELT, "dolongaction") AddStategraphActionHandler("wilson", handler) AddStategraphActionHandler("wilson_client", handler) Edited June 28, 2015 by przemolsz 1 Link to comment https://forums.kleientertainment.com/forums/topic/55708-custom-smelting-not-doing-anything/#findComment-650538 Share on other sites More sharing options...
Overreactedosbol Posted June 28, 2015 Author Share Posted June 28, 2015 Unfortunately, adding those 3 lines to my modmain doesnt do anything. Maybe i didn't explain it clearly enough (If I didn't im very sorry) but I'll show it here: (Sorry if its too big.) Link to comment https://forums.kleientertainment.com/forums/topic/55708-custom-smelting-not-doing-anything/#findComment-650547 Share on other sites More sharing options...
przemolsz Posted June 28, 2015 Share Posted June 28, 2015 I made a typo in the previous post. Should work now. Link to comment https://forums.kleientertainment.com/forums/topic/55708-custom-smelting-not-doing-anything/#findComment-650549 Share on other sites More sharing options...
Overreactedosbol Posted June 28, 2015 Author Share Posted June 28, 2015 No, I saw that it crashed when not adding the GLOBAL.ACTIONS and I fixed that, it still doesnt work. Link to comment https://forums.kleientertainment.com/forums/topic/55708-custom-smelting-not-doing-anything/#findComment-650551 Share on other sites More sharing options...
przemolsz Posted June 28, 2015 Share Posted June 28, 2015 Does adding "GLOBAL." before "ActionHandler" make it work? Link to comment https://forums.kleientertainment.com/forums/topic/55708-custom-smelting-not-doing-anything/#findComment-650555 Share on other sites More sharing options...
Overreactedosbol Posted June 28, 2015 Author Share Posted June 28, 2015 (edited) Nope, I know it also crashed without GLOBAL, but it still doesnt help. Maybe it's just a simple problem, like a string named wrong or so? Edited June 28, 2015 by Overreactedosbol Link to comment https://forums.kleientertainment.com/forums/topic/55708-custom-smelting-not-doing-anything/#findComment-650557 Share on other sites More sharing options...
przemolsz Posted June 28, 2015 Share Posted June 28, 2015 "SGwilson" -> "wilson""SGwilson_client" -> "wilson_client" Link to comment https://forums.kleientertainment.com/forums/topic/55708-custom-smelting-not-doing-anything/#findComment-650558 Share on other sites More sharing options...
Overreactedosbol Posted June 28, 2015 Author Share Posted June 28, 2015 YES! It works! Thank you so much man I couldn't have done this without you. Link to comment https://forums.kleientertainment.com/forums/topic/55708-custom-smelting-not-doing-anything/#findComment-650559 Share on other sites More sharing options...
przemolsz Posted June 28, 2015 Share Posted June 28, 2015 Glad I could help! 1 Link to comment https://forums.kleientertainment.com/forums/topic/55708-custom-smelting-not-doing-anything/#findComment-650560 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now