How can i Control The Health Bar
by Balmer Steve · in Torque Developer Network · 10/28/2010 (9:05 pm) · 5 replies
Hi all
I have a player. When the enemy hit our player the Health Bar Should Reduced to certain %.Like that if enemy hit our player more times. The health bar should reduced according to that.
I have a code to display Health bar.
new GuiHealthBarHud()
{
profile = "GuiDefaultProfile";
horizSizing = "right";
vertSizing = "top";
position = "53 315";
extent = "26 138";
minExtent = "8 8";
visible = "1";
helpTag = "0";
showFill = "1";
displayEnergy = "1";
showFrame = "1";
fillColor = "0.000000 0.000000 0.000000 0.500000";
frameColor = "0.000000 1.000000 0.000000 0.000000";
damageFillColor = "0.000000 0.000000 0.800000 1.000000";
pulseRate = "1000";
pulseThreshold = "0.5";
value = "1";
};
Could any one help me . How can i control Health bar?
Thanks in advance
#2
10/29/2010 (12:34 am)
Also, just to note, your above code example is set to show energy instead of health.
#3
How can i apply damage? The Energy should reduced automatically.After the player eats the energy drink.Then The energy bar should fill. How can i control it? where i have write coding for it?
Thanks in advance.
11/08/2010 (6:47 pm)
@Michael Thank You for Your reply.How can i apply damage? The Energy should reduced automatically.After the player eats the energy drink.Then The energy bar should fill. How can i control it? where i have write coding for it?
Thanks in advance.
#4
If you're needing to apply damage directly without using a weapon then you would use the applyDamage() method, an example of this is found in the player script in Playerdata::Damage -- may be called Armor::Damage -- which needs to know the object to apply the damage too and how much damage to give.
To give energy simply use setEnergyLevel() which needs to know the object to give the energy to and the amount of energy to recharge. You could call this in your energy drink item onUse or onCollision depending on how you use the energy drink -- look at how the health patch & kit gives health: one does it on a keypress (Item::onUse), and one does it when the player runs over it (Item::onCollision) -- substitute your call to give energy in place of giving health.
Examples of applyDamage and setEnergyLevel:
11/09/2010 (5:10 am)
If you're using a projectile weapon, then damage is handled automatically for you so long as set the damage amount in your projectile datablock.If you're needing to apply damage directly without using a weapon then you would use the applyDamage() method, an example of this is found in the player script in Playerdata::Damage -- may be called Armor::Damage -- which needs to know the object to apply the damage too and how much damage to give.
To give energy simply use setEnergyLevel() which needs to know the object to give the energy to and the amount of energy to recharge. You could call this in your energy drink item onUse or onCollision depending on how you use the energy drink -- look at how the health patch & kit gives health: one does it on a keypress (Item::onUse), and one does it when the player runs over it (Item::onCollision) -- substitute your call to give energy in place of giving health.
Examples of applyDamage and setEnergyLevel:
// %obj = object that gets hurt // %damage = amount of damage %obj.applyDamage(%damage); //%obj = object that gets energy //%amount = amount of energy to give %obj.setEnergyLevel(%amount);
#5
When i click the button the energy should increase. How can i do it.
After few seconds or few minutes the energy should decreased automatically.
How can i do it.
11/25/2010 (7:31 pm)
@Michael Hall Thank you for your reply. When i click the button the energy should increase. How can i do it.
After few seconds or few minutes the energy should decreased automatically.
How can i do it.
Associate Michael Hall
Distracted...
Is your player a "Player" -- based on the Shapebase PlayerObjectType (there are Resources that allow it to work for Vehicles and other object types) -- and have a server connection?
How are you applying damage? The GuiHealthBarHud simply gets the energy or health from the object, but if you're not using standard shapebase damage code then it won't work without code modification.