How do I have an enemy randomly drop an item upon death?

Just started using Construct 2? Post your questions here

Post » Thu Feb 12, 2015 12:56 am

Hi all,

I've been playing around with the Ghost Shooter demo game from the Beginner's guide to Construct 2, adding features as I learn more. I added limited ammunition which was easy enough, but one thing I can't figure out how to implement is to have ghosts randomly drop more bullets when they die. I was thinking something along the lines of there being a 1 in 5 chance of more ammo being left behind whenever a ghost is destroyed.

I would very much appreciate any help, and I apologize if I have missed the answer in searching the forums and manual.
B
7
Posts: 11
Reputation: 299

Post » Thu Feb 12, 2015 7:58 am

For the random drops:

1. Create new instance variable of "random" with initial value "0" on the monsters
2. On Monster Health < 0, set value of random with: floor(random(0,6))
3. Create sub-event inside "On Monster Health < 0":
if Monster.random = 5 {
Monster spawn another object: Bullet
}

Here's a pic:
Image
B
18
S
3
G
3
Posts: 109
Reputation: 2,784

Post » Fri Feb 13, 2015 7:52 pm

I finally had a chance to sit down and try this, and it works like a charm! Thank you very much for the help!
B
7
Posts: 11
Reputation: 299

Post » Thu Dec 10, 2015 1:06 pm

@jourdan Hi! I was curious what floor means, is it the same as round?
B
8
S
2
Posts: 27
Reputation: 610

Post » Thu Dec 10, 2015 4:06 pm

@Nitari

floor(x) Round down x e.g. floor(5.9) = 5

round(x) Round x to the nearest whole number e.g. round(5.6) = 6

( https://www.scirra.com/manual/126/system-expressions )
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,832

Post » Sat Dec 12, 2015 3:30 am

Message: Nitari is not yet permitted to post plain text URLS (300 rep required). 1 URLS removed. Why?
RamPackWobble wrote:@Nitari

floor(x) Round down x e.g. floor(5.9) = 5

round(x) Round x to the nearest whole number e.g. round(5.6) = 6

( )



Ahh thanks!
B
8
S
2
Posts: 27
Reputation: 610


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests