Skip to content

Class "WeightedOutcomePicker"⚓︎

An example mod using the WeightedOutcomePicker class can be found here.

Info

This class can be obtained using its constructor:

Example Code
1
local wop = WeightedOutcomePicker()

Constructors⚓︎

WeightedOutcomePicker ()⚓︎

WeightedOutcomePicker WeightedOutcomePicker ( )⚓︎


Functions⚓︎

AddOutcomeFloat ()⚓︎

void AddOutcomeFloat ( int Value, float Weight, int ScaleFactor = 100 )⚓︎

Adds an outcome to the outcome selector with the specified Weight. The internal weight is still an integer calculated like this: fWeight * scaleFactor, where ScaleFactor is the maximum weight (equivalent to 1.0).

Example Code
1
2
3
4
5
local picker = WeightedOutcomePicker()

picker:AddOutcomeFloat(1, 1.0) -- ~45%
picker:AddOutcomeFloat(2, 1.0) -- ~45%
picker:AddOutcomeFloat(3, 0.2) -- ~9%

AddOutcomeWeight ()⚓︎

void AddOutcomeWeight ( int Value, int Weight )⚓︎

Adds an outcome to the outcome selector with the specified Weight.

Example Code
1
2
3
4
5
local picker = WeightedOutcomePicker()

picker:AddOutcomeWeight(1, 65) -- 65%
picker:AddOutcomeWeight(2, 30) -- 30%
picker:AddOutcomeWeight(3, 5) -- 5%

ClearOutcomes ()⚓︎

void ClearOutcomes ( )⚓︎

Clears all outcomes from the outcome picker.


GetNumOutcomes ()⚓︎

int GetNumOutcomes ( )⚓︎

Returns the number of outcomes in the outcome picker.


GetOutcomes ()⚓︎

table[] GetOutcomes ( )⚓︎

Returns a table containing a list of all outcomes in the outcome picker.

Table structure & usage
  • The returned table contains a list of outcomes, where each outcome is a table containing the following fields:
    • Value: value of the outcome
    • Weight: weight of the outcome
      1
      2
      3
      for i, outcome in ipairs(p:GetOutcomes()) do
          print(outcome.Value, outcome.Weight)
      end
      

PickOutcome ()⚓︎

int PickOutcome ( RNG RNG )⚓︎

Returns a random outcome from the list in WeightedOutcomePicker. Accepts RNG.


RemoveOutcome ()⚓︎

void RemoveOutcome ( int Value )⚓︎

Removes an outcome from the outcome picker with the given Value.