0 Favourites

Random number..percentage?

  • Hi guys, weird question here that I'm hoping someone might be able to help me with.

    Is there a way to assign a random number...with a certain number having a higher percentage of being assigned than other numbers?

    Here's an example:

    I have a player sprite, I also have an enemy sprite. When the enemy sprite collides with the player (physics objects btw) I want to subtract say, 20 from the player's health variable.

    That's easy enough to do, but I would LIKE to have the damage be more randomized than that. Anywhere from having 10-20 health subtracted...but for the most part I want -20 health to be assigned on average with the 10-19 range only showing up on occasion.

    Oi, did I explain that well enough? =

    Maybe something like:

    Enemy >

          On collision with player >

                                   Subtract 20 from Healthvar...but sometimes 10-19 :P

    Thanks everyone.

  • Global Variable DAMAGE

    On collision with player: Set DAMAGE to int(random(100))

       If DAMAGE > 0 and DAMAGE <= 80 then - 20 from health.

       If DAMAGE > 81 then - int(random(10,20)

    80 percent chance to get 20

    20 percent chance to get 10-19

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Brilliant!

    Works perfectly, thanks a ton! :)

  • Using ArcadEd logic, you could fit all of it in a single expression.

    On collision with player: Set DAMAGE to (random(100) <= 80) ? 20 : int(random(10,20))
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
0 Favourites
random bugs and suggestions
90 4,517
Tom's avatar
Tom Construct Team Founder
Unread hot topic
0 Favourites
Rep is very random...
73 17,907
allavett's avatar
allavett
Unread hot topic
48 6,099
androidtimo's avatar
androidtimo