How do I Control Several Monster Properties

Get help using Construct 2

Post » Fri Feb 17, 2017 9:00 am

Hey there,

So basically, I have one monster who, when hit, pops up the damage received, over its head. It has the normal instance variables that an enemy normally would and its own movement etc. This all works great for now...

My problem is that I want to add different types of monsters into the game and somehow group the collision events with my weapon. Unfortunately, when I use a Family, the game doesn't work as intended. Now, I can manually insert each onWeaponHit for every single monster and this will work how I want it to... but I feel this probably isn't the correct way.

Here is what I am currently using. Should I just repeat this for each monster type or do you know of a way to handle all of this with something simpler?

Image
B
56
S
15
G
13
Posts: 826
Reputation: 17,645

Post » Sat Feb 18, 2017 11:59 am

Create a Family for your monsters. Do this by selecting 'Families' in the Project bar, right-clicking, and selecting 'Add family...'. A dialog will pop up where you can select your monster, and add it to the list. Now, when you clone the monster, it will create a new monster in the same family. You can apply rules to the whole family, or just single monsters, so they can all - for example - be damaged the same way, but move differently.

You should be able to replace your monster in the current project with a Family in order to create a basic 'class' of monster from its current behaviours by simply using 'Replace object' on these events, and replacing the monster with its family. You may need to create new variables for universal properties like health etc on the family, as instance variables from inidividual monsters will not be visible when referring to their family.

See https://www.scirra.com/manual/142/families for more info :)
The LEVEL GENERATOR TOOLKIT



24 functions dedicated to producing randomly generated terrain for all kinds of games.
B
25
S
7
Posts: 242
Reputation: 2,306

Post » Sat Feb 18, 2017 11:24 pm

Thank you for the reply but unfortunately Families will not work for what I am trying to do here. I guess I will just have to duplicate the events for each enemy type.
B
56
S
15
G
13
Posts: 826
Reputation: 17,645

Post » Mon Feb 20, 2017 2:07 pm

Can you describe how Families aren't working the way you're expecting them to? Because this is the exact use-case for Families - if they're not working how you expect, there's a good chance you're somehow mis-using them.
The LEVEL GENERATOR TOOLKIT



24 functions dedicated to producing randomly generated terrain for all kinds of games.
B
25
S
7
Posts: 242
Reputation: 2,306

Post » Tue Feb 21, 2017 6:42 am

that's the least you can do for now. duplicate the events and action for each monster/enemy type
B
79
S
31
G
7
Posts: 148
Reputation: 9,179

Post » Tue Feb 21, 2017 10:07 am

Maybe your problem and the one I was having are related? See here..

how-to-handle-a-collision-with-a-family-in-an-effective-way_t187858
B
16
S
6
Posts: 26
Reputation: 1,221

Post » Tue Feb 21, 2017 10:22 am

As seen in the first response, yes you use families, this avoids the need to duplicate events for each enemy type, that's what families are for!
B
46
S
16
G
78
Posts: 2,167
Reputation: 46,351

Post » Tue Feb 21, 2017 10:30 am

Indeed families sounds like something that should work.
Your issue might come from Function picking that you would have to handle differently.

You rely on the Function.ReturnValue from "Monster_Hit", but pass no UID for picking to MonsterHit (and we don't know what is inside this function).
Adapt it so it can handle families and is passed the family UID of the correctly picked monster and all should work as intended.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
292
S
115
G
96
Posts: 7,295
Reputation: 70,785

Post » Tue Feb 21, 2017 2:43 pm

mrtumbles wrote:Can you describe how Families aren't working the way you're expecting them to? Because this is the exact use-case for Families - if they're not working how you expect, there's a good chance you're somehow mis-using them.


Agree. Families is the way to go.

Some tips:
1. the "for each" event you have at event 28 is not necessary because C2 already does a for each object when you have it on a condition like "is overlapping Monster1" in your case. Read: "Unnecessary 'For-each' loops" in https://www.scirra.com/blog/141/common- ... nd-gotchas
2. Usually when you use "every X seconds", es because you want to do something "every x seconds", then, other conditions have to be after that condition not before like the one you have at event 28. Always put conditions In words so it would make sense like "every x seconds I want to check if some object is overlapping another". In your code, collision check is being made every tick, not every x seconds.
Lead developer at Octeto Studios
Visit our portfolio at: http://www.octetostudios.com/ :)
Facebook || Twitter || Youtube
B
37
S
7
G
5
Posts: 217
Reputation: 5,614


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, PROxMTswatTR and 13 guests