Re: [Code] Prompt Change Colors based on HP

From: Daniel Koepke (
Date: 02/04/97

On Tue, 4 Feb 1997, Travis Turner wrote:

> I've tried at this with no luck for a while.. and have seen it before on 
> the list.. but it was a while back and i didnt save it..
> What i'm looking for is whan a player goes below 100% change the color of 
> the HP numbers to blue, 50% Yellow, 25% Red, etc..   I've tried the 
> following where it would use green at 100%, but anything under would give 
> a normal color..
> { dunno if this code is abso correct as i have it.. writing in mailer }
> percent = ((GET_HIT(ch) / GET_MAX_HIT(ch))*100);

Bad percent formula in C.  Remember you're using whole number integers.
C will round up a decimal, so GET_HIT(ch) / GET_MAX_HIT(ch) always will
equal 1.  Of course, you can see then, that 1*100 == 100 regardless of
what GET_HIT or GET_MAX_HIT actually are for that player.

Solution?  Simple change of the percent formula:

  percent = (GET_HIT(ch) * 100) / GET_MAX_HIT(ch);

It does the same thing just works with non-decimal numbers (as C integers
cannot have decimals, and you don't want to go into floats, etc. :)).

Daniel Koepke
Forgive me father, for I am sin.

| Ensure that you have read the CircleMUD Mailing List FAQ: |
|   |

This archive was generated by hypermail 2b30 : 12/18/00 PST