Jump to content

Recipe creates a container - how to spawn loot inside?


sugarskull

Recommended Posts

I'm working on a mod where I want players to open packages and get random loot. I have also added distribution information such that players can find the packages and loot information for what should be inside the opened packages. However, the recipe only spawns empty containers, and does not populate them with items. (Note - if I spawn the open packages instead of closed packages in town they do show loot). Is there some OnCreate command I can use to fill the container with loot? Thanks so much!

 

item PackageOpened
{
    Type                = Container,
    DisplayName         = Open Package,
    Icon                = PackageOpened,
    Weight              = 0.1,
    Capacity            = 25,
    WeightReduction     = 25,
}

item PackageClosed
{
    Type                = Normal,
    DisplayName         = Package,
    Icon                = PackageClosed,
    Weight              = 0.5,
}

recipe Open Package
{
    PackageClosed,
    keep KitchenKnife/HuntingKnife/MeatCleaver/LetterOpener/Scissors,
    Result:PackageOpened,
    Sound:PutItemInBag,
    Time:15.0,
}
}

 

Edited by sugarskull
Link to comment
Share on other sites

As you noticed, the distributions table only populates items that are spawned by the world loot spawner. What you need to do here  is to make a custom OnCreate function that populates the open package with whatever items you had in mind. Since one of the three variables passed into the function is the result item, filling it is pretty trivial. Add a new lua file (or add the code to an existing lua file) in the mod's media\lua\server folder. And of course, call the function in the recipe's OnCreate parameter.

 

The following code will put a mirror or a credit card in the box with a 50/50 chance.

 

function FillPackage(items, result, player)
	local inv = result:getInventory();
	local randNum = ZombRand(2);
	if randNum == 0 then
		inv:AddItem("Base.Mirror");
	else
		inv.AddItem("Base.CreditCard");
	end
end 

 

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