Tosh Posted December 7, 2018 Share Posted December 7, 2018 I’m trying to make it so that a modded backpack only accepts single items, but I’m honestly stuck with how to do it. I tried putting in: inst.components.container.acceptsstacks = false After inst:AddComponent("container") In the modded backpack prefab lua. I’m not a coder, so I’m at a loss of what I’m missing or doing wrong. The server crashes at startup when I include that line, saying something about it being read only. Any help would be greatly appreciated! I’ll try to give more information tomorrow evening. Link to comment Share on other sites More sharing options...
Ultroman Posted December 7, 2018 Share Posted December 7, 2018 Please include a zip with your mod, and the entire error. Preferably the whole client_log.txt and both server_log.txt (there are only two if you made a server with caves). Link to comment Share on other sites More sharing options...
Tosh Posted December 7, 2018 Author Share Posted December 7, 2018 The server crashes when I craft the backpack that I want to add the code to (equip_pack). Some background information: I'm currently trying to fix the Additional Equipment mod by Silentine on the Steam Workshop. It's one of my favourite mods, but sadly it's been broken for years. If you could help me with this bit of code I'd really appreciate it! workshop-681368916-equip-fork.zip client_log.txt server_log (2).txt server_log.txt Link to comment Share on other sites More sharing options...
Tosh Posted December 8, 2018 Author Share Posted December 8, 2018 From what I can understand, container rules seem to be tied directly to the container widget set up. I’m going to see what I can find in the way of DST container widget tutorials. Link to comment Share on other sites More sharing options...
Ultroman Posted December 8, 2018 Share Posted December 8, 2018 1 hour ago, Tosh said: From what I can understand, container rules seem to be tied directly to the container widget set up. I’m going to see what I can find in the way of DST container widget tutorials. That sounds like a good plan. I'd love to help, but it'll be a few days before I can take a stab at something thing complex. I have a lot of assignments at uni atm. Link to comment Share on other sites More sharing options...
Developer zarklord_klei Posted December 8, 2018 Developer Share Posted December 8, 2018 (edited) in order to change something like that, you need to create a custom container widget to edit that, otherwise its set to be read only(so you cant edit the variable) if you really want to do it without container widgets you can (cheatily) do this: if not TheWorld.ismastersim then function inst.OnEntityReplicated(inst) --this gets called after every inst.replica, got initialized, and we need the variable changed for clients. inst.replica.containers.acceptsstacks = false end end inst:AddComponent("container") inst.components.container:WidgetSetup("WHATEVERYOUHADHERE") removesetter(inst.components.container, "acceptsstacks") --remove the read only property(please only do this if you really cant do it through widget setup) inst.components.containers.acceptsstacks = false makereadonly(inst.components.container, "acceptsstacks") --reapply read only inst.replica.containers.acceptsstacks = false Edited December 8, 2018 by Zarklord Link to comment Share on other sites More sharing options...
Tosh Posted December 8, 2018 Author Share Posted December 8, 2018 Thanks for getting back to me guys! I've since dug around in a few different mods and taught myself how to set up container widgets. This is the point that I've gotten to with this item: Quote local equip_pack = { widget = { slotpos = {}, animbank = "ui_piggyback_2x6", animbuild = "ui_piggyback_2x6", pos = Vector3(-5, -50, 0), }, issidewidget = true, type = "pack", } local containers = require("containers") local oldwidgetsetup = containers.widgetsetup function containers.widgetsetup(container, prefab, data, ...) if container.inst.prefab == "equip_pack" or prefab == "equip_pack" then for k, v in pairs(equip_pack) do container[k] = v end container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0) return end return oldwidgetsetup(container, prefab, data, ...) end This is mostly taken from the piggyback widget settings in containers.lua Quote params.piggyback = { widget = { slotpos = {}, animbank = "ui_piggyback_2x6", animbuild = "ui_piggyback_2x6", pos = Vector3(-5, -50, 0), }, issidewidget = true, type = "pack", } for y = 0, 5 do table.insert(params.piggyback.widget.slotpos, Vector3(-162, -75 * y + 170, 0)) table.insert(params.piggyback.widget.slotpos, Vector3(-162 + 75, -75 * y + 170, 0)) end So my current roadblock is slotpos. I either need to manually put in the coordinates in Vector 3 form for each backpack slot: Quote slotpos = { Vector3(0, 64 + 32 + 8 + 4, 0), Vector3(0, 32 + 4, 0), Vector3(0, -(32 + 4), 0), Vector3(0, -(64 + 32 + 8 + 4), 0), }, Or figure out how to convert the original formula (for y = 0, 5...) into a format that plays nice with what I currently have. I could also try and convert everything into a form where params.equip_pack is defined. Solved it! Quote slotpos = { Vector3(-162, -75 * 0 + 170, 0), Vector3(-162, -75 * 1 + 170, 0), Vector3(-162, -75 * 2 + 170, 0), Vector3(-162, -75 * 3 + 170, 0), Vector3(-162, -75 * 4 + 170, 0), Vector3(-162, -75 * 5 + 170, 0), Vector3(-162 + 75, -75 * 0 + 170, 0), Vector3(-162 + 75, -75 * 1 + 170, 0), Vector3(-162 + 75, -75 * 2 + 170, 0), Vector3(-162 + 75, -75 * 3 + 170, 0), Vector3(-162 + 75, -75 * 4 + 170, 0), Vector3(-162 + 75, -75 * 5 + 170, 0), }, Quote Vector3(-162, -75 * 0 + 170, 0), Vector3(-162 + 75, -75 * 0 + 170, 0), Vector3(-162, -75 * 1 + 170, 0), Vector3(-162 + 75, -75 * 1 + 170, 0), Vector3(-162, -75 * 2 + 170, 0), Vector3(-162 + 75, -75 * 2 + 170, 0), Vector3(-162, -75 * 3 + 170, 0), Vector3(-162 + 75, -75 * 3 + 170, 0), Vector3(-162, -75 * 4 + 170, 0), Vector3(-162 + 75, -75 * 4 + 170, 0), Vector3(-162, -75 * 5 + 170, 0), Vector3(-162 + 75, -75 * 5 + 170, 0), Changed it to this so that the item slots should fill in the correct order now. Link to comment Share on other sites More sharing options...
Developer zarklord_klei Posted December 9, 2018 Developer Share Posted December 9, 2018 18 hours ago, Tosh said: Thanks for getting back to me guys! I've since dug around in a few different mods and taught myself how to set up container widgets. This is the point that I've gotten to with this item: This is mostly taken from the piggyback widget settings in containers.lua So my current roadblock is slotpos. I either need to manually put in the coordinates in Vector 3 form for each backpack slot: Or figure out how to convert the original formula (for y = 0, 5...) into a format that plays nice with what I currently have. I could also try and convert everything into a form where params.equip_pack is defined. Solved it! Changed it to this so that the item slots should fill in the correct order now. local params = {} params.equip_pack = { widget = { slotpos = {}, animbank = "ui_piggyback_2x6", animbuild = "ui_piggyback_2x6", pos = Vector3(-5, -50, 0), }, issidewidget = true, type = "pack", } for y = 0, 5 do table.insert(params.equip_pack.widget.slotpos, Vector3(-162, -75 * y + 170, 0)) table.insert(params.equip_pack.widget.slotpos, Vector3(-162 + 75, -75 * y + 170, 0)) end local containers = require("containers") local oldwidgetsetup = containers.widgetsetup function containers.widgetsetup(container, prefab, data, ...) local t = data or params[prefab or container.inst.prefab] if t ~= nil then for k, v in pairs(t) do container[k] = v end container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0) return end return oldwidgetsetup(container, prefab, data, ...) end Link to comment Share on other sites More sharing options...
Tosh Posted December 10, 2018 Author Share Posted December 10, 2018 Is there a reason to build the widget using Params instead of how I did it? The mod is up here now if you want to have a look: https://steamcommunity.com/sharedfiles/filedetails/?id=1587240158 Link to comment Share on other sites More sharing options...
Developer zarklord_klei Posted December 11, 2018 Developer Share Posted December 11, 2018 On 12/9/2018 at 8:09 PM, Tosh said: Is there a reason to build the widget using Params instead of how I did it? The mod is up here now if you want to have a look: https://steamcommunity.com/sharedfiles/filedetails/?id=1587240158 it offers more flexibility, and works better with other mods... Link to comment Share on other sites More sharing options...
Tosh Posted December 11, 2018 Author Share Posted December 11, 2018 3 hours ago, Zarklord said: it offers more flexibility, and works better with other mods... That makes sense. I’ll look at updating the code later. Thanks for your help! Link to comment 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