Mentos Posted November 18, 2022 Share Posted November 18, 2022 (edited) i've been trying to add a custom widget for a custom backpack item, i managed to get it to work for the custom backpack, but it makes every container that is not my custom backpack crash when used. This is the code i have in my modmain local containers = require "containers" local params = {} containers.params = params 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) end end params.whiskpack = { widget = { slotpos = {}, animbank = "ui_krampusbag_2x8", animbuild = "ui_krampusbag_2x8", pos = Vector3(-5, -120, 0), }, issidewidget = true, type = "pack", openlimit = 1, } for y = 0, 6 do table.insert(params.whiskpack.widget.slotpos, Vector3(-162, -75 * y + 240, 0)) table.insert(params.whiskpack.widget.slotpos, Vector3(-162 + 75, -75 * y + 240, 0)) end function params.whiskpack.itemtestfn(container, item, slot) return item:HasTag("spider") or item:HasTag("cavedweller") or item:HasTag("spider_warrior") end params.whiskpack.priorityfn = params.whiskpack.itemtestfn If i remove my custom widget everything works fine, so i am clueless as to why it's crashing. Any help would be appreciated Edited November 18, 2022 by Mentos bruh Link to comment Share on other sites More sharing options...
Rickzzs Posted November 19, 2022 Share Posted November 19, 2022 why you erase every other container and override the widgetsetup function? Link to comment Share on other sites More sharing options...
Mentos Posted November 19, 2022 Author Share Posted November 19, 2022 oh i see what u mean. widgets are rly confusing to me sorry lol I've tried to go thru it one more time and looked at some other mods local params={} params.whiskpack = { widget = { slotpos = {}, animbank = "ui_krampusbag_2x8", animbuild = "ui_krampusbag_2x8", pos = GLOBAL.Vector3(-5, -120, 0), }, issidewidget = true, type = "pack", openlimit = 1, } for y = 0, 6 do table.insert(params.whiskpack.widget.slotpos, GLOBAL.Vector3(-162, -75 * y + 240, 0)) table.insert(params.whiskpack.widget.slotpos, GLOBAL.Vector3(-162 + 75, -75 * y + 240, 0)) end function params.whiskpack.itemtestfn(container, item, slot) return item:HasTag("spider") or item:HasTag("cavedweller") or item:HasTag("spider_warrior") end params.whiskpack.priorityfn = params.whiskpack.itemtestfn local containers = GLOBAL.require "containers" containers.MAXITEMSLOTS = math.max(containers.MAXITEMSLOTS, params.whiskpack.widget.slotpos ~= nil and #params.whiskpack.widget.slotpos or 0) local old_widgetsetup = containers.widgetsetup function containers.widgetsetup(container, prefab, data) local pref = prefab or container.inst.prefab if pref == "whiskpack" then local t = params[pref] 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) end else return old_widgetsetup(container, prefab) end end i think i managed to fix it, at least as far as i can tell 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