How do I make an odds system? (probabilities)

1 favourites
  • 4 posts
From the Asset Store
Create complex dialogues with ease with this tool/template!
  • Hi! I'm making a fishing game where sometimes there is a minigame that randomly create 1 objet (fish) out of 4 (like a raffle) based on its probabilities (odds).

    For example:

    FISH A: 22% of chance

    FISH B: 9.5% of chance

    FISH C: 8% of chance

    FISH D: 7.3% of chance

    NONE: 53.2% of chance

    How do I create a system that pick one of those fish (or none of them) based on its odds?

  • I put this together, which should work for you:

    dropbox.com/s/gavzxhalnxdur6n/probabilityTable.capx

    The data is in a json array file in the project settings and I import it into an array object using the AJAX object.

    If you run the project in debug you can check the a_fish object and see that the probabilities have been added correctly.

    I've used percentage figures you supplied, but a bonus of this system is that you don't have to use percentages - you can use counts (10 of fish A, 6 of fish B etc) and it will still work fine, meaning that if you change the value for one fish you don't have to recalculate the percentages for the other fish.

    Each fish is a separate object as you requested, but if you had a single fish object with each fish as an animation then you could set the animation in a single event directly from the "fish" variable rather than needing an event to check for each fish object.

    In Construct 3 there is a probability table feature in the Advanced Random plugin which makes this very easy to do. Sadly there isn't that option for C2.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • gabmusic Great example from mekonbekon, but may be a bit overcomplicated for your job. If you have a small number of fish and fixed odds, you can hard-code them and simply do this:

    Set r=random(100)
    
    if r<=22 Spawn FishA
    else if r<=31.5 Spawn FishB
    else if r<=39.5 Spawn FishC
    ....
    
  • dop2000 Thanks again man! It was really helpful!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)