Let's say you have 6 items in a chest. One diamond, two wood, and three dirt. You pick one randomly out of the bag. What likelihood is it that you picked a diamond? 1/6, because there was only one diamond in the bag out of 6 total items.
We can use probability in Skript to have certain cases, some of which are likely, some of which are rare. The case that is chosen is picked randomly, but is more likely to be a blue bean than a red bean.
The first way we can do this using MundoSK is a probability scope. A probability scope is written like this:
$ scope probability: 1 prob: #This is our diamond set {_item} to 1 of diamond 2 prob: #This is our wood set {_item} to 1 of dark oak log 3 prob: #This is our dirt set {_item} to 1 of dirt
Pretty simple, right? The diamond has 1/6 chance of being chosen, the wood 2/6 or 1/3, and the dirt 3/6 or 1/2. You can just do this if you want, but you can also go farther.
Let's say if the probability chooses a diamond or a wood, you want to add in a broadcast of "Lucky, avoided the dirt." . You can actually do that really easily.
$ scope probability: 1 prob: #This is our diamond set {_item} to 1 of diamond 2 prob: #This is our wood set {_item} to 1 of dark oak log broadcast "Lucky, avoided the dirt." 3 prob: #This is our dirt set {_item} to 1 of dirt
The broadcast runs if the diamond or the wood was chosen, but not if the dirt was chosen, because the dirt came after the broadcast. Now, what if instead of that broadcast, you wanted a broadcast "No diamonds today" that only ran if a wood or a dirt was chosen?
$ scope probability: 1 prob: #This is our diamond set {_item} to 1 of diamond false 2 prob: #This is our wood set {_item} to 1 of dark oak log 3 prob: #This is our dirt set {_item} to 1 of dirt broadcast "No diamonds today."
You see that false? That false stops the rest of the probability scope from running if the diamond was chosen and returns to whatever came after the probability scope.
Pretty cool, but what if you wanted to have a probability for every item? It would be ridiculous to write in every item.
That's what our next probability expression is for. Say you create a list variable, and you set a probability for each item, like
{chance::diamond} = 2 {chance::wood} = 40 {chance::dirt} = 100
And all the rest of the items too. Now what? Luckily, there is a very simple expression for that:
random from {chance::*} probs
This amazing expression chooses an item name based on the probabilities in the list variable. Mind blown. This means you can change the probabilities or even get a fancy list of all the probabilities or a specific probability quite easily.
You can also use this to make a simple lottery, like this:
command /lotterypay: permission: lottery.pay trigger: if {lottery::%player%} is not set: set {lottery::%player%} to 0 add number-arg to {lottery::%player%} subtract number-arg from player's balance message "You added %number-arg% to the lottery!" command /lotteryaward: permission: lottery.admin trigger: set {_winner} to random from {lottery::%player%} probs parsed as a player broadcast "&6%{_winner}% won the lottery!!! They get %sum of {lottery::*}% money!!!" add sum of {lottery::*} to {_winner}'s balance clear {lottery::*}
Bam. Lottery.
There is a final expression, almost the same to the one shown above.
Say you have something that isn't a list variable, like a literal list such as 1, 2, 3, 4, 5 or an expression that returns a list of numbers. In this case, it's preferable to use an expression that returns a number that is the index of the list rather than a string, as would be the case with the list variable examples shown above.
random number from integers from 1 to 10 probs
The above example gives each number 1 to 10 a chance based on their number. Ex. 1 would have 1/55 chance, 5 would have 5/55 chance, etc.
You can also change the probabilities like this:
random number from 1, 1, 2, 3, 5, 8, 13 probs
So that the probabilities are a bit more complicated, 1 will have a 1/33 chance, same for 2, 3 will have 2/33, so on until 7 which has a 13/33 chance.
You can also do this with list variables that have number indeces (string indeces would be converted to number indeces alphabetically) It would essentially work the same way as the earlier example with list variables, except it would return a number.