Jump to content

Recommended Posts

Currently making another character and I wanted to give him a custom backpack that he spawns in with and can't unequip. I'm having an issue with getting him to spawn in with it, but my main problem is that whenever I try to pick it up after spawning it in, my game crashes.

I used the code for DST's backpacks and tried using other forum posts for help, but I'm still getting errors..... Idk if this is just a case of me being dumb and misunderstanding things but it seems like no matter what I do I keep getting errors

Currently my log says: [string "scripts/containers.lua"]:10: attempt to index local 'container' (a nil value)

But none of the fixes I found online worked 😕

modmain and item prefab code:

Spoiler

image.png.c2735226ce26d50764ed3389318e5b0d.png

sbt2.png.739503fd4019425ce189fe080928c3f0.png

 

Any help is greatly appreciated!

Apparently the problem is being caused by

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

because inst.replica does not contain "container"

This may be because you are calling that block of code before placing the "container" component. Maybe it can be solved like this:

inst:AddComponent("container")
inst.components.container:WidgetSetup("solbag")
inst.components.container.skipclosesnd = true
inst.components.container.skipopensnd = true

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

If that doesn't work, then you may need to look at the replica components rather than the replica itself.

inst:AddComponent("container")
inst.components.container:WidgetSetup("solbag")
inst.components.container.skipclosesnd = true
inst.components.container.skipopensnd = true

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

It is difficult to diagnose because I don't know what things are in the replica object when the OnEntityReplicated function is called.

1 hour ago, seraph780 said:

Thank you for responding! I seem to be having the same error, do you need the entire item file? (I'm new to this sorry 😭)

solbag.lua 3.6 kB · 0 downloads

try this: 

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

 

1 hour ago, FerniFrenito said:

try this: 

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

 

still getting the same error 😢

do you need any of my other files?

1 hour ago, seraph780 said:

still getting the same error 😢

do you need any of my other files?

If the following doesn't solve the problem, I would like you to send the .zip with your entire mod so I can run the code on my computer.

From what I see in the game code, .replica is never used in OnEntityReplicated, which makes me think that inst is the replica itself, but I also saw that that part only handles things like tags and stuff like that.

To tell you the truth, I've never understood what object replicas are for, but from what I see, it has something to do with server-client communication.

Are you sure you need to do that in the replica? I'm viewing the code for the backpacks in the game, and 1. none of them have the OnEntityReplicated function, and 2. they all use WidgetSetup() only once, after adding the component.

I already saw the problem, but I need you to send me the complete traceback.

2 hours ago, FerniFrenito said:

If the following doesn't solve the problem, I would like you to send the .zip with your entire mod so I can run the code on my computer.

From what I see in the game code, .replica is never used in OnEntityReplicated, which makes me think that inst is the replica itself, but I also saw that that part only handles things like tags and stuff like that.

To tell you the truth, I've never understood what object replicas are for, but from what I see, it has something to do with server-client communication.

Are you sure you need to do that in the replica? I'm viewing the code for the backpacks in the game, and 1. none of them have the OnEntityReplicated function, and 2. they all use WidgetSetup() only once, after adding the component.

I already saw the problem, but I need you to send me the complete traceback.

Honestly I'm not entirely sure what I'm doing with the item's code since this is my first time trying to make something like this....

Also I tried to turn the mod into a zip, but the forums won't let me post them here. Is there some other way to send them? Only way I can think right now is submitting it as an unlisted mod to the steam workshop

The error isn't in the code. You can leave it as it was originally. It's in the WidgetSetup("solbag") argument. What is "solbag"? Is it a prefab in your mod?

It's weird that it won't let you publish the mod, but yes, you can add me on steam or I can add you and you can publish the mod only for friends.

1 minute ago, FerniFrenito said:

The error isn't in the code. You can leave it as it was originally. It's in the WidgetSetup("solbag") argument. What is "solbag"? Is it a prefab in your mod?

It's weird that it won't let you publish the mod, but yes, you can add me on steam or I can add you and you can publish the mod only for friends.

Yes, solbag is the name of the item (short for solace's bag)

It won't let me post it here since it's too big apparently, my steam is kyupita (friend code: 1040528481)

17 hours ago, seraph780 said:

Yes, solbag is the name of the item (short for solace's bag)

It won't let me post it here since it's too big apparently, my steam is kyupita (friend code: 1040528481)

The original problem was that the widget was being set to "backpack" instead of "solbag", so when trying to launch the widget, the game couldn't find the setting for the "solbag" widget because it didn't exist.

params.backpack =
{
    widget =
    {
        slotpos = {},
        animbank = "ui_backpack_2x4",
        animbuild = "ui_backpack_2x4",
        --pos = Vector3(-5, -70, 0),
        pos = Vector3(-5, -80, 0),        
    },
    issidewidget = true,
    type = "pack",
    openlimit = 1,
}

for y = 0, 3 do
    table.insert(params.backpack.widget.slotpos, Vector3(-162, -75 * y + 114, 0))
    table.insert(params.backpack.widget.slotpos, Vector3(-162 + 75, -75 * y + 114, 0))
end

The solution was simply to change "backpack" to "solbag"

params.solbag =
{
    widget =
    {
        slotpos = {},
        animbank = "ui_backpack_2x4",
        animbuild = "ui_backpack_2x4",
        --pos = Vector3(-5, -70, 0),
        pos = Vector3(-5, -80, 0),        
    },
    issidewidget = true,
    type = "pack",
    openlimit = 1,
}

for y = 0, 3 do
    table.insert(params.solbag.widget.slotpos, Vector3(-162, -75 * y + 114, 0))
    table.insert(params.solbag.widget.slotpos, Vector3(-162 + 75, -75 * y + 114, 0))
end

 

modmain.lua solbag.lua

  • Thanks 1

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...