A lot of enemies with their own health. How?

Talk about making games.

A lot of enemies with their own health. How?

Postby xenidius93 » Wed Jul 30, 2014 1:10 am

It's me again :). I have one good question for you guys. How to make one integer (health) for one actor (enemy), when I want to make a lot of enemies? You know, when the enemy will be created, health should be created for him too. enemy.1 = "health 1", enemy.2 = "health 2". How to do this?
xenidius93
 
Posts: 37
Joined: Mon Jul 28, 2014 4:24 am
Score: 1 Give a positive score

Re: A lot of enemies with their own health. How?

Postby lcl » Wed Jul 30, 2014 1:16 am

When creating the variable, select 'Actor variable' instead of 'Global'.
Now every actor has their own unique health variable accessible via actor.health
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: A lot of enemies with their own health. How?

Postby xenidius93 » Wed Jul 30, 2014 2:57 pm

This works the same way as normal variable :/. When there's collision between enemy and shot, in enemy Collision > Script Editor:

DestroyActor("Collide Actor");
enemy.health = enemy.health - 1;

What's wrong with this?
xenidius93
 
Posts: 37
Joined: Mon Jul 28, 2014 4:24 am
Score: 1 Give a positive score

Re: A lot of enemies with their own health. How?

Postby lcl » Wed Jul 30, 2014 4:15 pm

If you write enemy.health there, it'll use enemy.0's health variable. What you want to do is to just use health, because we're in the enemy actor's own event. That way it'll use the clone that triggers the event. When you're not in the current actor's code, you'll have to use the getclone function.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: A lot of enemies with their own health. How?

Postby xenidius93 » Wed Jul 30, 2014 4:28 pm

I don't understand :(, so how it should looks like? Where I should to use getclone?
xenidius93
 
Posts: 37
Joined: Mon Jul 28, 2014 4:24 am
Score: 1 Give a positive score

Re: A lot of enemies with their own health. How?

Postby skydereign » Wed Jul 30, 2014 7:07 pm

xenidius93 wrote:I don't understand :(, so how it should looks like? Where I should to use getclone?

getclone would be used when you want to access a specific enemy actor. In this case of collisions though gE already provides a way to do this. If the actor with that collision event is enemy, than all you need to do is use the health variable.
Code: Select all
DestroyActor("Collide Actor");
health = health - 1;

This is because the event actor is the specific clone you want to have health reduced. If you had happened to put this event in the bullet actor, it would look like this.
Code: Select all
DestroyActor("Event Actor");
collide.health = collide.health - 1;

If you type an actor variable out in a script, it means the variable of what gE calls the event actor (the actor that is running the script). The collide actor is the one that caused the collision event.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: A lot of enemies with their own health. How?

Postby xenidius93 » Wed Jul 30, 2014 7:35 pm

So what's wrong? Why it doesn't working? This is the project, please check it out: http://sendfile.pl/256362/test_zycia_wrogow.zip
xenidius93
 
Posts: 37
Joined: Mon Jul 28, 2014 4:24 am
Score: 1 Give a positive score

Re: A lot of enemies with their own health. How?

Postby skydereign » Wed Jul 30, 2014 8:03 pm

That is because you aren't using getclone correctly. In this case you don't need to use getclone at all, nor should you be using enemy.health. As lcl said, enemy.health will get you the health of enemy.0. In your case you want to use the following.
skydereign wrote:
Code: Select all
DestroyActor("Collide Actor");
health = health - 1;
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: A lot of enemies with their own health. How?

Postby Hares » Wed Jul 30, 2014 8:13 pm

xenidius93 wrote:So what's wrong? Why it doesn't working? This is the project, please check it out: http://sendfile.pl/256362/test_zycia_wrogow.zip

Because in your code you still use "enemy.health" to access the health variable, instead of just "health".

So in all the code on the enemy actor, change it to "health":
-in the create actor
-in the draw actor
-in the collision

You can put the twz-fixed.ged in same folder as the original, and see for yourself ... :wink:

edit: ahh ... skydereign was faster :)
Attachments
tzw-fixed.ged
(3.36 KiB) Downloaded 132 times
User avatar
Hares
 
Posts: 105
Joined: Fri Dec 20, 2013 8:39 pm
Location: Belgium
Score: 14 Give a positive score

Re: A lot of enemies with their own health. How?

Postby xenidius93 » Wed Jul 30, 2014 9:07 pm

Okay, thanks guys so much :). And thank you Hares for fixed project ;D.
xenidius93
 
Posts: 37
Joined: Mon Jul 28, 2014 4:24 am
Score: 1 Give a positive score

Re: A lot of enemies with their own health. How?

Postby mindcontrol » Wed May 27, 2015 4:57 pm

Hi, i tried, but is not working, each of mine enemys have their own life, but when i shoot to one enemy, they lose 2hp, but , a random enemy lose 2 hp, so sometimes i shoot a enemy and another one dies :/ . I'm using this codes:

On enemy create actor -> hp = 5;

On enemy draw actor->
if (hp<=0) {
DestroyActor("Event Actor");
}

On enemy collision with shoot -> enemy.hp=enemy.hp-2;

Hp is a actor variable as i read.
mindcontrol
 
Posts: 24
Joined: Sun Apr 26, 2015 12:54 pm
Score: 2 Give a positive score

Re: A lot of enemies with their own health. How?

Postby lcl » Wed May 27, 2015 7:26 pm

Your problem is here:
mindcontrol wrote:On enemy collision with shoot -> enemy.hp=enemy.hp-2;

Writing enemy.hp targets the enemy with the cloneindex 0.
What you should do is just this:

This will take away 2 hp from the actor that is executing the code, so it would damage the enemy that has collided with the bullet actor you're calling with the name "shoot". :)
Code: Select all
hp=hp-2;


EDIT:
Also, you'd better move the other code together with the damage code. It's always better to try to avoid putting codes in Draw Actor, as those get executed every frame when the actor exists, and most things are not needed to be executed so often. So, ideally, you'd have this in you "enemy" collision with "shoot":
Code: Select all
hp = hp - 2;

if (hp <= 0)
{
    DestroyActor("Event Actor");
}
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: A lot of enemies with their own health. How?

Postby Hares » Wed May 27, 2015 7:32 pm

Instead of
On enemy collision with shoot
Code: Select all
enemy.hp=enemy.hp-2;


try this
Code: Select all
hp=hp-2;


The difference is that if you set "enemy.hp" you only set it for enemy.0 (the first clone).
If you just set "hp" you set it only for the current clone (the current enemy clone in the collision).

Or as lcl explained it:
lcl wrote:If you write enemy.hp there, it'll use enemy.0's hp variable. What you want to do is to just use hp, because we're in the enemy actor's own event.


edit: ahh ... this time lcl was faster :D
User avatar
Hares
 
Posts: 105
Joined: Fri Dec 20, 2013 8:39 pm
Location: Belgium
Score: 14 Give a positive score

Re: A lot of enemies with their own health. How?

Postby Zivouhr » Thu May 28, 2015 12:34 am

Good tips, thanks to all. 8)
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score

Re: A lot of enemies with their own health. How?

Postby mindcontrol » Thu May 28, 2015 8:01 am

Is working! thank you guys :)
mindcontrol
 
Posts: 24
Joined: Sun Apr 26, 2015 12:54 pm
Score: 2 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron