Game Development Community

Vehicle Healthbar?

by Josiah Wang · in Torque Game Engine · 01/08/2005 (5:23 pm) · 17 replies

Alrighties, I think I sorta got my player to be a vehicle....all I did was change line 294ish to say this:

// Create the player object
   %player = new FlyingVehicle() {
      dataBlock = Drone;
      client = %this;
   };

WHen I load up the game, its fine, but the only problem i see is that my healthbar doesn't display...it's like blank...

any help on this? I looked at playGUI.gui, but couldn't find anything..


thanks!

edit: i also noticed that I wasn't taking any damage from my weapon. I'm sure that the weapon damage had to have hit me (i set damageRadius to 200), and I know i should've died (i set both radiusDamage and directDamage to realllllly high amounts). The red screen flashes aren't showing

#1
01/08/2005 (11:01 pm)
The normal damage function is Armor::Damage() or something like that in player.cs. You will have to write a function to either apply damage to the vehicle or the player inside the vehicle when the vehicle is hit. I believe that is what is happening.
#2
01/12/2005 (12:45 pm)
Hrmm...I looked in the engine/game/fps directory, and I found a file called guiHealthBarHud. Seemingly (and somewaht obviously), it's what controls the health bar hud being drawn. I checked around line 98, and I found this statement:

if (!control || !(control->getType() & PlayerObjectType))

I changed it a lil bit so that it would read

if (!control || !(control->getType() & PlayerObjectType)[b] || !(control->getType & VehicleObjectType)[/b])

will this work?

note: the only reason i'm doing this is because i won't really have a player() datablock (as you see in my first post). I know it'll probably get screwed up if i do have a player() datablock. So if i'm not gonna have a player(), should i remove the !(control->getType() & PlayerObjectType) completely?
#3
01/12/2005 (2:12 pm)
Hrm, ok, I got the health bar to show up....now another issue showing up is that it doesn't know what to do when the vehicle runs out of health...

i tried searching around vehicle.cc for damage/death/dead/destroy - only damage came up, and it was all for the damageemitters. So i looked at player.cc for a model, and I found that they have a damageState and onDeath functions. Is there any way to port them into vehicles? (ie can i just copy/paste, mod a lil, and done?)
#4
02/09/2005 (1:58 pm)
How did you get the health bar to show up? I have the same problem (No player mounted on vehicle).
#5
02/09/2005 (2:02 pm)
Heh, i got the healthbar to show up, but i still couldn't get it to do something when i died...

anyways, find the line in game/fps/guihealthbarhud.cc that says:

if (!control || !(control->getType() & PlayerObjectType))


I'm assuming that checks whether or not the thing being controlled is a player. what we wnat to do is also add if it's a player OR a vehicle.

So change that statement to read:

if (!control || !(control->getType() & PlayerObjectType) || !(control->getType() & VehicleObjectType))

and that should do the trick.

hope that helsp!
#6
02/09/2005 (2:53 pm)
Thanks... try this in your vehicle script.
function MyVehicle::onDamage(%this, %obj, %delta)
{
	Parent::onDamage(%this, %obj);
	%currentDamage = %obj.getDamageLevel();
	if(%currentDamage > %obj.destroyedLevel)
	{
		if(%obj.getDamageState() !$= "Destroyed")
		{
			if(%obj.respawnTime !$= "")
				%obj.marker.schedule = %obj.marker.data.schedule(%obj.respawnTime, "respawn", %obj.marker); 
			%obj.setDamageState(Destroyed);
		}
	}
	else
	{
		if(%obj.getDamageState() !$= "Enabled")
			%obj.setDamageState(Enabled);
	}
}
#7
02/16/2005 (3:35 pm)
Ok doesn't look like that worked. Anyone have any suggestions?
#8
02/16/2005 (3:38 pm)
I made a resource many moons ago, but it was based off of player mounting a vehicle. Still it is VERY easy. It will be a good challenge for you.
#9
02/16/2005 (3:52 pm)
@Anders what doesn't work? the code mods or your script? I remember i had some trouble compiling my code, due to some misplaced paranthesis >.,
#10
02/16/2005 (4:13 pm)
The script. I've been shooting at a vehicle for some time, but doesn't appear to take any damage. (I don't have players mounted in the vehicle here, and I won't have it either) :)

(FlyingVehicle at that)
#11
02/16/2005 (4:30 pm)
I must read some more code I guess... Can't leave all this to the community to figure out :)
#12
02/16/2005 (4:36 pm)
Hmm can't find anything about damage in flyingVehicle.cc

Should I 'steal' code from somewhere? Need some help on this afterall :)
#13
02/16/2005 (4:59 pm)
Start simple put an echo in the code

something like
echo("flying vehicle ID " @ %obj @ " recieves "@ %delta @ " in damage");
then maybe include the vehicles current damage amount, and make sure it keeps changing
If you don't have any emitters or debris files you won't know it is taking damage untill it mysteriously goes away
#14
02/16/2005 (5:12 pm)
Yeah, only got the 'health' bar. I'll try that. Thanks for the tip.
#15
02/16/2005 (7:13 pm)
@Anders it's probably going to be in vehicles.cc...i've noticed that all the 'common' stuff will be in vehicles.cc most likely....all the physics and stuff that makes them diff is usualyl in their appropriate file

@Anthony lol that's just the way i did it. My vehicle is taking damage (mind you i didn't change anything except for a vehilce health bar...). The delta and obj show up correctly....hrm...maybe i should test with damage emitters
#16
02/16/2005 (8:38 pm)
Anyone know how to apply damage to a nonmounted controlled (player) vehicle manually from console? I'm peeking in shapeBase.cc right now... I think I got lost. I added the echo into my onDamage but it doesn't even display in console, so either my bullets ain't making damage (I'm running one client + one serverclient to test this) or I'm having to do some C++ mods in shapeBase.cc ... Which is it though? Should I just start ripping my hair out? ;)
#17
02/17/2005 (1:02 pm)
Soon as I added
function FlyingVehicleData::Damage(%data, %obj, %sourceObj, %pos, %damage, %damageType)
{
     %obj.applyDamage(%damage);
}

It works. Kinda knew I was missing something.. ;)