Something like this (this is probably a very wrongly written line of code )
Code: Select all
Function
1="ruby-1"
2="topaz-1"
3="sapphire-1"
4="diamond-1"
5="emerald-1"
End
Recipe:
Result = function.math.random(1,5)
Result_count = math.random(1,3)
Code: Select all
Function
1="ruby-1"
2="topaz-1"
3="sapphire-1"
4="diamond-1"
5="emerald-1"
End
Recipe:
Result = function.math.random(1,5)
Result_count = math.random(1,3)
if possible with resetrecipes, i could just simply add an ontick event with game.force.player.resetrecipes() that runs every minute or so and be done with itFreeER wrote:so something like receiving a 'mystery ore'? Hmm...Not that I can think of. Well, of course it's possible with generic container entity and scripting etc., but not that I can think of otherwise if you want it to have a random chance upon each smelting. You could do it in the prototypes but that would choose one at load time and not change until Factorio is closed and reopened (maybe with resetrecipes?).
Code: Select all
function randomresult()
if math.random(1,5)==1 then "ruby-1",
else math.random(1,5)==2 then "emerald-1",
else math.random(1,5)==3 then "topaz-1",
else math.random(1,5)==4 then "diamond-1",
else math.random(1,5)==5 then "sspphire-1",
end
end
Code: Select all
{
type = "recipe",
name = "sand-110",
category = "gem-grinding",
energy_required = 50,
ingredients =
{
{"stone", 1},
},
result = randomresult()
},
Code: Select all
function random_gem()
local gem = math.random(5)
if gem == 1 then return "ruby-1"
elseif gem == 2 then return "emerald-1"
...
end
end
Code: Select all
{
type = "recipe",
name = "sandid",
category = "smelting",
energy_required = 50,
ingredients =
{
{"sand", 1},
},
result = gem_results[math.random(#gem_results)]
},
Code: Select all
gem_results={"ruby-1", "emerald-1", "topaz-1", "diamond-1", "sapphire-1"}
Well he's not (from what I read) trying to output more than one item type at a time, he wants a random one to be chosen (rather like the enemy spawner only spawns one unit at a time, but it is 'random' as to which, obviously not best example because spawner is affected by pollution and evolution factor but). The problem is that the recipe is only checked when Factorio loads, thus it picks one result item and doesn't change until Factorio is restarted. If resetrecipes could be used to force Factorio to reload that (and rerun math.random) then you'd effectively get a random output, but still only a single type at any one smelting.SilverWarior wrote:I don't think you can achieve this only by changing item recipie. Why? As far as I know recipies are just record informations and not classes. This means that they simply store constant data in more organized manner.
To be able to achieve this developers would have to change the furnace class first as it is curently build in a way to only support only one item output per recipie.
Code: Select all
function RandomResult(resources)
return resources[math.random(#resources)]
end
Yes I know that. But the problem with current implementation is that only one posible product type is read from the item recipie.FreeER wrote:Well he's not (from what I read) trying to output more than one item type at a time, he wants a random one to be chosen (rather like the enemy spawner only spawns one unit at a time
Yes that is the problem, I replied to your initial one because you saidSilverWarior wrote:But the problem with current implementation is that only one posible product type is read from the item recipie.
Slight difference but important. The furnace is not limited to a single output, it can have multiple input and output slots (if changed in the prototype). It's the actual recipe mechanic that is limited. Of course I've no idea exactly how much would have to be changed for this to work without issues, they'd first have to allow multiple results (and random results), then they'd have to decide how to insert those items into the furnace (if it has one slot is it even able to use a recipe with multiple outputs, or does it place the first in the output slot and the rest in a buffer?). Of course they'd also have to modify assembling machines as well (though in a similar manner). and what about mining results, could you mine ores and also receive stone (or stone fragments)? If so you'd also have to modify the mining drill. It's not straight forward as I'm sure you know, but there is a bit more to it than some others (with less experience or hadn't thought it through) may believe.SilverWarior wrote: To be able to achieve this developers would have to change the furnace class first as it is curently build in a way to only support only one item output per recipie.
Code: Select all
result = (function()
local res = {}
res[1] = {"ruby-1", 0.30}
res[2] = {"emerald-1", 0.20}
res[3] = {"sapphire-1", 0.20}
res[4] = {"topaz-1", 0.20}
res[5] = {"diamond-1", 0.10}
return res
end)(),
and it could be modified to have a random result_count:
res[1] = {"ruby-1", result_count = math.random(3), 0.30}
kovarex wrote:If we made recipes with multiple/random results (similar to loot definition probably) there would have to be special rules about these kind of recipes:
Makes sense[*] The recipe wouldn't be used for intermediate crafting automatically
Hm, not sure what you mean by custom icon name...Would that make the icon any different? If all results were given using a table the code should be able to easily say, if table.length > 1 then multi, else regular. You could also, I would think, make the results also show in the pop where the ingredients do now. That should prevent having to create recipes differently if they are multi vs singular result, though it would obviously require more changes...[*] The recipe would have to have custom icon name and description specified
Me too[*] I thought there were going to be more problems
You already have such recipies. All smelting recipies work only in furnaces.kovarex wrote:The recipe wouldn't be used for intermediate crafting automatically
Another posible problem that me and FreeER came out when further discusing about this idea through PM would be on how to determine output slots. You can't just use one as each item slot can only contain one item type.kovarex wrote:The recipe would have to have custom icon name and description specified[/qote]
Same would go to all smelting recipies right now. I can still remember how hard was for me to figure out hoow to make steel for the first time.
kovarex wrote:I thought there were going to be more problems [/list]