Page 1 of 1

[solved] Minable probabilities

Posted: Tue Sep 27, 2016 3:59 pm
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?

Re: Minable probabilities

Posted: Tue Sep 27, 2016 7:00 pm
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

Re: Minable probabilities

Posted: Tue Sep 27, 2016 7:47 pm
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`.