recipe with random result
recipe with random result
Is it somehow possible to create an recipe that produce random stuff from a list?
- Blockhead
- Member
- Posts: 1624
- Joined: Wed Jul 17, 2019 10:14
- GitHub: Montandalar
- IRC: Blockhead256
- In-game: Blockhead Blockhead256
- Location: Land Down Under
- Contact:
Re: recipe with random result
Yes, you can register a function to run when the player crafts something, and replace the output with what you decide instead. minetest.register_on_craft.
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂
Re: recipe with random result
Is it possible to return more than one type of items?
What I want to archive is, a user has converted some group:minegeld_note to currency:minegeld_bundle and is crying that he cannot use the later one for anything. I want to allow him to craft them back to 9 possible different currency:minegeld_* selected randomly.
I could modify the inventory directly but when exactly is that redister_on_craft executed? when A user click on the result? When it is showed or when he dropped the result into his inventory?
What I want to archive is, a user has converted some group:minegeld_note to currency:minegeld_bundle and is crying that he cannot use the later one for anything. I want to allow him to craft them back to 9 possible different currency:minegeld_* selected randomly.
I could modify the inventory directly but when exactly is that redister_on_craft executed? when A user click on the result? When it is showed or when he dropped the result into his inventory?
- Blockhead
- Member
- Posts: 1624
- Joined: Wed Jul 17, 2019 10:14
- GitHub: Montandalar
- IRC: Blockhead256
- In-game: Blockhead Blockhead256
- Location: Land Down Under
- Contact:
Re: recipe with random result
How about making the random choice happen when the bundle is held in the hand and the user left (or right) clicks? And think about the effects of letting players play the lottery/scratch tickets this way too.Mowgli wrote: ↑Fri Jun 09, 2023 10:02Is it possible to return more than one type of items?
What I want to archive is, a user has converted some group:minegeld_note to currency:minegeld_bundle and is crying that he cannot use the later one for anything. I want to allow him to craft them back to 9 possible different currency:minegeld_* selected randomly.
Either every time the crafting grid changes, to show a new result; or when the user clicks the result. I'm not sure right now. I think the former not the latter, because it has an itemstack argument, which is the output stack. But you could just go test it for yourself, you know. It's probably quicker than asking questions and waiting hours for a response. Maybe a documentation improvement pull request is in order, once you figure it out.
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂
- Skamiz Kazzarch
- Member
- Posts: 613
- Joined: Fri Mar 09, 2018 20:34
- GitHub: Skamiz
- In-game: Skamiz
- Location: la lojbaugag.
Re: recipe with random result
https://github.com/minetest/minetest/bl ... 0-L5572C64
Haven't used them myself but the documentation seems clear enough?
First one can be used to change the result, when you click on it and later one can be used to change what appears in the output before the crafting action happens.
Code: Select all
* `minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv))`
* Called when `player` crafts something
* `itemstack` is the output
* `old_craft_grid` contains the recipe (Note: the one in the inventory is
cleared).
* `craft_inv` is the inventory with the crafting grid
* Return either an `ItemStack`, to replace the output, or `nil`, to not
modify it.
* `minetest.register_craft_predict(function(itemstack, player, old_craft_grid, craft_inv))`
* The same as before, except that it is called before the player crafts, to
make craft prediction, and it should not change anything.
First one can be used to change the result, when you click on it and later one can be used to change what appears in the output before the crafting action happens.
Who is online
Users browsing this forum: No registered users and 9 guests