How do I make Items be % dropped?

Get help using Construct 2

Post » Fri Oct 10, 2014 5:49 pm

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
B
11
S
2
Posts: 93
Reputation: 917

Post » Fri Oct 10, 2014 5:52 pm

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)
Developing Surolace, the survival role playing space game.

surolace-survival-role-playing-space-game_t116953
B
14
S
4
Posts: 303
Reputation: 1,730

Post » Fri Oct 10, 2014 6:32 pm

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.
B
11
S
2
Posts: 93
Reputation: 917

Post » Fri Oct 10, 2014 6:39 pm

The example I provided will do that, assuming each percentage chance is populated in the list of if statement.s
Developing Surolace, the survival role playing space game.

surolace-survival-role-playing-space-game_t116953
B
14
S
4
Posts: 303
Reputation: 1,730


Return to How do I....?

Who is online

Users browsing this forum: ditocruz and 14 guests