SouceClient is null with vehicles?
by Arland (Barry) Woodham · in Torque Game Engine · 11/16/2004 (9:21 am) · 5 replies
This has been driving me crazy so I am appealing to gg community now. I have managed to change out the player.cs to be a vehicle complete with a weapon thanks to LabRat's code. Then I managed to incorperate the vehicleguihealth.cc file and got a working health bar for my vehicle. It took me some time after that but I managed to get weapon fire to take down health and projectiles to collide with the vehicles making the deathmatch aspect work. I even managed to get the vehicle to be destroyed and then spawn a new version.
However this is where I am now stuck. When the player dies by killing themselve's or by another's fire the %1 was killed by %2 always fires no matter what. What I have tracked the problem using echos to send debug info to the console. Basically when trying to get the %sourceClient info the information returned is always null not as in "null" but nothing just blank.
Here is a snippet of my damage and onDamage functions from player.cs
And then the onDeath in game.cs
So that is basically it if my player.cs is defining a character %sourceClient works but if it is a vehicle it returns no value. So any of the master coders out there have any ideas?
However this is where I am now stuck. When the player dies by killing themselve's or by another's fire the %1 was killed by %2 always fires no matter what. What I have tracked the problem using echos to send debug info to the console. Basically when trying to get the %sourceClient info the information returned is always null not as in "null" but nothing just blank.
Here is a snippet of my damage and onDamage functions from player.cs
function DefaultCar::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)
{
%amount = %amount+100;
%obj.applyDamage(%amount);
echo("Damage: "@%amount);
%damage = %obj.getDamageLevel();
%client = %obj.client;
%sourceClient = %sourceObject ? %sourceObject.client : 0;
echo(%sourceObject);
echo(%sourceClient);
if (%damage >= %data.destroyedLevel)
{
if(%obj.getDamageState() !$= "Destroyed")
%obj.setDamageState(Destroyed);
echo ("\n\n***************Player Died***********\n");
%client.onDeath(%sourceObject, %sourceClient, %damageType, %location);
}
else
{
if(%obj.getDamageState() !$= "Enabled")
%obj.setDamageState(Enabled);
}
}
function DefaultCar::onDamage(%data, %obj, %delta)
{
// Increment the flash based on the amount.
%flash = %obj.getDamageFlash() + ((%delta / %this.maxDamage) * 2);
if (%flash > 0.75)
%flash = 0.75;
%obj.setDamageFlash(%flash);
}And then the onDeath in game.cs
function GameConnection::onDeath(%this, %sourceObject, %sourceClient, %damageType, %damLoc)
{
// Clear out the name on the corpse
%this.player.setShapeName("");
// Switch the client over to the death cam and unhook the player object.
if (isObject(%this.camera) && isObject(%this.player)) {
%this.camera.setMode("Corpse",%this.player);
%this.setControlObject(%this.camera);
}
%this.player = 0;
// Doll out points and display an appropriate message
if (%damageType $= "Suicide" || %sourceClient == %this) {
%this.incScore(-1);
messageAll('MsgClientKilled','%1 takes his own life!',%this.name);
}
else {
%sourceClient.incScore(1);
messageAll('MsgClientKilled','%1 gets nailed by %2!',%this.name,%sourceClient.name);
if (%sourceClient.score >= $Game::EndGameScore)
cycleGame();
}
}So that is basically it if my player.cs is defining a character %sourceClient works but if it is a vehicle it returns no value. So any of the master coders out there have any ideas?
About the author
#2
11/17/2004 (9:17 pm)
When you spawn the vehicle set it's client.. like so:%player = new (WheeledVehicle)() {
dataBlock = DefaultCar;
client = %client;
};
MissionCleanup.add(%player);
%player.setShapeName(%client.name);
// etc..
#3
function DefaultCar::damage(%this, %obj, %sourceObject, %position, %damage, %damageTy
pe)
{
%sourceClient = %sourceObject.sourceObject;
Try that and see what happens
11/17/2004 (9:25 pm)
I think what you may be looking for is....function DefaultCar::damage(%this, %obj, %sourceObject, %position, %damage, %damageTy
pe)
{
%sourceClient = %sourceObject.sourceObject;
Try that and see what happens
#4
@Zod - I was already declaring the client in the spawn code but I changed it a little bit now after looking at your's. Now its not quite what I had before or quite what you posted but I know from echos that it works properly.
@Gonzo - That has helped me quite a bit I think you actually meant %sourceClient = %sourceObject.sourceClient; but from tinkering with that I have been able to get the source client some of the time I just don't know yet quite why it doesn't work all of the time, oh well I guess that means just more testing. This is what I ended up using and I think it has something to do with how labrat setup his weapons on the vehicles but, I'm not certian.
Thank you both again in working on this project I have read several helpful posts by both of you that have allowed me to get thusfar.
11/18/2004 (5:18 am)
Well thank you both, you have given me something to start on.@Zod - I was already declaring the client in the spawn code but I changed it a little bit now after looking at your's. Now its not quite what I had before or quite what you posted but I know from echos that it works properly.
@Gonzo - That has helped me quite a bit I think you actually meant %sourceClient = %sourceObject.sourceClient; but from tinkering with that I have been able to get the source client some of the time I just don't know yet quite why it doesn't work all of the time, oh well I guess that means just more testing. This is what I ended up using and I think it has something to do with how labrat setup his weapons on the vehicles but, I'm not certian.
%sourceClient = %sourceObject.sourceObject.client;
Thank you both again in working on this project I have read several helpful posts by both of you that have allowed me to get thusfar.
#5
Then in your scoring, check for zero, if it is, don't award points.
11/18/2004 (11:41 am)
Well, you should check for a source object..%sourceClient = isObject(%sourceObject) ? %sourceObject.client : 0;
Then in your scoring, check for zero, if it is, don't award points.
function GameConnection::onDeath(%this, %sourceObject, %sourceClient, %damageType, %damLoc)
{
// Clear out the name on the corpse
%this.player.setShapeName("");
// Switch the client over to the death cam and unhook the player object.
if (isObject(%this.camera) && isObject(%this.player))
{
%this.camera.setMode("Corpse",%this.player);
%this.setControlObject(%this.camera);
}
%this.player = 0;
// Doll out points and display an appropriate message
if (%damageType $= "Suicide" || %sourceClient == %this)
{
%this.incScore(-1);
messageAll(´MsgClientKilled´,´%1 takes his own life!´,%this.name);
}
else
{
if(%sourceClient != 0)
{
%sourceClient.incScore(1);
messageAll(´MsgClientKilled´,´%1 gets nailed by %2!´,%this.name,%sourceClient.name);
if (%sourceClient.score >= $Game::EndGameScore)
cycleGame();
}
}
}
Torque Owner Arland (Barry) Woodham