#Code is skipping/giving player nothing

1 messages · Page 1 of 1 (latest)

boreal crag
#

Every now and then my code randomly doesn't give the loop-player a random item from any of the tiers. The chances add to 100 so idk whats wrong.

Im testing out different forms of this code, I was using random integers before, but I wanted to see if just using chances would work.

    set {tier1::*} to dirt, stick
    set {tier2::*} to grass block, cobblestone
    set {tier3::*} to stone, netherrack

options:
  timer: 1

every {@timer} seconds:
    # sets a random number for quantity every {@timer} second(s)
    set {_q} to random integer from 1 to 3
    loop all players:
        if loop-player has permission "tiers.tier1":
            if chance of 80%:
                # 80% chance with random 1-3 item quantity
                give loop-player {_q} of random items out of {tier1::*}
            else if chance of 15%:
                # 15% chance
                give loop-player 1 of random items out of {tier2::*}
            else if chance of 5%:
                # 5% chance
                give loop-player 1 of random items out of {tier3::*}```
gaunt pebble
#

because you can't add chances like that

#

the first if has a 80% chance of doing A, and a 20% chance of continuing

#

Assume we got the 20% chance
Now we have a 15% chance to do B, and 85% chance to continue
If we get the 85% chance, now we have 5% to do C and 95% to continue

#

If you calculate all the total probabilities, it's
80% A
3% B
0.85% C
16.15% Nothing

#

You should instead get 1 random number and check what it is

#
set {_r} to random number between 0 and 100
if {_r} is between 0 and 80:
else if {_r} is between 80 and 95:
...```
boreal crag
#

if the number is 80 in that code, would it do the first if statement first?

#

since they overlap