0 Favourites

How do I choose random image by rarity

  • Hello all

    i need a simple project: in a window, i've only 1 sprite, with 10 images

    every sprite must have a rarity (common, un-common-rare)

    when i click on image, sprite must change to other one by rarity

    sprite have:

    image 0 common

    image 1 common

    image 2 common

    image 3 common

    image 4 common

    image 5 un-common

    image 6 un-common

    image 7 un-common

    image 8 rare

    image 9 rare

    some ideas?

    thanks

  • I am really not clear on what you are trying to do and there is no probably many different ways to achieve whatever you are trying to do.

    Which of the following have you thought about using to implement this:

    Instance variables

    Different sprites vs different animations

    Families

    Array

    I would make 3 different sprites, one for each level of rareness, put all the cards in as a different frame in the same animation. Then have it randomly choose a frame on prompt.

    Have you tried anything yet?

  • I am really not clear on what you are trying to do and there is no probably many different ways to achieve whatever you are trying to do.

    hi and thanks for reply

    this is an example of random:

    but i dont need only "egual" random

    i need that Animation Sprite frames 0 is most (?) common that Animation Sprite frames 5 (more rare)

    i can use some variable, examples "rarity" with a %

    totat rarity is 100%:

    rarity common + rarity uncommon + rarity rare = 100%

    than i can set:

    rarity common= 45%

    rarity uncommon= 35%

    rarity rare= 20%

    so, onload my Animation Sprite Frames will be a random: 0 to 5 according with variable "rarity"

    every time i click on my sprite, rarity check

    and will display one Animation Sprite Frames 0 to 5 according with variable "rarity"

    i decide rarity for every sprite: how i can give the variable rarity to my Animation Sprite Frames?

    example i want:

    0 set to common

    1 set to common

    2 set to common

    3 set to uncommon

    4 set to uncommon

    5 set to rare

  • you can try:

    Var = floor(random(0,101))

    if Var <=35

    animation frame = choose (0,1,2)

    else

    if Var>35 | Var <=80

    animation frame = choose(3,4)

    else

    animation frame = 5

  • Oh, you are saying you want some to be more rarely chosen than others? Let's say like cards in a deck (like in a board game/collecting game, not poker cards) where there are more of some cards than others.

    If so I think MadSpy hit the nail on the head there (except I think flipflopped percentages, 35 should be 45).

    Are you familiar with random and choose, the expressions for generating random numbers? (shown by MadSpy above). That is all you need to create any type of randomness you want. After learning about those you just have to really think out how you want the math because you could do it tons of different ways.

    For example, here is one thing to think about:

    You say you want a common card drawn 45% of the time, uncommon, 35% of the time, and rare 20% of the time. MadSpy's example will do exactly what you want.

    That means the following probability of drawing each card:

    0: 15% (45/3)

    1: 15%

    2: 15%

    3: 17.5% (35/2)

    4: 17.5%

    5: 20% (20/1)

    So probability wise you will draw common cards most often but the rare card, since you only have one rare card, will be the most commonly drawn card in the game. Not sure you are indenting that . . .

    But that is more of a balancing discussion. Like I said, you could set this up so many different ways so what I suggest is you get out pen and paper and write out the math you want. That way you can ask specific questions on how to implement if you get stuck.

  • you can try:

    thanks! you hit the point!!!

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Let's say like cards in a deck (like in a board game/collecting game, not poker cards) where there are more of some cards than others

    yes is that!

    thanks for helping

  • See this tutorial on monster loot drop.

    It actually explains how to do probabilities and rarity in the way you are looking to achieve.

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