Game Development Community

A quick question about a players health

by Snaggz · in Torque Game Engine · 04/30/2006 (6:54 pm) · 7 replies

Ok i have:

function Armor::onDamage( %this, %obj, %damage)
{
echo( %obj @ " has been dmged by:" @ %damage );
ScoreCounter.setText("Mob's HP: " SPC %this.Health);
}

what do i put in instead of %this.Health to show the remainder of his armor that he has left?

#1
04/30/2006 (7:17 pm)
%this.maxDamage - %obj.getDamageLevel()

Alternately

%this.maxDamage * %obj.getDamagePercent()

ScoreCounter.setText isn't going to work in a real game though. You have to set GUI elements with CommandToClient to work properly in multiplayer.
#2
04/30/2006 (7:23 pm)
Ok thanks a lot. I'll try and go back to the CommandToClient setup I origially had.
#3
04/30/2006 (7:32 pm)
You can use the numeric health indicator resource if you don't figure it out on your own..
#4
04/30/2006 (7:33 pm)
Hmm how would i get the %client out of the armor function?
I remember in the getting started tutorial on the collision function you set %client = %col.client but im not sure how to do that on this one.
#5
04/30/2006 (8:01 pm)
Use the numeric health indicator resource, everything is set as it should be. Actually.. hm.. that resource's main content area is blank now. Odd. Here's how mine is handled.

Place this code block in client/scripts/playGui.cs:
function clientCmdSetHealthAmountHud(%value)
{
   if ((%value-mFloor(%value)) < 0.5)
   {
   %ret = mFloor(%value);
   }
   else
   {
   %ret = mCeil(%value);
   }

   HealthAmount.setText(%ret);
}

Don't forget to make a GuiTextCtrl that is named "HealthAmount" in your GUI.

Now in server/scripts/player.cs, add this to the bottom:

function Player::UpdateHealth(%this)
{
   %this.schedule(100, "UpdateHealth");

   %this.client.setHealthAmountHud(100 - %this.getDamageLevel() );
}

function GameConnection::setHealthAmountHud(%client, %amount)
{
    commandToClient(%client, 'SetHealthAmountHud', %amount);
}

In the Armor::onAdd function, put this along with the rest of the stuff:

%obj.client.setHealthAmountHud(100);

Also add this in server/scripts/game.cs in function GameConnection::createPlayer after
%player.setShapeName:
%player.UpdateHealthBar();

Should work. Might've forgotten something, let me know.
#6
04/30/2006 (8:42 pm)
You should be using the players maxDamage value, not a numeric value... and quite bluntly, updating the players health every 100ms is retarded. It makes much more sense to have it in their onDamage callback.

You can see there that %obj.client will have your reference to the client though.
#7
05/01/2006 (9:59 am)
Thanks guys... i think ill stick with the basic ondamage function. but if i need to make a gui healthbar ill look back to this post.