Jump to content

Recommended Posts

I made a simple mod, that adds a backpack to starting inventory
But it seems, that  this mod works only with default characters, and don't work with custom characters
How can i fix that

This is "modmain.lua"
 

local default_inv = {"backpack"} 
local function setStarterInventory(inst, custom_inv)
local st_inv = inst.components.inventory.starting_inventory
if (st_inv) then 
for k,v in pairs(default_inv) do
table.insert(st_inv, v)
end
else 
inst.components.inventory.starting_inventory = default_inv
end
if (custom_inv) then 
for k,v in pairs(custom_inv)  do
table.insert(inst.components.inventory.starting_inventory, v)
end
end
end
 
local function makePostInit(custom_inv)
return function (inst)
setStarterInventory(inst, custom_inv)
end
end

If you can't just add it to the starter inventory, try using "AddSimPostInit". It's explained it a mod called "APIexamples" and runs when the player spawns in a newly created world. Then calculate random offset (as in other game files, "waxwelljournal" for example) and spawn a backpack.

You may need to add a "InCave" check. I could write it should you still struggle when I'm back in... ten hours...

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