Jump to content
Sign in to follow this  
sugarskull

Recipe creates a container - how to spawn loot inside?

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

Share this post


Link to post
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 

 

Share this post


Link to post
Share on other sites

recipe Open Package

{

PackageClosed,

keep KitchenKnife/HuntingKnife/MeatCleaver/LetterOpener/Scissors,

Sound:PutItemInBag,

Time:15.0,

Result:PackageOpened,

OnCreate:FillPackage,

}

Edited by Nebula

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...