red1500z Posted April 23, 2023 Share Posted April 23, 2023 hello (asking 2 things in one day is a bit embarrassing....) but I wanted to know if there is a way to make an armor have backpack space or is it technically impossible? (sorry if I'm asking too much...) Link to comment https://forums.kleientertainment.com/forums/topic/147333-helpdoes-anyone-know-how-to-add-4-backpack-slots-to-1-armor/ Share on other sites More sharing options...
-LukaS- Posted April 23, 2023 Share Posted April 23, 2023 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 1 Link to comment https://forums.kleientertainment.com/forums/topic/147333-helpdoes-anyone-know-how-to-add-4-backpack-slots-to-1-armor/#findComment-1631540 Share on other sites More sharing options...
red1500z Posted April 23, 2023 Author Share Posted April 23, 2023 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? Link to comment https://forums.kleientertainment.com/forums/topic/147333-helpdoes-anyone-know-how-to-add-4-backpack-slots-to-1-armor/#findComment-1631574 Share on other sites More sharing options...
-LukaS- Posted April 23, 2023 Share Posted April 23, 2023 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. 1 Link to comment https://forums.kleientertainment.com/forums/topic/147333-helpdoes-anyone-know-how-to-add-4-backpack-slots-to-1-armor/#findComment-1631588 Share on other sites More sharing options...
red1500z Posted April 23, 2023 Author Share Posted April 23, 2023 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 Link to comment https://forums.kleientertainment.com/forums/topic/147333-helpdoes-anyone-know-how-to-add-4-backpack-slots-to-1-armor/#findComment-1631612 Share on other sites More sharing options...
-LukaS- Posted April 23, 2023 Share Posted April 23, 2023 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 1 Link to comment https://forums.kleientertainment.com/forums/topic/147333-helpdoes-anyone-know-how-to-add-4-backpack-slots-to-1-armor/#findComment-1631613 Share on other sites More sharing options...
red1500z Posted April 23, 2023 Author Share Posted April 23, 2023 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? Link to comment https://forums.kleientertainment.com/forums/topic/147333-helpdoes-anyone-know-how-to-add-4-backpack-slots-to-1-armor/#findComment-1631614 Share on other sites More sharing options...
red1500z Posted April 23, 2023 Author Share Posted April 23, 2023 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 Link to comment https://forums.kleientertainment.com/forums/topic/147333-helpdoes-anyone-know-how-to-add-4-backpack-slots-to-1-armor/#findComment-1631620 Share on other sites More sharing options...
-LukaS- Posted April 23, 2023 Share Posted April 23, 2023 You can use the onunequip function and paste in this inside it: if inst.components.container then inst.components.container:Close(owner) end 1 Link to comment https://forums.kleientertainment.com/forums/topic/147333-helpdoes-anyone-know-how-to-add-4-backpack-slots-to-1-armor/#findComment-1631621 Share on other sites More sharing options...
red1500z Posted April 23, 2023 Author Share Posted April 23, 2023 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 Link to comment https://forums.kleientertainment.com/forums/topic/147333-helpdoes-anyone-know-how-to-add-4-backpack-slots-to-1-armor/#findComment-1631625 Share on other sites More sharing options...
-LukaS- Posted April 24, 2023 Share Posted April 24, 2023 (edited) Use: inst.components.container:DropEverything() Edited April 24, 2023 by -t- 1 Link to comment https://forums.kleientertainment.com/forums/topic/147333-helpdoes-anyone-know-how-to-add-4-backpack-slots-to-1-armor/#findComment-1631667 Share on other sites More sharing options...
red1500z Posted April 26, 2023 Author Share Posted April 26, 2023 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 Link to comment https://forums.kleientertainment.com/forums/topic/147333-helpdoes-anyone-know-how-to-add-4-backpack-slots-to-1-armor/#findComment-1632055 Share on other sites More sharing options...
red1500z Posted April 28, 2023 Author Share Posted April 28, 2023 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? Link to comment https://forums.kleientertainment.com/forums/topic/147333-helpdoes-anyone-know-how-to-add-4-backpack-slots-to-1-armor/#findComment-1632369 Share on other sites More sharing options...
-LukaS- Posted April 28, 2023 Share Posted April 28, 2023 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(). 1 Link to comment https://forums.kleientertainment.com/forums/topic/147333-helpdoes-anyone-know-how-to-add-4-backpack-slots-to-1-armor/#findComment-1632427 Share on other sites More sharing options...
red1500z Posted April 28, 2023 Author Share Posted April 28, 2023 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? Link to comment https://forums.kleientertainment.com/forums/topic/147333-helpdoes-anyone-know-how-to-add-4-backpack-slots-to-1-armor/#findComment-1632557 Share on other sites More sharing options...
-LukaS- Posted April 29, 2023 Share Posted April 29, 2023 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) 1 Link to comment https://forums.kleientertainment.com/forums/topic/147333-helpdoes-anyone-know-how-to-add-4-backpack-slots-to-1-armor/#findComment-1632641 Share on other sites More sharing options...
red1500z Posted April 29, 2023 Author Share Posted April 29, 2023 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 1 Link to comment https://forums.kleientertainment.com/forums/topic/147333-helpdoes-anyone-know-how-to-add-4-backpack-slots-to-1-armor/#findComment-1632733 Share on other sites More sharing options...
red1500z Posted April 29, 2023 Author Share Posted April 29, 2023 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 Link to comment https://forums.kleientertainment.com/forums/topic/147333-helpdoes-anyone-know-how-to-add-4-backpack-slots-to-1-armor/#findComment-1632777 Share on other sites More sharing options...
-LukaS- Posted April 30, 2023 Share Posted April 30, 2023 "percentusedchange" is not a tag but an event name. And, yes, it runs when durability changes. Link to comment https://forums.kleientertainment.com/forums/topic/147333-helpdoes-anyone-know-how-to-add-4-backpack-slots-to-1-armor/#findComment-1632849 Share on other sites More sharing options...
red1500z Posted April 30, 2023 Author Share Posted April 30, 2023 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 Link to comment https://forums.kleientertainment.com/forums/topic/147333-helpdoes-anyone-know-how-to-add-4-backpack-slots-to-1-armor/#findComment-1632906 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