Game Development Community

Getting player name from car

by Jason · in Torque Game Engine · 03/26/2006 (2:04 pm) · 3 replies

Hi.

In my game, you can kill people with the car. However, I can't figure out how to pass the driver's name as the source of the car damage in order to give the driver the %sourceClient.score in onDeath.


In my car's onCollision, I have these lines:

%driver = %obj.getMountNodeObject(0); // Grab Driver object from driving node
....
%col.damage(%driver, VectorAdd(%obj.getPosition(),%vec), 1000, "Car Impact");



This does 1000 damage and sends %driver as the source. However, since "%driver.name" is blank, so is %sourceObject.name over in GameConnection::onDeath (where the score is added):

...
else if (%sourceClient.name){
%sourceClient.incScore(1);
...

But I'm sure %driver isn't correct, because not only is %driver.name give no value, a call to %driver.incScore(1) says:

fps/server/scripts/vehiclemount.cs (235): Unknown command incScore.
Object (1499) Player -> ShapeBase -> GameBase -> SceneObject -> NetObject -> SimObject


I'm confused what value I'm getting from %driver = %obj.getMountNodeObject(0) and how to make it work.

[Note: %driver.getClassName() does report "Player". So i'm close, but maybe im getting mixed up between objects and datablocks or something.]

Help please!

About the author


#1
03/26/2006 (2:32 pm)
IncScore is a client (GameConnection) function, not a player function. I'm not sure if onDeath has the proper call backs to work with a player that isn't the control objects, so maybe look at modifying it to primarily use the client object as a reference and pass in %obj.getControlClient() to it.
#2
03/26/2006 (8:14 pm)
@i think you mean getControllingClient(); Thanks for the fast reply, it lead me to this function.

To get the gameconnection of the client sent to Armor::Damage(i think), it put


function Buggy::onCollision(%this,%obj,%col,%vec,%speed) {
...
if ( %buggyspeed >= 3 && %col.getClassName() $= "Player"){
%playerobject = %obj.getMountNodeObject(0);
%driver = %playerobject.getControllingClient();
%col.damage(%driver, VectorAdd(%obj.getPosition(),%vec), 1000, "Car Impact");
...
}


However, this caused a problem in the Armor::damage function.

....
// Deal with client callbacks here because we don't have this
// information in the onDamage or onDisable methods
%client = %obj.client;
%sourceClient = %sourceObject ? %sourceObject.client : 0; // I think i understand the ? operator, but this //doesnt make sense to me
if (!%sourceClient) %sourceClient = %sourceObject; // <----- MASSIVE HAKKKK!!!
if (%obj.getState() $= "Dead")
{
%client.onDeath(%sourceObject, %sourceClient, %damageType, %location);
}
...

There's an issue with %sourceclient not getting set right if the source of the damage is a car object. Normally, it seems, when a weapon does the damage, it sets sourceclient and object just fine. When the car does the damage, sourceobject gets the value that should be going to the sourceclient, and the sourceclient gets no value. I think the reason why i need my hakkk line is because the line above it should be:
%sourceClient = %sourceObject.client ? %sourceObject : 0;

But i dont have time to test it right now.
I had to use a million echo statements to check the variables as they passed along. Huge all day pain.
#3
03/26/2006 (9:18 pm)
I really am not to sure... I find the default arguments and setup for the onDamage, onDeath, etc. to all be rather wonky, so I've rewritten them all in code base.