Jump to content

How to spawn a bag with specific items?


Archsaint

Recommended Posts

For my mod, choosing a certain occupation will start the player with a bag (the bag has a unique item name).

I want that bag to be full of other items I added to the mod, instead of being empty in the player's inventory.

Is there a way to have specific items spawn inside a custom bag?

Link to comment
Share on other sites

Project Zomboid\media\lua\client\Items\SpawnItems.lua

local SpawnItems = {};
 
function SpawnItems.OnNewGame(playerObj, square)
    -- spawn with a belt
    local belt = playerObj:getInventory():AddItem("Base.Belt2");
    playerObj:setWornItem(belt:getBodyLocation(), belt);
Personally I played around with the starter kit a bit and got errors alot. Due to that it starts with a spear inside instead of a bat despite the bat being in the code there so I would backup the whole file before playing around with it.
 
        local bag =  playerObj:getInventory():FindAndReturn("Base.Bag_Schoolbag");
        if not bag then
            bag = playerObj:getInventory():AddItem("Base.Bag_Schoolbag");
            playerObj:getInventory():AddItem("Base.WaterBottleFull");
            bag:getItemContainer():AddItem("Base.BaseballBat");
            bag:getItemContainer():AddItem("Base.Hammer");
            playerObj:getInventory():AddItem("Base.Crisps");
            playerObj:setClothingItem_Back(bag);
thats how it looks like with the things in the bag but the first part is to spawn for every game, this is for spawning with starter kit so just drag the starter kit stuff over and paste the stuff you want inside
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
×
×
  • Create New...