Jump to content

Recommended Posts

There is a component called 'container'. You can add it to your armor and set it up like the backpack.

inst:AddComponent("container")
inst.components.container:WidgetSetup("backpack")

You'll also need to add this to the client/server check for your armor:

if not TheWorld.ismastersim then
    inst:DoTaskInTime(0, function(inst)
        inst.replica.container:WidgetSetup("backpack")
    end)

    return inst
end

 

  • Like 1
3 hours ago, -t- said:

There is a component called 'container'. You can add it to your armor and set it up like the backpack.

inst:AddComponent("container")
inst.components.container:WidgetSetup("backpack")

You'll also need to add this to the client/server check for your armor:

if not TheWorld.ismastersim then
    inst:DoTaskInTime(0, function(inst)
        inst.replica.container:WidgetSetup("backpack")
    end)

    return inst
end

 

or thanks but the client/server goes in "modmain.lua" or in another location, also another question can be asked that there are only 4 more inventory spaces?

If you plan on making your own container data you will need to change a few things. First of all you're gonna need a local table of widget data inside your prefab file, here's a quick template:

local container_params = {
    widget = {
        slotpos = {
            Vector3(-37.5, 32 + 4, 0),
            Vector3(37.5, 32 + 4, 0),
            Vector3(-37.5, -(32 + 4), 0),
            Vector3(37.5, -(32 + 4), 0)
        },
        animbank = "ui_chest_2x2",
        animbuild = "ui_chest_2x2",
        pos = Vector3(0, 200, 0),
        side_align_tip = 160,
    },
    type = "chest"
}

 

Using this table you'll need to change the WidgetSetup parameters like this:

inst.components.container:WidgetSetup(nil, container_params)
inst.replica.container:WidgetSetup(nil, container_params)

 

if not TheWorld.ismastersim then
    inst:DoTaskInTime(0, function(inst)
        inst.replica.container:WidgetSetup(nil, container_params)
    end)

    return inst
end

This part goes into your armors main 'fn'. You should have this check inside this function:

if not TheWorld.ismastersim then
    return inst
end

So you need to just add the DoTaskInTime part.

  • Like 1
2 hours ago, -t- said:

If you plan on making your own container data you will need to change a few things. First of all you're gonna need a local table of widget data inside your prefab file, here's a quick template:

local container_params = {
    widget = {
        slotpos = {
            Vector3(-37.5, 32 + 4, 0),
            Vector3(37.5, 32 + 4, 0),
            Vector3(-37.5, -(32 + 4), 0),
            Vector3(37.5, -(32 + 4), 0)
        },
        animbank = "ui_chest_2x2",
        animbuild = "ui_chest_2x2",
        pos = Vector3(0, 200, 0),
        side_align_tip = 160,
    },
    type = "chest"
}

 

Using this table you'll need to change the WidgetSetup parameters like this:

inst.components.container:WidgetSetup(nil, container_params)
inst.replica.container:WidgetSetup(nil, container_params)

 

if not TheWorld.ismastersim then
    inst:DoTaskInTime(0, function(inst)
        inst.replica.container:WidgetSetup(nil, container_params)
    end)

    return inst
end

This part goes into your armors main 'fn'. You should have this check inside this function:

if not TheWorld.ismastersim then
    return inst
end

So you need to just add the DoTaskInTime part.

ok I did what you asked and luckily I think I did it decently well so it didn't crash. Is there a next step or did I do something wrong? here is the prefab in case you want to see it (it is an example template from this same forum)

tummy.lua

I'm sorry, I don't think I saved the file and I sent it to you just as it was because I hadn't saved anything, I'm sorry for the inconvenience, that's why no change occurred (I've been working with the tutorial template and not with the one of the character I was building, so I don't nothing happened sorry for this confusion)

ok now if a change occurs in the mod, but it crashes although I don't understand why?

image.png

40 minutes ago, -t- said:

The file doesn't seem to have any code snippets I posted. Just so we're clear, this is roughly how the file should look:

tummy.lua 2.52 kB · 3 downloads

ok I managed to fix the crash of the image and it works perfectly, but I have a small bug, when I remove the armor the extra space remains open I think that some function in "onunequip" fixed it but I don't know which one

20 minutes ago, -t- said:

You can use the onunequip function and paste in this inside it:

if inst.components.container then
    inst.components.container:Close(owner)
end

 

ok I think it works perfectly thank you very much it's just what I was looking for. goodbye for now and thank you again

33 minutes ago, -t- said:

You can use the onunequip function and paste in this inside it:

if inst.components.container then
    inst.components.container:Close(owner)
end

 

PS = I just realized this. You will not know in some way that when you unequip the armor or it breaks all the items are dropped to the ground

On 4/24/2023 at 2:23 AM, -t- said:

Use:

inst.components.container:DropEverything()

Thank you very much it works sorry for thanking you so late, the only drawback is that I can't find how to make it drop the items when it's destroyed, but I think I'll find the solution with time

On 4/24/2023 at 2:23 AM, -t- said:

Use:

inst.components.container:DropEverything()

Hey sir, I wanted to ask how to add the variable "inst.components.container:DropEverything()" for when the armor is destroyed, with "onunequip" it is quite simple to unequip the armor and drop the items but when destroying it I can't find a way to Make the items not disappear. Do you have any ideas or a manual that you can lend me, please?

Assuming you're using the Armor component you can use `Armor:onfinished()` method. You need to declare it and it will run when the armor is destroyed by usage.

In the case where the armor is removed (either by a console command or the Remove() method) you can listen for the "onremove" event and then run DropEverything().

  • Sanity 1
13 hours ago, -t- said:

Assuming you're using the Armor component you can use `Armor:onfinished()` method. You need to declare it and it will run when the armor is destroyed by usage.

In the case where the armor is removed (either by a console command or the Remove() method) you can listen for the "onremove" event and then run DropEverything().

I tried to put together a couple of things with the last thing you said, but since I don't understand much about programming, I think I didn't get anywhere. I'm sorry, but could you give me an example please?

For `onfinished`:

inst.components.armor.isfinished = function(inst)
    inst.components.container:DropEverything()
end

For `onremove`:

inst:ListenForEvent("onremove", function(inst)
    inst.components.container:DropEverything()
end)

 

  • Sanity 1
11 hours ago, -t- said:

For `onfinished`:

inst.components.armor.isfinished = function(inst)
    inst.components.container:DropEverything()
end

For `onremove`:

inst:ListenForEvent("onremove", function(inst)
    inst.components.container:DropEverything()
end)

 

Ugh I couldn't find a solution mate, I tried several things but maybe I lack experience with the don't starve together code and well programming, although I think the items are not dropped because they are destroyed along with the armor but hey I'm not going to bother you anymore I think I've spent too much of your time, I'm just going to try to learn more and try more things, thank you very much for everything, I'm making progress, thanks to you

  • Like 1
15 hours ago, -t- said:

For `onfinished`:

inst.components.armor.isfinished = function(inst)
    inst.components.container:DropEverything()
end

For `onremove`:

inst:ListenForEvent("onremove", function(inst)
    inst.components.container:DropEverything()
end)

 

Hey friend, I managed to make it work, I don't know how, but it works perfectly, thank you very much, but before I go I would like to ask you something about the solution I found on the forum, the tag ("percentusedchange") is used to detect the event when does armor durability change? Or cause something else. but hey I wanted to inform you that it already works and thank you very much, see you at another time thank you

11 hours ago, -t- said:

"percentusedchange" is not a tag but an event name. And, yes, it runs when durability changes.

wow that is great, that information is very useful thank you very much, I really appreciate all the help you have given me, I say goodbye see you sir

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...