Doodle Monster Posted June 13, 2025 Share Posted June 13, 2025 Hi! So as the title says; i'm trying to make a container repair items inside it; like wickerbottom's bookshelf. I did some digging and found Wickerbottom's code for restoreing books. However It only restores items with a certain tag; I want my container to restore any item with durability inside it. Since the container only allows certain items inside it anyways. I set up a few functions in my prefab file but it's currently crashing and I think it's not exactly what I want. I'll put the function in here; hopefully Someone knows how to get this working! local function RestoreWrampItem(inst) for k,v in pairs(inst.components.container.slots) do if v.components.finiteuses then local percent = v.components.finiteuses:GetPercent() if percent < 1 then v.components.finiteuses:SetPercent(math.min(1, percent + (TUNING.BOOKSTATION_RESTORE_AMOUNT))) end end end end local function ItemGet(inst) if inst.RestoreTask == nil then inst.RestoreTask = inst:DoPeriodicTask(TUNING.BOOKSTATION_RESTORE_TIME, RestoreWrampItem) end end end local function ItemLose(inst) if not inst.components.container:HasItemWithTag("shadow_item", 1) then if inst.RestoreTask ~= nil then inst.RestoreTask:Cancel() inst.RestoreTask = nil end end end And further down my prefab file I listen for event: inst:ListenForEvent("itemget", ItemGet) inst:ListenForEvent("itemlose", ItemLose) If you need me to upload my mod I can do that! I'm pretty new to LUA so any help would be awesome. Link to comment https://forums.kleientertainment.com/forums/topic/166434-help-with-item-making-container-repair-any-item-inside-it/ Share on other sites More sharing options...
Marmalade Posted June 13, 2025 Share Posted June 13, 2025 I'm also fairly new to LUA, so I don't feel that qualified for this, but uploading your mod or a screenshot of what your screen looks like with the crash log could help me solve this! (Or whatever gobbledegook is spat out in the Documents\Klei\DoNotStarveTogether directory if DST is straight up crashing with no crash log popping up) Link to comment https://forums.kleientertainment.com/forums/topic/166434-help-with-item-making-container-repair-any-item-inside-it/#findComment-1822058 Share on other sites More sharing options...
Doodle Monster Posted June 13, 2025 Author Share Posted June 13, 2025 Sure! I'll send the crash screen. If you need the uploaded mod I can also do that. Link to comment https://forums.kleientertainment.com/forums/topic/166434-help-with-item-making-container-repair-any-item-inside-it/#findComment-1822064 Share on other sites More sharing options...
Doodle Monster Posted June 13, 2025 Author Share Posted June 13, 2025 Here's the crash 00:00:50]: Mod: Wramp suitcase CODE REPAIR TEST (Wramp Suitcase REPAIR TEST) Registering prefabs [00:00:50]: Mod: Wramp suitcase CODE REPAIR TEST (Wramp Suitcase REPAIR TEST) Registering prefab file: prefabs/wramp_suitcase [00:00:50]: error calling LoadPrefabFile in mod Wramp suitcase CODE REPAIR TEST (Wramp Suitcase REPAIR TEST): [string "scripts/mainfunctions.lua"]:160: Error loading file prefabs/wramp_suitcase [string "../mods/Wramp suitcase CODE REPAIR TEST/scripts/prefabs/wramp_s..."]:39: '<eof>' expected near 'end' LUA ERROR stack traceback: =[C] in function 'assert' scripts/mainfunctions.lua(160,1) =(tail call) ? =[C] in function 'xpcall' scripts/mods.lua(190,1) scripts/mods.lua(689,1) in function '_RegisterPrefabs' local MS_MODNAME = 'workshop-2812783478';local a = {} Link to comment https://forums.kleientertainment.com/forums/topic/166434-help-with-item-making-container-repair-any-item-inside-it/#findComment-1822066 Share on other sites More sharing options...
Doodle Monster Posted June 13, 2025 Author Share Posted June 13, 2025 Wramp suitcase CODE REPAIR TEST.zip Link to comment https://forums.kleientertainment.com/forums/topic/166434-help-with-item-making-container-repair-any-item-inside-it/#findComment-1822067 Share on other sites More sharing options...
Doodle Monster Posted June 13, 2025 Author Share Posted June 13, 2025 Thanks for the help by the way! Even if we can't figure it out I know it takes some time to look it over. Wramp suitcase CODE REPAIR TEST.zip Link to comment https://forums.kleientertainment.com/forums/topic/166434-help-with-item-making-container-repair-any-item-inside-it/#findComment-1822068 Share on other sites More sharing options...
Marmalade Posted June 13, 2025 Share Posted June 13, 2025 9 minutes ago, Doodle Monster said: Here's the crash 00:00:50]: Mod: Wramp suitcase CODE REPAIR TEST (Wramp Suitcase REPAIR TEST) Registering prefabs [00:00:50]: Mod: Wramp suitcase CODE REPAIR TEST (Wramp Suitcase REPAIR TEST) Registering prefab file: prefabs/wramp_suitcase [00:00:50]: error calling LoadPrefabFile in mod Wramp suitcase CODE REPAIR TEST (Wramp Suitcase REPAIR TEST): [string "scripts/mainfunctions.lua"]:160: Error loading file prefabs/wramp_suitcase [string "../mods/Wramp suitcase CODE REPAIR TEST/scripts/prefabs/wramp_s..."]:39: '<eof>' expected near 'end' Alright, I believe this crash should be an easy fix. It seems you just have an additional end on the "ItemGet" function that's causing the game to go crazy. So... local function ItemGet(inst) if inst.RestoreTask == nil then inst.RestoreTask = inst:DoPeriodicTask(TUNING.BOOKSTATION_RESTORE_TIME, RestoreWrampItem) end end end Should get trimmed down to just... local function ItemGet(inst) if inst.RestoreTask == nil then inst.RestoreTask = inst:DoPeriodicTask(TUNING.BOOKSTATION_RESTORE_TIME, RestoreWrampItem) end end Link to comment https://forums.kleientertainment.com/forums/topic/166434-help-with-item-making-container-repair-any-item-inside-it/#findComment-1822073 Share on other sites More sharing options...
Doodle Monster Posted June 13, 2025 Author Share Posted June 13, 2025 (edited) Thanks! Will give it a test! Edited June 13, 2025 by Doodle Monster Link to comment https://forums.kleientertainment.com/forums/topic/166434-help-with-item-making-container-repair-any-item-inside-it/#findComment-1822075 Share on other sites More sharing options...
Doodle Monster Posted June 13, 2025 Author Share Posted June 13, 2025 (edited) :O wow it works! I didn't expect it to be so easy. Thanks again for the help! Edited June 13, 2025 by Doodle Monster Link to comment https://forums.kleientertainment.com/forums/topic/166434-help-with-item-making-container-repair-any-item-inside-it/#findComment-1822077 Share on other sites More sharing options...
Doodle Monster Posted June 13, 2025 Author Share Posted June 13, 2025 (edited) It still does only seem to repair darkswords currently; but I can work with this! Edited June 13, 2025 by Doodle Monster Link to comment https://forums.kleientertainment.com/forums/topic/166434-help-with-item-making-container-repair-any-item-inside-it/#findComment-1822080 Share on other sites More sharing options...
Doodle Monster Posted June 13, 2025 Author Share Posted June 13, 2025 (edited) I just did a little additon to the function; hopefully it will work but i'm not sure. It's supposed to detect if the item uses armor durability instead and repair that. local function RestoreWrampItem(inst) for k,v in pairs(inst.components.container.slots) do if v.components.finiteuses then local percent = v.components.finiteuses:GetPercent() if percent < 1 then v.components.finiteuses:SetPercent(math.min(1, percent + (TUNING.BOOKSTATION_RESTORE_AMOUNT))) or if v.components.armor then local percent = v.components.armor:GetPercent() if percent < 1 then v.components.armor:SetPercent(math.min(1, percent + (TUNING.BOOKSTATION_RESTORE_AMOUNT))) end end end end Edited June 13, 2025 by Doodle Monster Link to comment https://forums.kleientertainment.com/forums/topic/166434-help-with-item-making-container-repair-any-item-inside-it/#findComment-1822096 Share on other sites More sharing options...
Doodle Monster Posted June 13, 2025 Author Share Posted June 13, 2025 (edited) Okay, I added a area for repairing armor; problem is I'm getting a new crash. Here's the function I changed and the crash. local function RestoreWrampItem(inst) for k,v in pairs(inst.components.container.slots) do if v.components.finiteuses then local percent = v.components.finiteuses:GetPercent() if percent < 1 then v.components.finiteuses:SetPercent(math.min(1, percent + (TUNING.BOOKSTATION_RESTORE_AMOUNT))) else if v.components.armor then local percent = v.components.armor:GetPercent() if percent < 1 then v.components.armor:SetPercent(math.min(1, percent + (TUNING.BOOKSTATION_RESTORE_AMOUNT))) end end end end Edited June 13, 2025 by Doodle Monster Link to comment https://forums.kleientertainment.com/forums/topic/166434-help-with-item-making-container-repair-any-item-inside-it/#findComment-1822101 Share on other sites More sharing options...
Doodle Monster Posted June 13, 2025 Author Share Posted June 13, 2025 (edited) [00:01:10]: [string "scripts/mainfunctions.lua"]:160: Error loading file prefabs/wramp_suitcase [string "../mods/Wramp suitcase CODE REPAIR WORKING PARTIALLY/scripts/pr..."]:124: 'end' expected (to close 'for' at line 24) near '<eof>' LUA ERROR stack traceback: =[C] in function 'assert' scripts/mainfunctions.lua(160,1) =(tail call) ? =[C] in function 'xpcall' scripts/mods.lua(190,1) scripts/mods.lua(689,1) in function '_RegisterPrefabs' local MS_MODNAME = 'workshop-2812783478';local a = {} Edited June 13, 2025 by Doodle Monster Link to comment https://forums.kleientertainment.com/forums/topic/166434-help-with-item-making-container-repair-any-item-inside-it/#findComment-1822102 Share on other sites More sharing options...
Doodle Monster Posted June 14, 2025 Author Share Posted June 14, 2025 (edited) Okay, I think I fixed the syntax error on my own; However it is still crashing when trying to read the armor repair line. local function RestoreWrampItem(inst) for k,v in pairs(inst.components.container.slots) do if v.components.finiteuses then local percent = v.components.finiteuses:GetPercent() if percent < 1 then v.components.finiteuses:SetPercent(math.min(1, percent + (TUNING.BOOKSTATION_RESTORE_AMOUNT))) else v.components.armor then local percent = v.components.armor:GetPercent() if percent < 1 then v.components.armor:SetPercent(math.min(1, percent + (TUNING.BOOKSTATION_RESTORE_AMOUNT))) end end end end end Edited June 14, 2025 by Doodle Monster Link to comment https://forums.kleientertainment.com/forums/topic/166434-help-with-item-making-container-repair-any-item-inside-it/#findComment-1822112 Share on other sites More sharing options...
Doodle Monster Posted June 14, 2025 Author Share Posted June 14, 2025 (edited) [00:01:52]: [string "scripts/mainfunctions.lua"]:160: Error loading file prefabs/wramp_suitcase [string "../mods/Wramp suitcase CODE repair armor test/scripts/prefabs/w..."]:30: '=' expected near 'then' LUA ERROR stack traceback: =[C] in function 'assert' scripts/mainfunctions.lua(160,1) =(tail call) ? =[C] in function 'xpcall' scripts/mods.lua(190,1) scripts/mods.lua(689,1) in function '_RegisterPrefabs' local MS_MODNAME = 'workshop-2812783478';local a = {} Edited June 14, 2025 by Doodle Monster Link to comment https://forums.kleientertainment.com/forums/topic/166434-help-with-item-making-container-repair-any-item-inside-it/#findComment-1822113 Share on other sites More sharing options...
Doodle Monster Posted June 14, 2025 Author Share Posted June 14, 2025 (edited) I'm not sure if v.components.armor works for repairing armor anyways, I did take a quick look at the dreadstone armor but I don't really know what's happening in the code Edited June 14, 2025 by Doodle Monster Link to comment https://forums.kleientertainment.com/forums/topic/166434-help-with-item-making-container-repair-any-item-inside-it/#findComment-1822115 Share on other sites More sharing options...
Doodle Monster Posted June 14, 2025 Author Share Posted June 14, 2025 (edited) I think this line is what i'm looking for. I'll take another crack at it later, Hopefully someone can help me get this working :P inst.components.armor:Repair(inst.components.armor.maxcondition * rate * setbonus) Edited June 14, 2025 by Doodle Monster Link to comment https://forums.kleientertainment.com/forums/topic/166434-help-with-item-making-container-repair-any-item-inside-it/#findComment-1822118 Share on other sites More sharing options...
Doodle Monster Posted June 14, 2025 Author Share Posted June 14, 2025 It seems geting it to repair armor is a lot trickyer; I added the line from the dreadstone armor into the function. I *really* Don't know what i'm doing. Here's the function and the crash: local function RestoreWrampItem(inst) for k,v in pairs(inst.components.container.slots) do if v.components.finiteuses then local percent = v.components.finiteuses:GetPercent() if percent < 1 then v.components.finiteuses:SetPercent(math.min(1, percent + (TUNING.BOOKSTATION_RESTORE_AMOUNT))) else v.components.armor then local percent = v.components.armor:GetPercent() if percent < 1 then v.components.armor:Repair(inst.components.armor.maxcondition * 1 * 1.5) end end end end end Link to comment https://forums.kleientertainment.com/forums/topic/166434-help-with-item-making-container-repair-any-item-inside-it/#findComment-1822345 Share on other sites More sharing options...
Doodle Monster Posted June 14, 2025 Author Share Posted June 14, 2025 [00:01:48]: Disabling Wramp suitcase CODE repair armor test dreadstone (Wramp Suitcase REPAIR TEST) because it had an error. [00:01:48]: [string "scripts/mainfunctions.lua"]:160: Error loading file prefabs/wramp_suitcase [string "../mods/Wramp suitcase CODE repair armor test dreadstone/script..."]:30: '=' expected near 'then' LUA ERROR stack traceback: =[C] in function 'assert' scripts/mainfunctions.lua(160,1) =(tail call) ? =[C] in function 'xpcall' scripts/mods.lua(190,1) scripts/mods.lua(689,1) in function '_RegisterPrefabs' local MS_MODNAME = 'workshop-2812783478';local a = {} Link to comment https://forums.kleientertainment.com/forums/topic/166434-help-with-item-making-container-repair-any-item-inside-it/#findComment-1822346 Share on other sites More sharing options...
Doodle Monster Posted June 14, 2025 Author Share Posted June 14, 2025 Line 30 starts at this part: v.components.armor then local percent = v.components.armor:GetPercent() if percent < 1 then v.components.armor:Repair(inst.components.armor.maxcondition * 1 * 1.5) Link to comment https://forums.kleientertainment.com/forums/topic/166434-help-with-item-making-container-repair-any-item-inside-it/#findComment-1822347 Share on other sites More sharing options...
Baguettes Posted June 20, 2025 Share Posted June 20, 2025 you're missing an if. that has to be an elseif, not just an else. Link to comment https://forums.kleientertainment.com/forums/topic/166434-help-with-item-making-container-repair-any-item-inside-it/#findComment-1823581 Share on other sites More sharing options...
Doodle Monster Posted June 20, 2025 Author Share Posted June 20, 2025 Thank you! Will give it another go when I get the chance! Link to comment https://forums.kleientertainment.com/forums/topic/166434-help-with-item-making-container-repair-any-item-inside-it/#findComment-1823603 Share on other sites More sharing options...
Doodle Monster Posted June 20, 2025 Author Share Posted June 20, 2025 @Baguettes The syntax error is fixed! It's not crashing; However I think it still won't repair nightmare armor. I think I might be using the wrong componet Link to comment https://forums.kleientertainment.com/forums/topic/166434-help-with-item-making-container-repair-any-item-inside-it/#findComment-1823610 Share on other sites More sharing options...
Doodle Monster Posted June 21, 2025 Author Share Posted June 21, 2025 I'll upload the updated test mod file incase anyone wants to take a look at it. Wramp suitcase repair test.zip Link to comment https://forums.kleientertainment.com/forums/topic/166434-help-with-item-making-container-repair-any-item-inside-it/#findComment-1823646 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