How do I randomize loot?

Get help using Construct 2

Post » Thu Jul 21, 2016 10:02 am

Hello!
I would really need your help as a beginner, even though my question is similar with those in forums. I can't find an answer to my actual question.

I want to create:
When clicked > ex: 75% chance to drop boots and 25% chance to drop armor.
and example: If u buy chance it'll increase, and it can be 50% armor and 50% boots.

So could anyone please help me? Thanks a lot :D
B
6
S
1
Posts: 7
Reputation: 364

Post » Thu Jul 21, 2016 11:06 am

Use a variable. Variable loot = 0
-on click > set loot = int(random(101)) // this will set a variable between 0-100 without float variable
- if loot < 75 then drop boot
- if loot >= 75 then drop armor
B
18
S
7
G
1
Posts: 56
Reputation: 3,000

Post » Thu Jul 21, 2016 11:21 am

I made a system where I did the following:

For each enemy I would assign a number for each drop item (I stored in XML, but you could do instance variables or straight in the events if you don't have different enemy types). So for example it would look like:
Nothing: 6
Coin:4
Heart: 2

Then I would use a local variable to store a random number between zero and total of those numbers -> random(0, 12) in this case. Then cycle through the drop items:

If random <= nothing amount( 6) then drop is nothing
elseIf random <= nothing amount plus coin amount (10) then drop is coin
Else drop is heart

I'm sure there is a way to do this with less events but it works. Was my first time creating this. Can see it in action in Ninja game linked in my signature. I like it because you can change one number and not have to change the rest so it will equal 100% each time; I feel like that could get really annoying.
ImageImageImage
B
43
S
26
G
11
Posts: 517
Reputation: 10,475

Post » Thu Jul 21, 2016 2:17 pm

Search functions could have been of great help here.
Searching the tutorials for example would have given "How to code monster loot drops" as a result which is exactly what you are looking to do.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
294
S
117
G
96
Posts: 7,310
Reputation: 71,084


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 30 guests