Jump to content

Recipe without result?


blindcoder

Recommended Posts

Hello.

 

I'm trying to do this with a recipe: Add one item to another via a recipe, destroying one item and keeping the other.

Currently my code looks like this:

recipe Add sheet of paper{keep BCMapMod.Map,SheetPaper=1,Time=25,Category:General,OnCreate:BCMapMop_AddPage}

I handle the modData manipulation in the OnCreate, but unfortunately the code breaks on Result being null.

I also tried adding a dummy item in the Result and removing it from the inventory in the OnCreate hook, but that doesn't work either, as the OnCreate is run before the Result is added to the inventory.

 

I also tried this:

recipe Add a page to map   {                            SheetPaper=1,              BCMapMod.Map,                                         Time:25,                   Category:General,          Result:BCMapMod.Map,       OnCreate:BCMapMod_AddPage}                          

And copied the modData in the OnCreate hook. This works nicely, but it has the flaw that I can only do one instance of the recipe at a time because the recipe code doesn't realize that I can do this recipe as often as I have sheets of paper in my inventory.

 

Any ideas?

Link to comment
Share on other sites

I get around this by either deleting an item in the recipie and then giving it back. Or making a junk item. Some examples ...

recipe Open Gift    {    HCXmasgift,       Result:HCCardboardbox,        Time:15,        OnCreate:HCRandomGiftGet,        Category:Leisure,    }
recipe Play With    {        HCToymonkey,    Result:HCToymonkey,    Time:500,    OnCreate:HC_ToyStatModifier,    Category:Leisure,    }
Link to comment
Share on other sites

 

I get around this by either deleting an item in the recipie and then giving it back. Or making a junk item. Some examples ...

recipe Open Gift    {    HCXmasgift,       Result:HCCardboardbox,        Time:15,        OnCreate:HCRandomGiftGet,        Category:Leisure,    }
recipe Play With    {        HCToymonkey,    Result:HCToymonkey,    Time:500,    OnCreate:HC_ToyStatModifier,    Category:Leisure,    }

 

I had that idea, too, but how do I get rid of the junk item afterwards?

Link to comment
Share on other sites

  • 3 weeks later...

I had that idea, too, but how do I get rid of the junk item afterwards?

Sorry for the late response, I was trying to figure how to do this for a while now and I finally did.

Edit: Further tests proved it doesn't quite work... Well, it kinda works, it removes the item SOMETIMES.

Edit 2: Figured it out, it removes the item if you had it in inventory before, after 10 tests I had 10 results and it just removed and added one. If one could make it scan the inventory a little after the result spawns in then it would probably work just fine.

Edit 3: Which is exactly what you did...  (I'm kinda drunk, sorry) Eh, a function that runs in the background with Event.OnTick that removes all dummy items? Really the only thing I can think off right now, seriously, No Result recipes NEED to be a thing.

Original Post Before Edits In Spoiler

 

function SVGRecipeTest_OnCreate(player)        local pl = getPlayer();	pl:getInventory():Remove("SVGDummyResult");end

Just put ItemID without module before it, it will remove whatever item has that ID.

 

recipe No Result Recipe Test    {        SVGTestItem,        Result:SVGDummyResult,        Time:10.0,        Category:Health,	OnCreate:SVGRecipeTest_OnCreate,    }

Idk why recipes that only have OnCreate and no result item are not a thing, it's a super easy way to give an item some functionality.

PS: Didn't test it much, got excited that result didn't spawn and console didn't throw any exceptions at me.

Link to comment
Share on other sites

The function you're trying to do is:

function BCMapMop_AddPage(items, result, player)    for i=0, items:size()-1 do        if items:get(i):getType() == "BCMapMod.Map" then            --- copy mod data            result:setModData(items:get(i):getModData()); -- no idea of this is how mod data is copied XD            player:getInventory():Remove(items:get(i));        end    endendrecipe Add sheet of paper{    keep BCMapMod.Map,    SheetPaper=1,    Time=25,    Result:BCMapMod.Map,    Category:General,    OnCreate:BCMapMop_AddPage}

No clue if it works or not, but give it a spin ;) This way it should be able to do the recipe multiple times.

Link to comment
Share on other sites

The function you're trying to do is:

function BCMapMop_AddPage(items, result, player)    for i=0, items:size()-1 do        if items:get(i):getType() == "BCMapMod.Map" then            --- copy mod data            result:setModData(items:get(i):getModData()); -- no idea of this is how mod data is copied XD            player:getInventory():Remove(items:get(i));        end    endendrecipe Add sheet of paper{    keep BCMapMod.Map,    SheetPaper=1,    Time=25,    Result:BCMapMod.Map,    Category:General,    OnCreate:BCMapMop_AddPage}

No clue if it works or not, but give it a spin ;) This way it should be able to do the recipe multiple times.

 

That might work with keep and Result... I'll give it a try soon. The copying needs to be a bit different, but basically works, too.

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