Help With Health

Posted by Theonlywonderboy on June 20, 2006, 5:18 a.m.

I don't use code so I need to know how to give an enemy health using the drag and drop icons. I know how to give an enemy health but for some reason I an't get the health to be tacken away from the enemy. I could use the help. Thanks.

Comments

Firebird 18 years, 10 months ago

Well, using code would be much easier for this, but meh. Use the variable icons. It's better if you go into the manual because you'll gain a greater understanding about them then from me :p.

Theonlywonderboy 18 years, 10 months ago

Okay I'll use code. Could someone give me code for this. Also where should I put the code

Polystyrene Man 18 years, 10 months ago

Well, since you'll be drawing the health you'll probably want to put it in the draw event. To draw it use the function draw_healthbar(x,y,etc.)

Firebird 18 years, 10 months ago

Okay. In the creation event -

int_health = 100;

This creates a local variblae, recognised by the object that created the variable only. You can change it's name to anything, but no spaces!. Here, we set the variable 'int_health' (I like to put prefixes on my variables. Comes from programming in C++) to 100. Our enemy will have 'int_health' set to 100 now. They have 100 health.

In the step event, put this in (Or in an event where it gets attacked) -

if int_health <= 0 {
  instance_destroy();
}

Pretty much, if int_health is below or equal to zero, destroy the instance (object).

Now, in a collsion event with the bullet or whatever, put this -

int_health -= 10;

This takes away 10 from the int_health variable. If it reaches zero, then, you know what happens.

You could also add this to a collsion event with a bullet, to prevent any more health being taken away -

with(other) {instance_destroy();}

That sets the code scope (what it affects) to what has collided with the enemy (the bullet, for example) and then destroys it.

I hope you understood that!

Firebird 18 years, 10 months ago

Oh yeah, and if you want to draw a health bar, use this code in the draw event -

draw_sprite(sprite_index,image_index,x,y);

draw_healthbar(x1,y1,x2,y2,amount,backcol,mincol,maxcol,direction,showback,showborder);

The draw_sprite is for preventing the sprite not being drawn. Take the draw_sprite code out to see what I mean. Look in the manual for the meanings of draw_healthbar().

twisterghost 18 years, 10 months ago

You do know that you are spelling "Medievil" wrong, right?

Theonlywonderboy 18 years, 10 months ago

It's supposed to be spelled like that. It's implying evil