HELP! about health/life

Talk about making games.

HELP! about health/life

Postby robin.deman » Tue Oct 24, 2006 8:40 am

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!
User avatar
robin.deman
 
Posts: 70
Joined: Sat Nov 12, 2005 9:50 am
Location: Netherlands
Score: 0 Give a positive score

Postby DilloDude » Tue Oct 24, 2006 10:08 am

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
}
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby pavel329 » Wed Oct 25, 2006 3:02 am

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.
Drugs r bad.
Mgaay?

Image
User avatar
pavel329
 
Posts: 269
Joined: Thu May 25, 2006 2:05 pm
Location: Behind you
Score: 5 Give a positive score

Postby robin.deman » Fri Oct 27, 2006 6:27 am

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!
User avatar
robin.deman
 
Posts: 70
Joined: Sat Nov 12, 2005 9:50 am
Location: Netherlands
Score: 0 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron