Topic: Do not fully understand how to use a built-in method/functionReason: From the name, it seems to be the method/function I require for what I am trying to do in a mod I am working on.More Info: The method/function is "minetest.register_on_craft". However I cannot find any good information on how it is used. What I am trying to accomplish using this method/function is allow a crafting item to be used multiple times, but also have a chance of it "breaking".
Also I'm the type of person that requires an example to learn, I need to see it being used to fully understand it.
Please note that this isn't a finished product, and is still a work-in-progress and I have not tested the code.
But like I said, I couldn't find any good information on it's usage. PilzAdam gave me a small example of it being used, however it didn't use the main variable I'm looking to use, which is the "old_craft_grid".
How I currently have the code written is below in the spoiler.
[spoiler]
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv)
local seed = os.time()
local recipe = minetest.get_craft_recipe(item)
local inv = minetest.get_inventory({type="player", name=player})
local rh = true
if old_craft_grid = recipe('PoweredMachines:Copper_Plate') then
math.randomseed( seed ),
if math.random( 1, 100) < 15 then
itemstack = 'PoweredMachines:BrokenHammer',
inv:add_item("main", ItemStack('PoweredMachines:Copper_Plate'),
rh = false
return itemstack,
end
if rh then
inv:add_item("main", ItemStack('PoweredMachines:Hammer'),
end
elseif old_craft_grid = recipe('PoweredMachines:Steal_Plate') then
math.randomseed( seed ),
if math.random( 1, 100) < 15 then
itemstack = 'PoweredMachines:BrokenHammer',
inv:add_item("main", ItemStack('PoweredMachines:Steal_Plate'),
rh = false
return itemstack,
end
if rh then
inv:add_item("main", ItemStack('PoweredMachines:Hammer'),
end
end
end
end)
[/spoiler]