Author Topic: Vehicle Health Bar?  (Read 3169 times)

I'm looking for an addon for a vehicle health bar that works either like Wrapperup's or Kyuande's health bar, except it measures the health of the vehicle/mount the player is currently in. My purpose is for a racing gamemode where the vehicles battle eachother with powerups. Wrapperup's would work perfectly for this since you could see other cars health bars. (Even if this were to float above the player but possess the health of the vehicle that would work.)
« Last Edit: September 16, 2017, 12:16:04 PM by speeddog73 »

If players never leave cars and you don't want them dying without their cars blowing up, you could just change it to be the amount of health whatever vehicle they're in has.

If players never leave cars and you don't want them dying without their cars blowing up, you could just change it to be the amount of health whatever vehicle they're in has.
The vehicle health and player health are not linked and cannot mean the same thing. If I were to set the health of the player and health of the car to be the same amount, the health bar would still show health after the car has been destroyed, or the player (with healthbar) would die and the car would still be present. It wouldn't work right.
I would need the health bar to be linked to the car's health, and not the player's health.

Neat idea, may include in the health bar update as an option for the server to show health bars to a vehicle they are in (will be a separate health bar).

Neat idea, may include in the health bar update as an option for the server to show health bars to a vehicle they are in (will be a separate health bar).
That would be awesome! But for now, is there a way to manually change it in the addon's coding? Like a way to change "Player" values to "Mount/Vehicle" values?

Bump.
Anybody know anything relating to coding this manually or something? If somebody were to script one I'd prefer Wrapperup's since you can actually see another player's health with that addon, which would work amazingly.

Sorry been very busy lately, seems to never end now due to work and school (studying is a huge pain now). I'm not sure when the update will come out but it shouldn't take long to make it either, it's just the lack of time I have with gaming.

Kyuande's
looks like the main part to edit would be the send data to client bit
Code: [Select]
function Player::sendHealthData(%this, %val)
{
if(!isObject(%client = %this.client))
return;

if(%this.getState() $= "dead")
{
commandToClient(%client, 'setDamageLevel', 0, 0);
commandToClient(%client, 'setHealthBarVisible', false);
return;
}

%max = %this.getMaxHealth();
%curHp = %this.getHealth() + (%this.pseudoHealth + %this.tf2Overheal);

%dmgPercent = %this.getHealthLevel() - (%this.pseudoHealth + %this.tf2Overheal);
%dmgPercent /= %this.getDatablock().maxDamage;
if($HealthBar::Mode == 1)
%hp = mClampF(%curHp, 0, %max + (%this.pseudoHealth + %this.tf2Overheal)) SPC %max;

if(%val) //I means they are invincible, it's not always accurate
%hp = "I";

commandToClient(%client, 'setDamageLevel', %dmgPercent, %hp);
if(!%player.healthBarVisible)
{
%player.healthBarVisible = 1;
commandToClient(%client, 'setHealthBarVisible', true);
}
}

adding a check to see if the player is in a vehicle, and send vehicle health data instead of vehicle health data
after a bit of digging, I found %player.getControlObject(); returns the vehicle the player is in (0 if none)
Code: [Select]
function Player::sendHealthData(%this, %val)
{
if(!isObject(%client = %this.client))
return;

if(%this.getState() $= "dead")
{
commandToClient(%client, 'setDamageLevel', 0, 0);
commandToClient(%client, 'setHealthBarVisible', false);
return;
}

if(!isObject(%vehicle = %this.getControlObject())) //not in vehicle
{
%max = %this.getMaxHealth();
%curHp = %this.getHealth() + (%this.pseudoHealth + %this.tf2Overheal);

%dmgPercent = %this.getHealthLevel() - (%this.pseudoHealth + %this.tf2Overheal);
%dmgPercent /= %this.getDatablock().maxDamage;
if($HealthBar::Mode == 1)
%hp = mClampF(%curHp, 0, %max + (%this.pseudoHealth + %this.tf2Overheal)) SPC %max;

if(%val) //I means they are invincible, it's not always accurate
%hp = "I";
}
else //in vehicle
{
%max = %vehicle.getDataBlock().maxDamage;
%curHp = %max - %vehicle.getDamageLevel();
%dmgPercent = 1 - %vehicle.getDamagePercent(); //is % health remaining, not % damaged?
}

commandToClient(%client, 'setDamageLevel', %dmgPercent, %hp);
if(!%player.healthBarVisible)
{
%player.healthBarVisible = 1;
commandToClient(%client, 'setHealthBarVisible', true);
}
}

replacing that function may work, let me know if there's any issues
hopefully that's solve the problem until kyu/vis updates it for real

replacing that function may work, let me know if there's any issues
hopefully that's solve the problem until kyu/vis updates it for real
Thank you for taking the time to help. I replaced your code with the piece you specified in Kyuande's Script_Healthbar and ran a few tests in Single Player but I couldn't get the health bar to change at all while in a vehicle. It still followed the same method of it being tied to the player. I double-checked everything and ran my client twice but found nothing has changed from the original. Maybe I pasted it wrong?

Nah it doesn't update correctly, you have to also package the vehicle damage function as well -- I have some time this weekend so I can try to make an update that time.

Nah it doesn't update correctly, you have to also package the vehicle damage function as well -- I have some time this weekend so I can try to make an update that time.
That would be awesome, thanks!

urg, didn't see that bit, thought I saw something on a loop in there

also, may not work for passengers, forgot to test how to get what vehicle they're in

edit: use %p.getObjectMount();, it works for both driver and passengers (still returns 0 for not mounted, or can use %p.isMounted();)
« Last Edit: September 22, 2017, 11:30:25 AM by phflack »

got it working, except that the tank explode at 10%, jeep explodes at 0%
I think it might be because the tank is drivable for a bit while exploded
just replace the server.cs file with this new one and it should work (only able to test it locally)

also, feel free to use any of the bits when you update the mod for real

do note that this works for mounting bots and vehicles, but the tank turret has its own health bar