How do I make Items be % dropped?

0 favourites
  • 4 posts
From the Asset Store
320 high-quality cinematic sound effects for trailers and game scenes.
  • Hello Forum Members,

    I have a little Question, i dont know if it is a beginner question, but i dont want to waste time on this now.

    My Question is: I have for example 3 Sprites ..

    Noooow... When I Click the Button I want that one of these 3 Sprites will Spawn , and this with % chances!

    So for example:

    Sprite 1 = 5 %

    Sprite 2 = 35%

    Sprite 3 = 60%

    So that Sprite 1 should be rare.

    Can someone help me out, thanks

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sure, create a local variable

    localvariable = round(random(0,100))

    Then make some subevents

    localvariable < 5 -> drop item 1

    localvariable >=5

    localvariable < 40 -> drop item 2

    etc

    explanation, random(0,100) will return a random number between 0 and 100 but it will have a decimal point attached (this is called a floating point precision number) so the call to round() makes it a whole number. You type this directly in as the expression in the "set variable" dialog.

    The subevents are "if statements". If the local variable is less than 5, then drop that item.

    if the local variable is higher 5, and lower than 40, drop that item (this gives a 35% chance, since 0-4 is already accounted for)

  • The Problem is, that i want for 100% that one sprite will spawn. When I click now the Button i get after 100 times for example sprite 1 or 2.

  • The example I provided will do that, assuming each percentage chance is populated in the list of if statement.s

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