Jump to content
blindcoder

Recipe without result?

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?

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

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.

Share this post


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

Share this post


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

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

×
×
  • Create New...