Creating a Random Mob Spawner in the Free Ed?

Get help using Construct 2

Post » Sat Feb 09, 2013 12:04 am

Now, I have been told this is possible, and a gent on Reddit by the name of Firebelly gave me some tips on how to do the random interval portion, by using an Instance Variable. To quote him:

[quote]
Create an instance variable on the spawner, "NextSpawnTime" and on each spawn, set that that time to Time+Random(N,N). Then set your spawn time to Time = Spawner.NextSpawnTime.
[/quote]

I think I know what that means. Doing it will be interesting though.

However, he says I should be able to have the spawner create 1 of 4 creatures at its spawning intervals (which is what I want to do). I got no direction for this part though, and since this is only the second game I have created, I come here for some assistance.

I did not see anything similar to my issue in the FAQ either.

I am also trying to figure out how to have an enemy maintain a distance from the player but chase him, shooting at him, but that is later.
MOO
B
14
S
4
G
4
Posts: 53
Reputation: 3,862

Post » Sat Feb 09, 2013 12:26 am

@Stomphoof You posted that you're on the free edition...this is where Families would be your friend.

Without it, you have two directions that I would look into:

1, you could create a local variable and set it with a choose action..I.e. choose('mob1','mob2','mob3','mob4'), then use 4 sub events to check to see if the local variable = mob1 or mob2, etc...then spawn your sprite.

2, you could create 1 mob sprite and give it 4 different animations. Use the choose function to randomly set one of those animations, then check the sprite to see what animation is running and set any instance variables on the sprite to correct values (health/hp, movement speed, etc.)

Again, this is a LOT easier in the licensed version using families.
B
26
S
8
G
3
Posts: 210
Reputation: 5,973

Post » Sat Feb 09, 2013 12:29 am

[QUOTE=theubie] @Stomphoof You posted that you're on the free edition...this is where Families would be your friend.

Without it, you have two directions that I would look into:

1, you could create a local variable and set it with a choose action..I.e. choose('mob1','mob2','mob3','mob4'), then use 4 sub events to check to see if the local variable = mob1 or mob2, etc...then spawn your sprite.

2, you could create 1 mob sprite and give it 4 different animations. Use the choose function to randomly set one of those animations, then check the sprite to see what animation is running and set any instance variables on the sprite to correct values (health/hp, movement speed, etc.)

Again, this is a LOT easier in the licensed version using families.[/QUOTE]

So I have heard. Sadly I don't have the cash for it at the moment. So I am working with what I have right now.

I may just avoid the random mob spawning and just stick with 4 spawner types that spawn a specific sort of enemy.

Option 1 sounds like the best idea but...not sure how I would set that up exactly to randomize which of the values in the varible it would choose.

EDIT: I think I see what you are saying. Setup a global variable like "mobSpawn = random(4)" and then when the spawner gets within range of the player (no idea how to check this) have it check that value and spawn a dude.

That about right?Stomphoof2013-02-09 00:39:05
MOO
B
14
S
4
G
4
Posts: 53
Reputation: 3,862

Post » Sat Feb 09, 2013 1:30 am

Quick and dirty prototype:

B
26
S
8
G
3
Posts: 210
Reputation: 5,973

Post » Sat Feb 09, 2013 1:58 am

If you are on free edition, you probably would like to keep your events count as low as possible.

I took @theubie image and remade it a little to use function object and sprite animations.

There is only one Mob sprite with four different animations "Mob1", "Mob2", "Mob3" and "Mob4".

As in @theubie image i've used Local text "SpawnType" to choose("Mob1","Mob2","Mob3","Mob4"), but then instead of spawning Mob sprite equal to SpawnType variable I've called Function "spawn" with "SpawnTpe" variable as a parameter.

Function: On "spawn" spawns Mob sprite and then set proper animation by name selected from function parameter.



It basically do the same thing like in @theubie example but using less eventsshinkan2013-02-09 01:59:34
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Sat Feb 09, 2013 2:50 am

@shinkan I already offered that type of solution (1 sprite, 4 animations) in my first post. He wanted more info on how to do it this way. I'd go with the 1 sprite method myself.

If you're going that route, you wouldn't even need the variable or function. Just set animation to choose("mob1",etc) when you create the mob. Even less to code that way.theubie2013-02-09 02:51:30
B
26
S
8
G
3
Posts: 210
Reputation: 5,973

Post » Sat Feb 09, 2013 3:23 am

[QUOTE=shinkan] If you are on free edition, you probably would like to keep your events count as low as possible.

I took @theubie image and remade it a little to use function object and sprite animations.

There is only one Mob sprite with four different animations "Mob1", "Mob2", "Mob3" and "Mob4".

As in @theubie image i've used Local text "SpawnType" to choose("Mob1","Mob2","Mob3","Mob4"), but then instead of spawning Mob sprite equal to SpawnType variable I've called Function "spawn" with "SpawnTpe" variable as a parameter.

Function: On "spawn" spawns Mob sprite and then set proper animation by name selected from function parameter.



It basically do the same thing like in @theubie example but using less events[/QUOTE]

[quote=theubie]
@shinkan I already offered that type of solution (1 sprite, 4 animations) in my first post. He wanted more info on how to do it this way. I'd go with the 1 sprite method myself.

If you're going that route, you wouldn't even need the variable or function. Just set animation to choose("mob1",etc) when you create the mob. Even less to code that way.
[/quote]

So how would I have 4 different mobs setup using this method? I mean yes, I can see how using this would give me a frame of the animation as the Sprite, but how would I give that frame the individual stats (HP and whatnot) as needed?

I can see in @theubie's first example how it would work, by setting the instance variable in the code...but not sure how that would work in the function example.

I think I am being stupid here >.>
MOO
B
14
S
4
G
4
Posts: 53
Reputation: 3,862

Post » Sat Feb 09, 2013 3:39 am

@Stomphoof

In this case, you would set the sprite not to an animation frame, but to a completely different animation. You can then check the animation name (sprite.animation) and based on that you can assign the HP, etc. That would require events like the ones in the other example...you're just checking Sprite.Animation rather than the Variable but the methodology is the same.

Either way, you're going to need an event for each mob so I'm not sure if either way saves on total number of events.
B
26
S
8
G
3
Posts: 210
Reputation: 5,973

Post » Sat Feb 09, 2013 3:46 am

[QUOTE=theubie] @Stomphoof

In this case, you would set the sprite not to an animation frame, but to a completely different animation. You can then check the animation name (sprite.animation) and based on that you can assign the HP, etc. That would require events like the ones in the other example...you're just checking Sprite.Animation rather than the Variable but the methodology is the same.

Either way, you're going to need an event for each mob so I'm not sure if either way saves on total number of events.[/QUOTE]

If I am going to need an event for each mob, I think I will just stick to using the first method since I comprehend that better at the moment.

Perhaps as I get better with Construct 2 I will understand what you mean by checking completely different animations. My fault for not understanding and I thank you all for the help.

This serves my purposes quite well. I have the spare events (I got 43 used of my 100 and most of my work is done) as the game itself will be fairly simple.

And thanks to you guys I now understand how to check distance relative to the player and thus use that to start the spawn sequence. Now I need to figure out how to randomize how often it actually spawns something.
MOO
B
14
S
4
G
4
Posts: 53
Reputation: 3,862

Post » Sat Feb 09, 2013 4:16 am

Add a condition to the one that checks distance. If you want it to spawn say...15% of the time, you'd use something like Compare Two Values-> random(0,100) <= 15.

Another thing to consider: This action is going to spawn everytime you run through the loop, so if that spawner object stays within the spawn distance you put in there, it's going to start popping out mobs at a high rate. The random statement I just mentioned will address that. You might want to add in one more condition to limit the number of times it can fire over a given period of time, like Every 1 second or something of that type.

(just speaking from experience there)
B
26
S
8
G
3
Posts: 210
Reputation: 5,973

Next

Return to How do I....?

Who is online

Users browsing this forum: flemmig, Matthew de, semaso, Skebab, Virpoja and 24 guests