Page 1 of 1

Max hp

PostPosted: Sun Sep 25, 2011 8:18 pm
by beginnerirvaz
could somebody help me to set a max hp. I already have a hp in my game and items the player can collect to increase hp. I would like to set my hp so it can never go above 100 so if the hp was at 80 and an item collected was worth 30 the hp could only raise to 100.
Thanks everyone.
Irvaz

Re: Max hp

PostPosted: Sun Sep 25, 2011 8:25 pm
by skydereign
The following code will do just that. It increases the hp by 30, but has a max of 100, since min returns the smaller of the two.
Code: Select all
hp=min(hp+30,100);

Re: Max hp

PostPosted: Sun Sep 25, 2011 9:02 pm
by beginnerirvaz
Sorry for being stupid but could you explain that for me?
My hp is a bit complicated but basically I have used an array of 5
Health type 1 count(shows number on screen)
Health type 2 count(shows number on screen)
Total health count ( I want to show the average of 1 and 2)
Health type 1=100
Health type 2=100

So I need to set health type 1 and 2 so they can't ever be more than 100 each. If a enemy hits my player I say health type 1 or 2 -=watever the value

I have an array of health items that when you collect them they show on screen if u have 1 you can click and this adds hp to either health type 1, 2 or both but I never want this to go above 100 for each.

I hope I'm making sense, thanks.
Irvaz

Re: Max hp

PostPosted: Sun Sep 25, 2011 9:08 pm
by skydereign
Yeah, it makes sense, I did help you out with your hp system before. Essentially the code I gave is a way of limiting, while increasing any number. So whenever you increase a variable, you can use that to limit it.
Code: Select all
variable+=10; // this is the normal way to increase variable by 10

variable = min(variable+10, 100); // this way increases variable by 10, but limits it to a max of 100

Now if you need to use a variable in an array, just replace that. But anyways, whenever you increase the variable you don't want to have exceed 100, use that code and it will never exceed 100.

Re: Max hp

PostPosted: Sun Sep 25, 2011 10:07 pm
by beginnerirvaz
Hey sorry I didn't relies it was you, that's great exactly what I need. I'll not b able to try that for an hour but I'll let you know what happens. I'm still having some trouble making an average of some of my array.
Thanks

Re: Max hp

PostPosted: Mon Sep 26, 2011 1:22 am
by skydereign
Hmm... not sure what to tell you for the average thing. I can upload a ged for you, but all it would be is a text actor with that code I gave in its create actor. I'd need to know more about what is going wrong.

Re: Max hp

PostPosted: Mon Sep 26, 2011 2:45 am
by master0500
Code: Select all
if (hp>100)
{
        hp=100;
}

would this work?

Re: Max hp

PostPosted: Mon Sep 26, 2011 2:50 am
by skydereign
It would, but using min is a better choice. It does the same thing, takes less lines, and doesn't involve an if.