[solved] Minable probabilities

Place to get help with not working mods / modding interface.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

[solved] Minable probabilities

Post by aubergine18 »

I'm trying to add some variation to mining results from trees, stone, etc., but only ever seem to get one resource back.

For example, if I set something like this (item names simplified for sake of clarity):

Code: Select all

someProto.minable.result = nil
someProto.minable.results = {
  { name = "item1", probability = 0.8, amount_min = 1, amount_max = 2, type = "item" },
  { name = "item2", probability = 0.1, amount_min = 1, amount_max = 2, type = "item" },
  { name = "item3", probability = 0.1, amount_min = 1, amount_max = 2, type = "item" },
}
I expect to get item1 80% of the time, or a 10% chance of each of the other items.

The chances show up in the game UI when entity is selected, but I only ever seem to get back item1 - any ideas?
Last edited by aubergine18 on Tue Sep 27, 2016 8:01 pm, edited 1 time in total.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
User avatar
LuziferSenpai
Filter Inserter
Filter Inserter
Posts: 393
Joined: Tue Jul 08, 2014 10:06 am
Contact:

Re: Minable probabilities

Post by LuziferSenpai »

aubergine18 wrote:I'm trying to add some variation to mining results from trees, stone, etc., but only ever seem to get one resource back.

For example, if I set something like this (item names simplified for sake of clarity):

Code: Select all

someProto.minable.result = nil
someProto.minable.results = {
  { name = "item1", probability = 0.8, amount_min = 1, amount_max = 2, type = "item" },
  { name = "item2", probability = 0.1, amount_min = 1, amount_max = 2, type = "item" },
  { name = "item3", probability = 0.1, amount_min = 1, amount_max = 2, type = "item" },
}
I expect to get item1 80% of the time, or a 10% chance of each of the other items.

The chances show up in the game UI when entity is selected, but I only ever seem to get back item1 - any ideas?
Try this:

Code: Select all

someProto.minable.result = nil
someProto.minable.results = {
  result = { name = "item1", probability = 0.8, amount_min = 1, amount_max = 2, type = "item" },
  result = { name = "item2", probability = 0.1, amount_min = 1, amount_max = 2, type = "item" },
  result = { name = "item3", probability = 0.1, amount_min = 1, amount_max = 2, type = "item" },
}
I think this will work, because if you like in the Icon Section than you see that there is the same way ;)

Greetz,

Senpai
Coding is awesome!
Animes are love!
Factorio is life!

My MODs:
Click

Greetz,

Senpai
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Minable probabilities

Post by aubergine18 »

That definitely won't work because you're defining a table with three named properties - and they are all using same name 'result' so they will overwrite one another.

Code: Select all

someProto.minable.results = {
  result = { ... },
  result = { ... },
  result = { ... },
}
Anyway, I did some more digging and found the following:

1. The sum of the probabilities doesn't need to add up to 1; each element in the table can be 0..1 regardless of what the other probabilities are.

2. Anything less than 0.1 is almost never going to happen, even having mined something hundreds of times.

3. The `minable.count` property no longer seems to take effect when using `minable.results` instead of `minable.result`.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Post Reply

Return to “Modding help”