Dynamic Reward Values - TheTurkeyDev/ChanceCubes GitHub Wiki
As of Chance Cubes version 4.0.0, Rewards now have the ability to have dynamic values when creating a reward via the custom reward creation files. All json entries support the dynamic values, but not all rewards and parts of the rewards support runtime dynamic values and therefore some dynamic values may be calculated upon the reward load and not when its triggered.
How do I add Dynamic values?
First off Dynamic values are indified by "%%" preceeding and following the dynamic value contents. Nested Dynamic values may work, but is not really tested, so use at your own risk and don't expect to work.
Currently 2 types of dynamic values. One is a random value from a defined range, the other is a random value from a defined list.
Range
For the defined range, this works with all value types with Integer and Float taking in their respective types while String and NBT Types work solely with integers. Boolean types will simply return true or false. The defined rage can be defined in one of two ways, with just an upper bound (exclusive) or both an upper (exclusive) and lower (inclusive) bound. Examples given below:
Without Dynamic Value:
"delay":1
With Dynamic Integer Value and only upper bound:
"delay":"%%RND(5)%%" //Will produce a number from 0 - 4
With Dynamic Integer Value and both upper and lower bound:
"delay":"%%RND(1,5)%%" //Will produce a number from 1 - 4
With Dynamic Float Value and only upper bound:
"pitch":"%%RND(5.5)%%" //Will produce a number from 0.0 - 5.4999...
With Dynamic Float Value and both upper and lower bound:
"delay":"%%RND(1,5.5)%%" //Will produce a number from 1 - 5.499...
List
For the defined list, this works with all value types using in their respective types as a cast for each list element. There isn't really a limit on the length of the list. Examples given below:
Without Dynamic Value:
"delay":1
With Dynamic Integer Value:
"delay":"%%[1,2,3,4,6,8,10]%%" //Will choose one number from this list
With Dynamic Float value:
"pitch":"%%[1.0,3.0,5.0]%%" //Will choose one number from this list
With Dynamic String value:
"message":"%%[Hi, Hello, Good day]%%" //Will one element from this list
Defined lists are also good ways to add in weights and allow for one value to have a greater chance to be selected:
"delay":"%%[3,3,3,5,5,2]%%" //3 has a 3 in 6 chance of being picked while 5 has a 2 in 6 chance of being picked and 2 has a 1 in 6 chance
Dynamic values may also be used in line. The Values are simply concatenated:
"delay":"1%%RND(10)%%" // This will give all numbers between 10 and 19.
"delay":"1%%RND(11)%%" // This will give all numbers between 10 and 19, with the addition of 110 as a possibility, so be careful.
This in line feature is great for messages though!:
"message":"%%[Hi, Hello, Good day]%%, how are you?" // This will produce one of 3 possible messages "Hi, how are you", "Hello, how are you", or "Good day, how are you?"