Doodle Monster Posted May 3, 2025 Share Posted May 3, 2025 Hi! So I'm working on my moded character Wramp, and one of his perks was going to be a suitcase that can store Dress items. I got the suitcase ingame and it works! But I have no idea how to maker it only accept certain items. Any help would be awesome! Link to comment https://forums.kleientertainment.com/forums/topic/165584-help-how-to-make-container-only-accept-certain-items/ Share on other sites More sharing options...
Baguettes Posted May 3, 2025 Share Posted May 3, 2025 Can I see your container code? Checks involve returning boolean and anything you could think of like tags. I forgot how I did it... Link to comment https://forums.kleientertainment.com/forums/topic/165584-help-how-to-make-container-only-accept-certain-items/#findComment-1814928 Share on other sites More sharing options...
Doodle Monster Posted May 4, 2025 Author Share Posted May 4, 2025 Sure! wramp_suitcase.lua Link to comment https://forums.kleientertainment.com/forums/topic/165584-help-how-to-make-container-only-accept-certain-items/#findComment-1815053 Share on other sites More sharing options...
Doodle Monster Posted May 4, 2025 Author Share Posted May 4, 2025 (edited) I don't really know how to make my own Widget; so I just reused chester's. Hopefully that dosen't change anything. Edited May 4, 2025 by Doodle Monster Link to comment https://forums.kleientertainment.com/forums/topic/165584-help-how-to-make-container-only-accept-certain-items/#findComment-1815056 Share on other sites More sharing options...
Doodle Monster Posted May 4, 2025 Author Share Posted May 4, 2025 (edited) @Baguettes Sorry for the ping! Edited May 4, 2025 by Doodle Monster Link to comment https://forums.kleientertainment.com/forums/topic/165584-help-how-to-make-container-only-accept-certain-items/#findComment-1815057 Share on other sites More sharing options...
Merkyrrie Posted May 5, 2025 Share Posted May 5, 2025 9 hours ago, Doodle Monster said: Sure! wramp_suitcase.luaUnavailable this file is unavailable 9 hours ago, Doodle Monster said: I don't really know how to make my own Widget; so I just reused chester's. Hopefully that dosen't change anything. you'll probably want to make your own so you can make use of the itemtestfn for containers Link to comment https://forums.kleientertainment.com/forums/topic/165584-help-how-to-make-container-only-accept-certain-items/#findComment-1815087 Share on other sites More sharing options...
Doodle Monster Posted May 5, 2025 Author Share Posted May 5, 2025 Got it! So Inorder to make my own Widget I would need to do something like this? I don't *really* know what i'm looking at; my end goal would be a Widget that is exactly like the normal chest (I borrowed this code from another mod, it is not mine) GLOBAL.setfenv(1, GLOBAL) local params = require("containers").params local widget_toolbox = { widget = { slotpos = {}, animbank = "ui_toolbox_3x3", animbuild = "ui_toolbox_3x3", pos = Vector3(0, 200, 0), side_align_tip = 160, }, type = "chest", } for y = 2, 0, -1 do for x = 0, 2 do table.insert(widget_toolbox.widget.slotpos, Vector3(80 * x - 80 * 2 + 80, 80 * y - 80 * 2 + 80, 0)) end end Link to comment https://forums.kleientertainment.com/forums/topic/165584-help-how-to-make-container-only-accept-certain-items/#findComment-1815135 Share on other sites More sharing options...
Doodle Monster Posted May 5, 2025 Author Share Posted May 5, 2025 @Merkyrrie Sorry for the ping! I'm guessing I need the Widget inorder to use something like this; (I took this from a mod it is not mine) function widget_toolbox.itemtestfn(container, item, slot) return item.prefab == "sewing_tape" or item.prefab == "winona_catapult_item" or item.prefab == "winona_spotlight_item" or item.prefab == "winona_battery_low_item" or item.prefab == "winona_battery_high_item" or item.prefab == "winona_remote" or item.prefab == "inspectacleshat" or item.prefab == "winona_storage_robot" or item.prefab == "winona_teleport_pad_item" or item.prefab == "winona_telebrella" end Link to comment https://forums.kleientertainment.com/forums/topic/165584-help-how-to-make-container-only-accept-certain-items/#findComment-1815139 Share on other sites More sharing options...
Doodle Monster Posted May 5, 2025 Author Share Posted May 5, 2025 I'll try and reupload the prefab file; hopefully it lets you download it. wramp_suitcase.lua Link to comment https://forums.kleientertainment.com/forums/topic/165584-help-how-to-make-container-only-accept-certain-items/#findComment-1815140 Share on other sites More sharing options...
Merkyrrie Posted May 5, 2025 Share Posted May 5, 2025 3 hours ago, Doodle Monster said: I'll try and reupload the prefab file; hopefully it lets you download it. wramp_suitcase.luaUnavailable It did not but thats fine 3 hours ago, Doodle Monster said: Got it! So Inorder to make my own Widget I would need to do something like this? I don't *really* know what i'm looking at; my end goal would be a Widget that is exactly like the normal chest (I borrowed this code from another mod, it is not mine) GLOBAL.setfenv(1, GLOBAL) local params = require("containers").params local widget_toolbox = { widget = { slotpos = {}, animbank = "ui_toolbox_3x3", animbuild = "ui_toolbox_3x3", pos = Vector3(0, 200, 0), side_align_tip = 160, }, type = "chest", } for y = 2, 0, -1 do for x = 0, 2 do table.insert(widget_toolbox.widget.slotpos, Vector3(80 * x - 80 * 2 + 80, 80 * y - 80 * 2 + 80, 0)) end end 3 hours ago, Doodle Monster said: @Merkyrrie Sorry for the ping! I'm guessing I need the Widget inorder to use something like this; (I took this from a mod it is not mine) function widget_toolbox.itemtestfn(container, item, slot) return item.prefab == "sewing_tape" or item.prefab == "winona_catapult_item" or item.prefab == "winona_spotlight_item" or item.prefab == "winona_battery_low_item" or item.prefab == "winona_battery_high_item" or item.prefab == "winona_remote" or item.prefab == "inspectacleshat" or item.prefab == "winona_storage_robot" or item.prefab == "winona_teleport_pad_item" or item.prefab == "winona_telebrella" end Both of these are correct yeah, maybe not quite how I'd have done it but they'll work for you. I personally wouldn't do a long line of conditionals checking prefab names like this mod does but you can set the test function up however works for you. For reference, the 'require' statement pulls the definition of containers from another file. Then you setup a table variable containing the parameters that a container needs and that the widget parameter needs which are all there. Animbank and animbuild set the UI of the container, pos is the position of the container's background, slotpos is a table of positions for each individual slot of the container which gets set in the for loop. Type = "chest" is the type of container it will be, you'd have to look at the other definitions in the container file to see all the options but chest is obviously correct for what you want. Itemtestfn is self-explanatory and returns true to accept and item and false to block an item. Link to comment https://forums.kleientertainment.com/forums/topic/165584-help-how-to-make-container-only-accept-certain-items/#findComment-1815154 Share on other sites More sharing options...
Baguettes Posted May 6, 2025 Share Posted May 6, 2025 As for the original question, @Merkyrrie answered it; Itemtestfn is there to test whether an item is supposed to be accepted or not. The mod you reference does it, sure, but it's a bit... messy. For me personally, I'd do tables: local AcceptedItems = { "prefab1", "prefab2", --"", } function yourprefab.itemtestfn(container, item, slot) if table.contains(AcceptedItems, item.prefab) then return true elseif item:HasTag("any_possible_tag") then return true end return false end (Note: table.contains() is not present in Lua by default and is made by Klei. You'd have to define the new function yourself elsewhere not DST.) Link to comment https://forums.kleientertainment.com/forums/topic/165584-help-how-to-make-container-only-accept-certain-items/#findComment-1815198 Share on other sites More sharing options...
Doodle Monster Posted May 6, 2025 Author Share Posted May 6, 2025 (edited) I think my Widget isn't working; when trying to open my container I crash I assume you have to put this in the script for the container to refrence the widget inst:AddComponent("container") inst.components.container:WidgetSetup("wrampsuitcase") inst.components.container.onopenfn = onopen inst.components.container.onclosefn = onclose inst.components.container.skipclosesnd = true inst.components.container.skipopensnd = true inst.components.container.droponopen = true Edited May 6, 2025 by Doodle Monster Link to comment https://forums.kleientertainment.com/forums/topic/165584-help-how-to-make-container-only-accept-certain-items/#findComment-1815238 Share on other sites More sharing options...
Doodle Monster Posted May 6, 2025 Author Share Posted May 6, 2025 (edited) Here's my code for the Widget GLOBAL.setfenv(1, GLOBAL) local params = require("containers").params local widget_wrampsuitcase = { widget = { slotpos = {}, pos = Vector3(0, 200, 0), side_align_tip = 160, }, type = "chest", } for y = 2, 0, -1 do for x = 0, 2 do table.insert(widget_wrampsuitcase.widget.slotpos, Vector3(80 * x - 80 * 2 + 80, 80 * y - 80 * 2 + 80, 0)) end end Edited May 6, 2025 by Doodle Monster Link to comment https://forums.kleientertainment.com/forums/topic/165584-help-how-to-make-container-only-accept-certain-items/#findComment-1815239 Share on other sites More sharing options...
Doodle Monster Posted May 6, 2025 Author Share Posted May 6, 2025 (edited) @Merkyrrie Is there any vanilla Continer Widgets I can look at? I'm just trying to make a exact copy of the regular chest; Hopefully you can see where I went wrong with my widget Edited May 6, 2025 by Doodle Monster Link to comment https://forums.kleientertainment.com/forums/topic/165584-help-how-to-make-container-only-accept-certain-items/#findComment-1815241 Share on other sites More sharing options...
Doodle Monster Posted May 6, 2025 Author Share Posted May 6, 2025 @Baguettes Thank you for the help! 1 Link to comment https://forums.kleientertainment.com/forums/topic/165584-help-how-to-make-container-only-accept-certain-items/#findComment-1815243 Share on other sites More sharing options...
Merkyrrie Posted May 6, 2025 Share Posted May 6, 2025 5 hours ago, Doodle Monster said: I think my Widget isn't working; when trying to open my container I crash I assume you have to put this in the script for the container to refrence the widget inst:AddComponent("container") inst.components.container:WidgetSetup("wrampsuitcase") inst.components.container.onopenfn = onopen inst.components.container.onclosefn = onclose inst.components.container.skipclosesnd = true inst.components.container.skipopensnd = true inst.components.container.droponopen = true Had this exact crash happen to someone else too so luckily for you I know how to fix it (though one of the two fixes I haven't figured out the logic behind) Changing the name of the widget from wrampsuitcase to wramp_suitcase so it matches the prefab name might work, I've weirdly had success getting around this issue by matching names. However the 2nd option that should work if that doesn't is to do this: -- Replacing the original version of this if statement in your prefab's function, not adding a second if not TheWorld.ismastersim then inst:DoTaskInTime(0, function(inst) inst.replica.container:WidgetSetup("wrampsuitcase") -- Sets up the widget for the client too end) return inst end Link to comment https://forums.kleientertainment.com/forums/topic/165584-help-how-to-make-container-only-accept-certain-items/#findComment-1815280 Share on other sites More sharing options...
Doodle Monster Posted May 6, 2025 Author Share Posted May 6, 2025 Thanks for the help! I'll test it when I get a chance! Link to comment https://forums.kleientertainment.com/forums/topic/165584-help-how-to-make-container-only-accept-certain-items/#findComment-1815286 Share on other sites More sharing options...
Doodle Monster Posted May 7, 2025 Author Share Posted May 7, 2025 Hmm, I tried both methods of renameing to match the prefab and replaceing the if not TheWorld function. Neither have worked I'll put my modmain and prefab file. Link to comment https://forums.kleientertainment.com/forums/topic/165584-help-how-to-make-container-only-accept-certain-items/#findComment-1815291 Share on other sites More sharing options...
Doodle Monster Posted May 7, 2025 Author Share Posted May 7, 2025 (edited) Modmain PrefabFiles = { "wramp_suitcase", } -- Load in some assets globally Assets = { Asset("ATLAS", "images/inventoryimages/wramp_suitcase.xml"), Asset("IMAGE", "images/inventoryimages/wramp_suitcase.tex"), } -- Load our item icon XMLs into the Minimap! AddMinimapAtlas("images/inventoryimages/wramp_suitcase.xml") -- Declare global variables local require = GLOBAL.require local STRINGS = GLOBAL.STRINGS local Ingredient = GLOBAL.Ingredient local RECIPETABS = GLOBAL.RECIPETABS local TECH = GLOBAL.TECH -- Custom strings! STRINGS.NAMES.WRAMP_SUITCASE = "Suit case" STRINGS.RECIPE_DESC.WRAMP_SUITCASE = "For packing away any clothes." STRINGS.CHARACTERS.GENERIC.DESCRIBE.WRAMP_SUITCASE = "This thing is heavy! What is in here?" -- Custom recipes! --[[ Default recipetabs: RECIPETABS.TOOLS RECIPETABS.LIGHT RECIPETABS.SURVIVAL RECIPETABS.FARM RECIPETABS.SCIENCE RECIPETABS.WAR RECIPETABS.TOWN RECIPETABS.SEAFARING RECIPETABS.REFINE RECIPETABS.MAGIC RECIPETABS.DRESS Default tech levels (science level you need to craft the item): TECH.NONE TECH.SCIENCE_ONE TECH.SCIENCE_TWO TECH.SCIENCE_THREE TECH.MAGIC_TWO TECH.MAGIC_THREE ]] AddCharacterRecipe("wramp_suitcase", { -- recipes.lua or recipe.lua GLOBAL.Ingredient("decrease_sanity", 10), GLOBAL.Ingredient("nightmarefuel", 4) }, GLOBAL.TECH.MAGIC_TWO, -- techtree.lua { -- recipe.lua builder_tag = "wramp_crafter", atlas = "images/inventoryimages/wramp_suitcase.xml", -- if this is an inventory item, only add this if you want the recipe image to be different than your inventory item image. otherwise, make an inventory item atlas for your item. image = "wramp_suitcase.tex", }, { -- recipes_filter.lua "DRESS", }) GLOBAL.setfenv(1, GLOBAL) local params = require("containers").params local widget_wramp_suitcase = { widget = { slotpos = {}, pos = Vector3(0, 200, 0), side_align_tip = 160, }, type = "chest", } for y = 2, 0, -1 do for x = 0, 2 do table.insert(widget_wramp_suitcase.widget.slotpos, Vector3(80 * x - 80 * 2 + 80, 80 * y - 80 * 2 + 80, 0)) end end --[[wramp_suitcase WRAMP_SUITCASE ]] Edited May 7, 2025 by Doodle Monster Link to comment https://forums.kleientertainment.com/forums/topic/165584-help-how-to-make-container-only-accept-certain-items/#findComment-1815292 Share on other sites More sharing options...
Doodle Monster Posted May 7, 2025 Author Share Posted May 7, 2025 And the prefab file local Assets = { -- Animation files for the item (showing it on the ground and swap symbols for the players). Asset("ANIM", "anim/wramp_suitcase_ground.zip"), -- Inventory image and atlas file used for the item. Asset("ATLAS", "images/inventoryimages/wramp_suitcase.xml"), Asset("IMAGE", "images/inventoryimages/wramp_suitcase.tex"), } local function onopen(inst) inst.SoundEmitter:PlaySound("qol1/ancientboat/chest_open_f2") end local function onclose(inst) inst.SoundEmitter:PlaySound("qol1/ancientboat/chest_close_f2") end local function OnPutInInventory(inst) inst.components.container:Close() end local function MainFunction() -- Functions which are performed both on Client and Server start here. local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() inst.entity:AddSoundEmitter() MakeInventoryPhysics(inst) -- Add minimap icon. Remember about its XML in modmain.lua! local minimap = inst.entity:AddMiniMapEntity() minimap:SetIcon("wramp_suitcase.tex") --[[ ANIMSTATE ]]-- -- This is the name visible on the top of hierarchy in Spriter. inst.AnimState:SetBank("wramp_suitcase_ground") -- This is the name of your compiled*.zip file. inst.AnimState:SetBuild("wramp_suitcase_ground") -- This is the animation name while item is on the ground. inst.AnimState:PlayAnimation("anim") --[[ TAGS ]]-- inst:AddTag("wramp_suitcase") MakeInventoryFloatable(inst, "small", 0.05, {1.2, 0.75, 1.2}) inst.entity:SetPristine() if not TheWorld.ismastersim then inst:DoTaskInTime(0, function(inst) inst.replica.container:WidgetSetup("wramp_suitcase") -- Sets up the widget for the client too end) return inst end inst:AddComponent("inspectable") inst:AddComponent("container") inst.components.container:WidgetSetup("wramp_suitcase") inst.components.container.onopenfn = onopen inst.components.container.onclosefn = onclose inst.components.container.skipclosesnd = true inst.components.container.skipopensnd = true inst.components.container.droponopen = true inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "wramp_suitcase" inst.components.inventoryitem.atlasname = "images/inventoryimages/wramp_suitcase.xml" inst.components.inventoryitem:SetOnPutInInventoryFn(OnPutInInventory) inst.components.inventoryitem.canonlygoinpocket = true inst:AddComponent("lootdropper") --new new code MakeHauntableLaunch(inst) return inst end return Prefab("common/inventory/wramp_suitcase", MainFunction, Assets) Link to comment https://forums.kleientertainment.com/forums/topic/165584-help-how-to-make-container-only-accept-certain-items/#findComment-1815293 Share on other sites More sharing options...
Doodle Monster Posted May 7, 2025 Author Share Posted May 7, 2025 My crash is still the same, I think something might be wrong with the way I set up the widget? @Merkyrrie Link to comment https://forums.kleientertainment.com/forums/topic/165584-help-how-to-make-container-only-accept-certain-items/#findComment-1815294 Share on other sites More sharing options...
Merkyrrie Posted May 7, 2025 Share Posted May 7, 2025 3 hours ago, Doodle Monster said: Modmain PrefabFiles = { "wramp_suitcase", } -- Load in some assets globally Assets = { Asset("ATLAS", "images/inventoryimages/wramp_suitcase.xml"), Asset("IMAGE", "images/inventoryimages/wramp_suitcase.tex"), } -- Load our item icon XMLs into the Minimap! AddMinimapAtlas("images/inventoryimages/wramp_suitcase.xml") -- Declare global variables local require = GLOBAL.require local STRINGS = GLOBAL.STRINGS local Ingredient = GLOBAL.Ingredient local RECIPETABS = GLOBAL.RECIPETABS local TECH = GLOBAL.TECH -- Custom strings! STRINGS.NAMES.WRAMP_SUITCASE = "Suit case" STRINGS.RECIPE_DESC.WRAMP_SUITCASE = "For packing away any clothes." STRINGS.CHARACTERS.GENERIC.DESCRIBE.WRAMP_SUITCASE = "This thing is heavy! What is in here?" -- Custom recipes! --[[ Default recipetabs: RECIPETABS.TOOLS RECIPETABS.LIGHT RECIPETABS.SURVIVAL RECIPETABS.FARM RECIPETABS.SCIENCE RECIPETABS.WAR RECIPETABS.TOWN RECIPETABS.SEAFARING RECIPETABS.REFINE RECIPETABS.MAGIC RECIPETABS.DRESS Default tech levels (science level you need to craft the item): TECH.NONE TECH.SCIENCE_ONE TECH.SCIENCE_TWO TECH.SCIENCE_THREE TECH.MAGIC_TWO TECH.MAGIC_THREE ]] AddCharacterRecipe("wramp_suitcase", { -- recipes.lua or recipe.lua GLOBAL.Ingredient("decrease_sanity", 10), GLOBAL.Ingredient("nightmarefuel", 4) }, GLOBAL.TECH.MAGIC_TWO, -- techtree.lua { -- recipe.lua builder_tag = "wramp_crafter", atlas = "images/inventoryimages/wramp_suitcase.xml", -- if this is an inventory item, only add this if you want the recipe image to be different than your inventory item image. otherwise, make an inventory item atlas for your item. image = "wramp_suitcase.tex", }, { -- recipes_filter.lua "DRESS", }) GLOBAL.setfenv(1, GLOBAL) local params = require("containers").params local widget_wramp_suitcase = { widget = { slotpos = {}, pos = Vector3(0, 200, 0), side_align_tip = 160, }, type = "chest", } for y = 2, 0, -1 do for x = 0, 2 do table.insert(widget_wramp_suitcase.widget.slotpos, Vector3(80 * x - 80 * 2 + 80, 80 * y - 80 * 2 + 80, 0)) end end --[[wramp_suitcase WRAMP_SUITCASE ]] Do you have a line in modmain like this params.wramp_suitcase = widget_wramp_suitcase Link to comment https://forums.kleientertainment.com/forums/topic/165584-help-how-to-make-container-only-accept-certain-items/#findComment-1815306 Share on other sites More sharing options...
Doodle Monster Posted May 7, 2025 Author Share Posted May 7, 2025 No I do not! I'll add it Link to comment https://forums.kleientertainment.com/forums/topic/165584-help-how-to-make-container-only-accept-certain-items/#findComment-1815327 Share on other sites More sharing options...
Doodle Monster Posted May 7, 2025 Author Share Posted May 7, 2025 The Widget works! Thanks for the help! Link to comment https://forums.kleientertainment.com/forums/topic/165584-help-how-to-make-container-only-accept-certain-items/#findComment-1815329 Share on other sites More sharing options...
Doodle Monster Posted May 7, 2025 Author Share Posted May 7, 2025 (edited) I know this isn't a functionality thing; but do you know how I would get it to look like the regular chest? Edited May 7, 2025 by Doodle Monster Link to comment https://forums.kleientertainment.com/forums/topic/165584-help-how-to-make-container-only-accept-certain-items/#findComment-1815342 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