Random Loot, spawning and other??

Get help using Construct 2

Post » Mon Jan 26, 2015 1:50 am

I feel like I always come back to this question and I've never really come away with a solid answer.

Is there a simple, full-proof way of creating items at random?

Kill and enemy, an item is selected from a pool at random for it's loot. Or, you have an item that spawns random enemies..

I feel like this is a very basic function most games have to create variety but C2 doesn't have a quick behavior for it like everything else.

Anyone have links to tutorials or know a quick/easy way to do this?

Thank you,
B
12
S
4
G
2
Posts: 132
Reputation: 1,749

Post » Mon Jan 26, 2015 2:53 am

There are much more elegant ways but the easiest I can think of off hand is this:

On enemy destroyed > set value of powerupvariable to floor(random(100)) (or whatever number you like).
Then.
If powerupvariable = 1 > spawn powerup1
if powerupvariable = 2 > spawn powerup2 etc...

This way if you have 10 powerups then with the above formula you would have a 10% chance of getting a random powerup.
B
61
S
20
G
56
Posts: 1,077
Reputation: 35,991

Post » Mon Jan 26, 2015 3:56 am

Burvey wrote:There are much more elegant ways but the easiest I can think of off hand is this:

On enemy destroyed > set value of powerupvariable to floor(random(100)) (or whatever number you like).
Then.
If powerupvariable = 1 > spawn powerup1
if powerupvariable = 2 > spawn powerup2 etc...

This way if you have 10 powerups then with the above formula you would have a 10% chance of getting a random powerup.


THANK YOU!!!!
This is what I needed!
I just made a simple mock up with the idea you posted and with a few little changes I got a working model. This is so simple, but so incredibly powerful.
:D
B
12
S
4
G
2
Posts: 132
Reputation: 1,749

Post » Mon Jan 26, 2015 5:06 am

Another way you can also just put all the things you want to choose from inside a family then spawn that family it will spawn one of the objects randomly
B
42
S
17
G
2
Posts: 850
Reputation: 6,209

Post » Mon Jan 26, 2015 5:27 am

volkiller730 wrote:Another way you can also just put all the things you want to choose from inside a family then spawn that family it will spawn one of the objects randomly


Can you elaborate?
I'm going to test this but I thought that families would spawn as a group and not as a single item one at a time.
B
12
S
4
G
2
Posts: 132
Reputation: 1,749

Post » Mon Jan 26, 2015 6:48 am

If you you use the Create Object Action an set it to a family it will create one instance of a single random object you put into the family
B
42
S
17
G
2
Posts: 850
Reputation: 6,209


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 21 guests