0 Favourites

Creating a Random Mob Spawner in the Free Ed?

  • 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:

    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.

    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.

  • 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.

  • 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.

    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?

  • Quick and dirty prototype:

    <img src="http://www.infinitepossibilitygames.com/demos/MobSpawnerExample/mobspawnerexample.PNG" border="0" />

  • 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.

    <img src="http://dl.dropbox.com/u/34375299/Construct%202/examples/spawn.JPG" border="0" />

    It basically do the same thing like in theubie example but using less events

  • 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.

  • 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.

    <img src="http://dl.dropbox.com/u/34375299/Construct%202/examples/spawn.JPG" border="0" />

    It basically do the same thing like in theubie example but using less events

    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.

    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 >.>

  • 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.

  • 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.

    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.

  • 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)

  • 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)

    So add a second condition to do say random(0,100) <= 20 (for 20% spawn chance) and then a third condition that checks every 3 seconds? What would that even look like? 0_o

  • Something like this

    <img src="http://www.infinitepossibilitygames.com/demos/MobSpawnerExample/conditions.PNG" border="0" />

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • Something like this

    <img src="http://www.infinitepossibilitygames.com/demos/MobSpawnerExample/conditions.PNG" border="0" />

    I figured something like that. Thanks sir!

    Next on my list is to figure out how to make a mob stay at a distance from a player while still following them, shooting bullets at them, and moving around in a random pattern.

  • So I am having an issue where it doesnt seem that anything wants to trigger...

    Here is what I have:

    <img src="http://i.imgur.com/k5sdbnV.png" border="0" />

    No matter what (even without the random and the every second statements) the spawner is doing nothing...

  • Check the coordinates for Player.X,Y and Spawner.X,Y and make sure you've got the right objects selected.

    Disable all three of the requirements, then enable them one by one until it stops working and we can go from there.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
302 48,088
Eric Matyas's avatar
Eric Matyas
Unread hot topic
233 187,230
Kenney's avatar
Kenney
Unread hot topic
153 104,445
DravenX's avatar
DravenX