Jump to content

Recommended Posts

I'm creating an item similar to Walter's slingshot that contains an item slot. Whenever I equip the item in a world with caves enabled, the game gives me this crash screen:

image.thumb.png.257774e3eefec1a165b42b04467ab6da.png

This report doesn't give me the exact line of code in my mod like I'm used to with most crash screens, and when I go to line 30 in containerwidget.lua, I still can't find any pointers as to why my game is still crashing! :confusion:

containerwidget.lua:
image.png.7963f093c2e19438c81abc4f047401bf.png

 

Here is my snippet of code in my modmain.lua that I believe creates the container:

local function CreateSpecialSlingshotWidget()
	local params = containers.params

	params.specialslingshot =
	{
		widget =
		{
        slotpos =
        {
            Vector3(0,   32 + 4,  0),
        },
        slotbg =
        {
            { image = "slingshot_ammo_slot.tex" },
        },
        animbank = "ui_cookpot_1x2",
        animbuild = "ui_cookpot_1x2",
        pos = Vector3(0, 15, 0),
    },
    usespecificslotsforitems = true,
    type = "hand_inv",
    excludefromcrafting = true,
	}
	
	containers.MAXITEMSLOTS = math.max(containers.MAXITEMSLOTS, params.specialslingshot.widget.slotpos ~= nil and #params.specialslingshot.widget.slotpos or 0)

	local old_widgetsetup = containers.widgetsetup
	
	function containers.widgetsetup(container, prefab, data)
		local pref = prefab or container.inst.prefab
		
		if pref == "specialslingshot" 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, data)
		end
	end
	
	function params.specialslingshot.itemtestfn(container, item, slot)
		return item:HasTag("specialitem")
	end
end

CreateSpecialSlingshotWidget()

 

Two steps.

1.in prefab, server

inst:AddComponent("container")
inst.components.container:WidgetSetup("piggyback")

2.in prefab, client. If you are not registering a widget that has its name exactly the same as the prefab

if not TheWorld.ismastersim then
    inst.OnEntityReplicated = function(inst)
      if inst.replica.container then inst.replica.container:WidgetSetup("piggyback") end
    end
    return inst
end

or

2.in modmain, both server and client, the name must match the prefab

local params=require("containers").params
params.piggyback={...(params you would like)}

 

  • Thanks 2
14 hours ago, Rickzzs said:

 

if not TheWorld.ismastersim then
    inst.OnEntityReplicated = function(inst)
      if inst.replica.container then inst.replica.container:WidgetSetup("piggyback") end
    end
    return inst
end
 

Thank you, this simple change did just the trick!

I know this thread is EXTREMELY old but this helped me figure out a problem I had with changing the properties of the spice pack to the same slot capacity of the krampus sack.

 

I didn't know the game ran on like, two 'dimensions' if caves are added. Thanks to the both of you.

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
×
  • Create New...