Jump to content

Need help making tool that can dissasemble items in the inventory


Recommended Posts

Hello
My goal was to make something similar to Wanda's Clockmaker's Tools but instead of disassembling clocks - it can disassemble any item into it's crafting components.

I used and modified official code as a basis and didn't get any results, I can only craft the item and it doesn't do anything, can't even uncraft Wanda's clocks anymore.

I'm attaching prefab file and component file.
If anyone have any leads on what to change, please tell me.

toolboxw.lua toolboxw.lua

Link to comment
Share on other sites

2 hours ago, _zwb said:

You need to call AddComponentAction on your custom component. Check componentaction.lua and modutil.lua for more info

Something like this?
(I don't know if crafted items have specific tag attached, so I just left it blank)

function AddComponentAction:DISMANTLE_ITEM
        Item_Dismantler = function (inst, doer, target, actions)
            if doer:HasTag("wusty") and target:HasTag("---") then
                table.insert(actions, ACTIONS.DISMANTLE_ITEM)
            end
        end
end

 

Link to comment
Share on other sites

9 hours ago, _zwb said:

In modmain.lua:

AddComponentAction("INVENTORY", "your_component_name", function(inst, doer, target, actions)
    --[[your actual function here]]--
end

 

Since I have a character mod, I'm not sure if this goes into modmain
maybe in prefabs/toolboxw?

Link to comment
Share on other sites

1 hour ago, _zwb said:

It goes in modmain

Character stops working when I add code into modmain
 

	AddComponentAction("INVENTORY", "DISMANTLE_ITEM", function(inst, doer, target, actions)
    Item_Dismantler = function (inst, doer, target, actions)
            if doer:HasTag("wusty") then
                table.insert(actions, ACTIONS.DISMANTLE_ITEM)
            end
        end
	end
end

 

Link to comment
Share on other sites

19 minutes ago, RexySeven said:

Character stops working when I add code into modmain
 

	AddComponentAction("INVENTORY", "DISMANTLE_ITEM", function(inst, doer, target, actions)
    Item_Dismantler = function (inst, doer, target, actions)
            if doer:HasTag("wusty") then
                table.insert(actions, ACTIONS.DISMANTLE_ITEM)
            end
        end
	end
end

 

In modmain.lua

AddComponentAction("INVENTORY", "toolboxw", function(inst, doer, target, actions)
    if doer:HasTag("wusty") then
      table.insert(actions, GLOBAL.ACTIONS.DISMANTLE_ITEM)
    end
end)
  

you would have to either modify ACTIONS.DISMANTLE_ITEM or add a new action for your component

Link to comment
Share on other sites

34 minutes ago, _zwb said:

In modmain.lua

AddComponentAction("INVENTORY", "toolboxw", function(inst, doer, target, actions)
    if doer:HasTag("wusty") then
      table.insert(actions, GLOBAL.ACTIONS.DISMANTLE_ITEM)
    end
end)
  

you would have to either modify ACTIONS.DISMANTLE_ITEM or add a new action for your component

isn't that the action in the component\toolboxw?

my game crashed asking for missing loot table

function Item_Dismantler:Dismantle(target, doer)
    local owner = target.components.inventoryitem:GetGrandOwner()
    local receiver = owner ~= nil and not (owner.components.inventory or owner.components.container) or nil
    local pt = receiver ~= nil and self.inst:GetPosition() or doer:GetPosition()

    local loot = target.components.lootdropper:GetFullRecipeLoot(AllRecipes[target.prefab])
    target:Remove() -- We remove the target before giving the loot to make more space in the inventory


    SpawnPrefab("brokentool").Transform:SetPosition(doer.Transform:GetWorldPosition())
end
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...