sugarskull Posted December 11, 2019 Share Posted December 11, 2019 (edited) 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 December 11, 2019 by sugarskull Link to comment Share on other sites More sharing options...
Yossitaru Posted December 14, 2019 Share Posted December 14, 2019 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 More sharing options...
Nebula Posted December 16, 2019 Share Posted December 16, 2019 (edited) recipe Open Package { PackageClosed, keep KitchenKnife/HuntingKnife/MeatCleaver/LetterOpener/Scissors, Sound:PutItemInBag, Time:15.0, Result:PackageOpened, OnCreate:FillPackage, } Edited December 16, 2019 by Nebula Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now