[Help]Type conversions?

Posts 1–4 of 4 · Page 1 of 1
[Help]Type conversions?
Alright so I have 2 addresses, one is for Total Health, one is for Current Health.. The problem is for some reason or another the Total is type(2Byte) and the Current is type(Float) What I am trying to do is determine when the Current Health gets to a certain % of the total for example..
Code:
#define MaxHP			(*(short*)( 0x030C178E ) )
#define CurHP			(*(float*)( 0x0307A66C ) )

if(CurHP < (MaxHP * 0.6))
{
    do stuff
}
^ The idea is to "do something" once you reach 60% of your total Health!
The problem is that MaxHP is of type 2BYTE(INT) and CurHP is type FLOAT, anyone have any advice?
Cast your short into a float and store it in a float that you declare.

[php]
float MAX_HP = (float)*(short*)0x030C178E;
float CURR_HP = *(float*)0x0307A66C;

if(blah blah)
{
// do whatever..
}
[/php]
Quote Originally Posted by +NULL View Post
MaxHP is of type 2BYTE(INT)
Integers are 4 bytes, short int would be 2 bytes.

Also @ void: 2 bytes parsed as float(4 bytes) will have weird results if the last two bytes contain values of something random ;P
Quote Originally Posted by Hell_Demon View Post
Integers are 4 bytes, short int would be 2 bytes.

Also @ void: 2 bytes parsed as float(4 bytes) will have weird results if the last two bytes contain values of something random ;P
Orly. Fine D:

[php]
float MAX_HP = 0;

...

MAX_HP = (float)*(short*)0x030C178E;
[/php]
Posts 1–4 of 4 · Page 1 of 1

Post a Reply

Tags for this Thread

None

Need help?