Jump to content

Need help container change slot size


Recommended Posts

Please help!

Any containers normal works!

The problem appearsafter adding spicepack, if select 8, 10, 12 slots, after creating prefab spicepack crashed:

[00:02:13]: [string "scripts/components/container.lua"]:104: assertion failed!
LUA ERROR stack traceback:
    =[C]:-1 in (global) assert (C) <-1--1>
    scripts/components/container.lua:104 in (method) SetNumSlots (Lua) <103-106>
    ../mods/Configurate Storage(TEST)/modmain.lua:153 in (field) widgetsetup (Lua) <39-175>
    scripts/components/container.lua:69 in (method) WidgetSetup (Lua) <64-75>
    scripts/prefabs/spicepack.lua:93 in (field) fn (Lua) <53-107>
    scripts/mainfunctions.lua:300 in () ? (Lua) <289-331>
    =[C]:-1 in (method) SpawnPrefab (C) <-1--1>
    scripts/mainfunctions.lua:348 in (global) SpawnPrefab (Lua) <342-350>
    scripts/components/builder.lua:461 in () ? (Lua) <412-558>
    =(tail call):-1 in ()  (tail) <-1--1>
    scripts/bufferedaction.lua:25 in (method) Do (Lua) <21-35>
    scripts/entityscript.lua:1369 in (method) PerformBufferedAction (Lua) <1356-1379>
    scripts/stategraphs/SGwilson.lua:5313 in (field) ontimeout (Lua) <5306-5314>
    scripts/stategraph.lua:554 in (method) UpdateState (Lua) <540-584>
    scripts/stategraph.lua:611 in (method) Update (Lua) <603-631>
    scripts/stategraph.lua:128 in (method) Update (Lua) <109-153>
    scripts/update.lua:239 in () ? (Lua) <170-249>

My script:

Assets = {
  Asset("ATLAS", "images/container.xml"),
  Asset("ATLAS", "images/container_x20.xml"),
  Asset("ATLAS", "images/krampus_sack_bg.xml"),
}
--Make Global
local require = GLOBAL.require
local Vector3 = GLOBAL.Vector3
local net_entity = GLOBAL.net_entity
--Require                     
local containers = require("containers")

--LOAD VALUE IN MODINFO
containers.MAXITEMSLOTS = math.max(containers.MAXITEMSLOTS, 24)
--Type Backpack
local BackpackSlotMax = GetModConfigData("BackpackSlotMax") 
local PiggybackSlotMax = GetModConfigData("PiggybackSlotMax")
local KrampussackSlotMax = GetModConfigData("KrampussackSlotMax")
local IcepackSlotMax = GetModConfigData("IcepackSlotMax")
--local SpicepackSlotMax = GetModConfigData("SpicepackSlotMax")
--Type Chest
local ChestSlotMax = GetModConfigData("ChestSlotMax")    
local IceboxSlotMax = GetModConfigData("IceboxSlotMax")
local SaltboxSlotMax = GetModConfigData("SaltboxSlotMax")
local DragonflychestSlotMax = GetModConfigData("DragonflychestSlotMax")


  local function addItemSlotNetvarsInContainer(inst)
     if(#inst._itemspool < containers.MAXITEMSLOTS) then
        for i = #inst._itemspool+1, containers.MAXITEMSLOTS do
            table.insert(inst._itemspool, net_entity(inst.GUID, "container._items["..tostring(i).."]", "items["..tostring(i).."]dirty"))
        end
     end
  end
  AddPrefabPostInit("container_classified", addItemSlotNetvarsInContainer)

--Change size of Backpacks, Chests, Bundles, and Chester
  local widgetsetup_Base = containers.widgetsetup or function() return true end
  function containers.widgetsetup(container, prefab, data, ...)
  	local tempPrefab = prefab or container.inst.prefab
  	local result = widgetsetup_Base(container, prefab, data, ...)  
   function NewCustomContainers(Type, SlotMax)
		if Type == "Backpack" then
			if SlotMax == 10 then
				container.widget.animbank = "ui_krampusbag_2x5"
				container.widget.animbuild = "ui_krampusbag_2x5"
				container.widget.pos = Vector3(-5, -70, 0)
				for y = 0, 4 do
					table.insert(container.widget.slotpos, Vector3(-162, -75 * y + 115, 0))
					table.insert(container.widget.slotpos, Vector3(-162 + 75, -75 * y + 115, 0))
				end
			elseif SlotMax == 12 then
				container.widget.animbank = "ui_piggyback_2x6"
				container.widget.animbuild = "ui_piggyback_2x6"
				container.widget.pos = Vector3(-5, -50, 0)
				for y = 0, 5 do
					table.insert(container.widget.slotpos, Vector3(-162, -75 * y + 170, 0))
					table.insert(container.widget.slotpos, Vector3(-162 + 75, -75 * y + 170, 0))
				end
			elseif SlotMax == 14 then
				container.widget.animbank = "ui_krampusbag_2x8"
				container.widget.animbuild = "ui_krampusbag_2x8"
				container.widget.pos = Vector3(-5, -120, 0)
				for y = 0, 6 do
					table.insert(container.widget.slotpos, Vector3(-162, -y*75 + 240 ,0))
					table.insert(container.widget.slotpos, Vector3(-162 +75, -y*75 + 240 ,0))
				end	
			elseif SlotMax == 16 then
				container.widget.animbank = "ui_krampusbag_2x8"
				container.widget.animbuild = "ui_krampusbag_2x8"
				container.widget.pos = Vector3(-5, -50, 0)
				for y = 0, 7 do
					table.insert(container.widget.slotpos, Vector3(-162, -65 * y + 245, 0))
					table.insert(container.widget.slotpos, Vector3(-162 + 75, -65 * y + 245, 0))
				end  
			elseif SlotMax == 18 then
				container.widget.animbank = nil
				container.widget.animbuild = nil
				container.widget.bgatlas = "images/krampus_sack_bg.xml"
				container.widget.bgimage = "krampus_sack_bg.tex"
				container.widget.pos = Vector3(-76,-70,0)
				for y = 0, 8 do
					table.insert(container.widget.slotpos, Vector3(-37, -y*75 + 300 ,0))
					table.insert(container.widget.slotpos, Vector3(-37 +75, -y*75 + 300 ,0))
				end		
			end
		elseif Type == "Chest" then
			if SlotMax == 12 then
				container.widget.animbank = "ui_chester_shadow_3x4"
				container.widget.animbuild = "ui_chester_shadow_3x4"
				for y = 2.5, -0.5, -1 do
					for x = 0, 2 do
						table.insert(container.widget.slotpos, Vector3(75 * x - 75 * 2 + 75, 75 * y - 75 * 2 + 75, 0))
					end     
				end	
			elseif SlotMax == 16 then
				container.widget.animbank = nil
				container.widget.animbuild = nil
				container.widget.bgatlas = "images/container.xml"
				container.widget.bgimage = "container.tex"
				container.widget.bgimagetint = {r=.82,g=.77,b=.7,a=1}
				for y = 3, 0, -1 do
					for x = 0, 3 do
						table.insert(container.widget.slotpos, Vector3(80*x-80*2+40, 80*y-80*2+40,0))
					end
				end
			elseif SlotMax == 20 then
				container.widget.animbank = nil
				container.widget.animbuild = nil
				container.widget.bgatlas = "images/container_x20.xml"
				container.widget.bgimage = "container_x20.tex"
				container.widget.bgimagetint = {r=.82,g=.77,b=.7,a=1}
				for y = 3, 0, -1 do
					for x = 0, 4 do
						table.insert(container.widget.slotpos, Vector3(75*x-75*2+0, 75*y-75*2+40,0))
					end
				end
			elseif SlotMax == 24 then
				container.widget.animbank = nil
				container.widget.animbuild = nil
				container.widget.bgatlas = "images/container_x20.xml"
				container.widget.bgimage = "container_x20.tex"
				container.widget.bgimagetint = {r=.82,g=.77,b=.7,a=1}
				for y = 3, 0, -1 do
					for x = 0, 5 do
						table.insert(container.widget.slotpos, Vector3(65*x-65*2-33, 80*y-80*2+38,0))
					end
				end
			end
		end
	end
--Type Backpack
--Back Pack   
  	if(tempPrefab == "backpack" and BackpackSlotMax ~= 8) then
		container.widget.slotpos = {}
		NewCustomContainers("Backpack", BackpackSlotMax)
		container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)
	elseif (tempPrefab == "piggyback" and PiggybackSlotMax ~= 12) then
		container.widget.slotpos = {}
		NewCustomContainers("Backpack", PiggybackSlotMax)
		container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)
	elseif (tempPrefab == "krampus_sack" and KrampussackSlotMax ~= 14) then
		container.widget.slotpos = {}
		NewCustomContainers("Backpack", KrampussackSlotMax)
		container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)
	elseif (tempPrefab == "icepack" and IcepackSlotMax ~= 8) then
		container.widget.slotpos = {}
		NewCustomContainers("Backpack", IcepackSlotMax)
		container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)
	elseif (tempPrefab == "spicepack" and SpicepackSlotMax ~= 6) then
		container.widget.slotpos = {}
		NewCustomContainers("Backpack", SpicepackSlotMax)
		container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)
		
--Type Chest
--Chest	  
    elseif(tempPrefab == "treasurechest" and ChestSlotMax ~= 9) then
      container.widget.slotpos = {}
	  NewCustomContainers("Chest", ChestSlotMax)
  	  container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)
	elseif(tempPrefab == "icebox" and IceboxSlotMax ~= 9) then
      container.widget.slotpos = {}
	  NewCustomContainers("Chest", IceboxSlotMax)
  	  container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)
	elseif(tempPrefab == "saltbox" and SaltboxSlotMax ~= 9) then
      container.widget.slotpos = {}
	  NewCustomContainers("Chest", SaltboxSlotMax)
  	  container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)
	elseif(tempPrefab == "dragonflychest" and DragonflychestSlotMax ~= 12) then
      container.widget.slotpos = {}
	  NewCustomContainers("Chest", DragonflychestSlotMax)
  	  container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)
  	end 
   return result
  end

 


 

 

Link to comment
Share on other sites

Trouble this! After spawn prefab error assertion failed!

elseif (tempPrefab == "spicepack" and SpicepackSlotMax ~= 6) then
		container.widget.slotpos = {}
		NewCustomContainers("Backpack", SpicepackSlotMax)
		container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)

modmain.lua preview.tex preview.xml modinfo.lua container.tex container.xml container_x20.tex container_x20.xml krampus_sack_bg.tex krampus_sack_bg.xml

Edited by DiRten
Add files.
Link to comment
Share on other sites

The problem lies in the fact that the spicepack has normally 14 slots and if you have less, the game will always crash at this assert.

I had the same problem in one of my mods where I tried to change the size of backpacks, aslso to smaller sizes.

I think I fixed it by adding this piece of code beforehand:

removesetter(container, "numslots")	
container.numslots = SlotMax

Try adding it at the beginning of your NewCustomContainers function.

removesetter removes the unability to change numslots and then you change the numslots to the number you want.

  • Like 1
Link to comment
Share on other sites

58 minutes ago, Monti18 said:

Проблема заключается в том, что в пакете специй обычно 14 слотов, и если у вас их меньше, игра всегда вылетает при этом утверждении.

У меня была такая же проблема в одном из моих модов, когда я пытался изменить размер рюкзака, а также на меньшие размеры.

Думаю, я исправил это, предварительно добавив этот фрагмент кода:


 

Попробуйте добавить его в начало функции NewCustomContainers.

removesetter удаляет невозможность изменить numslots, а затем вы меняете numslots на желаемое число.

Spicepack(this Chef Pouch) have 6 slot for dst.

Chef Pouch
Add you code:

:48: attempt to call global 'removesetter' (a nil value)
LUA ERROR stack traceback:
    ../mods/Configurate Storage(TEST)/modmain.lua:48 in (global) NewCustomContainers (Lua) <47-161>
    ../mods/Configurate Storage(TEST)/modmain.lua:194 in (field) widgetsetup (Lua) <44-211>
    scripts/components/container.lua:69 in (method) WidgetSetup (Lua) <64-75>
    scripts/prefabs/icebox.lua:76 in (field) fn (Lua) <46-96>
    scripts/mainfunctions.lua:300 in () ? (Lua) <289-331>
    =[C]:-1 in (method) SpawnPrefab (C) <-1--1>
    scripts/mainfunctions.lua:348 in (global) SpawnPrefab (Lua) <342-350>
    scripts/mainfunctions.lua:365 in (global) SpawnSaveRecord (Lua) <363-405>
    scripts/gamelogic.lua:592 in (upvalue) PopulateWorld (Lua) <349-628>
    scripts/gamelogic.lua:852 in (upvalue) DoInitGame (Lua) <727-931>
    scripts/gamelogic.lua:965 in (local) cb (Lua) <959-966>
    scripts/shardindex.lua:209 in (upvalue) OnLoadSaveDataFile (Lua) <191-210>

After use:

   function NewCustomContainers(Type, SlotMax, Custom)
		GLOBAL.removesetter(container, "numslots")	
		container.numslots = SlotMax
  		...................

and tested spicepack: error assertion again.

I tested piggypack, set size smaller than default,

error assertion again.

Edited by DiRten
Link to comment
Share on other sites

2 hours ago, Monti18 said:

The problem lies in the fact that the spicepack has normally 14 slots and if you have less, the game will always crash at this assert.

I had the same problem in one of my mods where I tried to change the size of backpacks, aslso to smaller sizes.

I think I fixed it by adding this piece of code beforehand:


removesetter(container, "numslots")	
container.numslots = SlotMax

Try adding it at the beginning of your NewCustomContainers function.

removesetter removes the unability to change numslots and then you change the numslots to the number you want.

Maybe problem here?:

containers.MAXITEMSLOTS = math.max(containers.MAXITEMSLOTS, 24)
  local function addItemSlotNetvarsInContainer(inst)
     if(#inst._itemspool < containers.MAXITEMSLOTS) then
        for i = #inst._itemspool+1, containers.MAXITEMSLOTS do
            table.insert(inst._itemspool, net_entity(inst.GUID, "container._items["..tostring(i).."]", "items["..tostring(i).."]dirty"))
        end
     end
  end
  AddPrefabPostInit("container_classified", addItemSlotNetvarsInContainer)

 

Link to comment
Share on other sites

I just tried it using the code that you posted and I had no problems.

image.thumb.png.2db1e855cbf07c76f2054dacb211c665.png

For 8 slots, I can see why it crashes, as you call

container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)

but you didn't define the case for 8 slots, so it will default to 0, which is less than self.numslots, which will cause the crash. For the others I don't know.

I think it would be better to change the 0 in the function before to container.numslots, this way you won't get the crash even if it doesn't work.

  • Like 1
Link to comment
Share on other sites

6 hours ago, Monti18 said:

I just tried it using the code that you posted and I had no problems.

image.thumb.png.2db1e855cbf07c76f2054dacb211c665.png

For 8 slots, I can see why it crashes, as you call


container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)

but you didn't define the case for 8 slots, so it will default to 0, which is less than self.numslots, which will cause the crash. For the others I don't know.

I think it would be better to change the 0 in the function before to container.numslots, this way you won't get the crash even if it doesn't work.

I'm tired, doesn't work. Please, help. :'(

I add case 8 slots.

using 8 - crashed.

using 10 - crashed.

I don’t understand what the problem is, other containers do not cause problems when enlarged. There are errors when trying to set smaller of default slot, but not exaggerate. Other containers are stable.

Configurate Storage(TEST).rar

client_log.txt

Edited by DiRten
I add log
Link to comment
Share on other sites

6 hours ago, Monti18 said:

I just tried it using the code that you posted and I had no problems.

image.thumb.png.2db1e855cbf07c76f2054dacb211c665.png

For 8 slots, I can see why it crashes, as you call


container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)

but you didn't define the case for 8 slots, so it will default to 0, which is less than self.numslots, which will cause the crash. For the others I don't know.

I think it would be better to change the 0 in the function before to container.numslots, this way you won't get the crash even if it doesn't work.

Ahahahahah 

--local SpicepackSlotMax = GetModConfigData("SpicepackSlotMax")

My fault. I am stupid.:wilson_cry::wilson_enraged:

Link to comment
Share on other sites

7 hours ago, Monti18 said:

I just tried it using the code that you posted and I had no problems.

image.thumb.png.2db1e855cbf07c76f2054dacb211c665.png

For 8 slots, I can see why it crashes, as you call


container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)

but you didn't define the case for 8 slots, so it will default to 0, which is less than self.numslots, which will cause the crash. For the others I don't know.

I think it would be better to change the 0 in the function before to container.numslots, this way you won't get the crash even if it doesn't work.

Thanks to you, I have a new function, setting values less than standard. :wilson_love:

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...