Game Development Community

changing image for health state

by Richard Preziosi · in Torque Game Engine · 08/09/2010 (1:16 am) · 2 replies

I was attempting to make a bitmap ctrl that i can change the image of depending on the client's current health. I understand the how in a sense, just cannot seem to set it up properly. Here is how i was going about it:

server/commands.cs
function updateHealthImage(%client)
{
   %healthdamagelevel = %client.getDamageLevel();
   if (%healthdamagelevel = 50);{
      healthbarhud.setbitmap("./starter.fps/client/ui/healthimages/healthbar50");
   }
   if (%healthdamagelevel = 25);
   {
      healthbarhud.setbitmap("./starter.fps/client/ui/healthimages/healthbar25");
   }
   if (%healthdamagelevel = 75);
   {
      healthbarhud.setbitmap("./starter.fps/client/ui/healthimages/healthbar75");
   }
}

I was attempting to set this by calling updateHealthImage, any time that the player was damaged or healed, however I know that the above code is wrong, plus i can't get getDamageLevel() to do anything. Any advice on this would be great.

#1
08/09/2010 (2:12 am)
Quote:plus i can't get getDamageLevel() to do anything
Presumably you want %client.getControlObject().getDamageLevel(). A client doesn't have a damage level - it's just a GameConnection!

Also, I think getDamageLevel will return a float in the range 0...1. So you'd want to be comparing against 0.25, 0.5, and 0.75. Also, inequalities. You don't want to only change the bitmap when the client's health is exactly a certain value.

I assume you want the healthbar75 to display when the health is greater than .75 as well? So your function could look something like this:
Quote:
1. If client's health is less than .25, set the healthbar25 image
2. Otherwise if the client's health is less than .5, set the healthbar50 image
3. In all other cases, set the healthbar75 image
#2
08/09/2010 (10:15 pm)
Ah ok, i will try this out momentarily and let you know how it goes.

And actually i do want it to only show at exactly at certain intervals due to damage being restricted to a specific amount, I just used those in the above to save space/time while typing it out.

Thanks a ton, hopefully I can get it going.