Page 1 of 1

HELP! about health/life

PostPosted: Tue Oct 24, 2006 8:40 am
by robin.deman
Hi there, i have a question.
Somewhere on the forum i saw an code and instructions about how to create a simple health/life meter.
It worked but somehow i deleted the script during my project..

I saw the following but that looks like it but aint it..
http://game-editor.com/forum/viewtopic. ... light=life

And it seemed to look like the following:
Adding an Actor variable called "life"

and adding a code like the following:
life--;
if(life <= 0)
{
//Game Over
}

Now i cannot get it to work, does anybody know where i can find the script back on the forum? :cry: :cry: :cry:

What i wanted to do is make it possible for the player to be hit 5 times by an enemy before he dies..
The code/tutorial/help topic on this forum was very clear and worked instantly.

It would really help me a lot!

PostPosted: Tue Oct 24, 2006 10:08 am
by DilloDude
Create an actor integer called life (or health or whatever). On your enemy's create actor event, set life to 5 (or whatever you want). On your collision (or whatever event damages the enemy),
Code: Select all
life -= 1;
//life -- will do the same thing, but you might want some attacks to do more damage, so you could put life -= 2


Tthe next part can be done in the collision event, or in draw actor. If done in draw actor, you can have lots of different events decreasing the health, and you don't need to put the same code lots of times:
Code: Select all
if (life <= 0)
{
    DestroyActor("Event Actor");//or any other code you want
}

PostPosted: Wed Oct 25, 2006 3:02 am
by pavel329
Thanx.I have been using GE for a very long time....and i still had not figured that out.I would always forget to look in the forums too.Lol.I guess i finally did.

PostPosted: Fri Oct 27, 2006 6:27 am
by robin.deman
Got it!
Forgot to put on draw actor:
playerhealth = 5;

on collision: with enemy
playerhealth = playerhealth -= 1;

on draw actor
if(playerhealth<000)
{
playerhealth=0;
ExitGame();
}

and it works!