Game Development Community

Kill the %client object...

by Kirby Webber · in Torque Game Engine · 12/30/2005 (9:34 am) · 2 replies

Caveat:

I'm working exclusively with a heavily modifiecd (source and scripts) version of the racing starter kit.

==============================

I've been working on weapons and damage lately, and thought I'd begin by handling simple impact and collision damage.

To that end, I have defined several script funcitons to handle damage and death.

Additionally, I copied the GameConnection::onDeath() function from starter.fps (server/scripts/game.cs) into my game.cs (the server side (C;) to handle client death.

Here are the function definitions:

HoverVehicleData::onImpact()
function HoverVehicleData::onImpact(%this, %obj, %collidedObject, %vec, %vecLen)
{
   %obj.damage(%obj, VectorAdd(%obj.getPosition(),%vec),
                  %vecLen * %this.speedDamageScale, "Impact");
}

Deals with terrain/ interior collisions - seems to work flawlessly.


HoverVehicleData::damage()
function HoverVehicleData::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)
{
   %obj.applyDamage(%damage);

   // 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;
   echo("SourceObject: "@%sourceObject);

   //if player is dead, kill him!
   if (%obj.getDamageLevel() $= %this.maxDamage)
      %obj.setDamageState(Destroyed);

   
   if (%obj.getDamageState() $= "Destroyed")
   {
      %obj.setImageTrigger(0, false);
      %client.onDeath(%sourceObject, %sourceClient, %damageType, %location);
   }
}

Damage applies to the object appropriately and (since it's "forced to", it changes the object state to "Destroyed". After that, it calls the OnDeath() function in game.cs (definition below), but generates this error in the console:

base.AB/server/scripts/game.cs (374): Unable to find object: '' attempting to call function 'setShapeName'

Now, for the coup de grace:

GameConnection::onDeath
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;

   // Assign points and display an appropriate message
   if (%damageType $= "Suicide" || %sourceClient == %this) {
      %this.incScore(-1);
      messageAll('MsgClientKilled','%1 takes his own life!',%this.name);
   }
   else {
      // Here we are seperating deaths by another player from deaths by ineptitude
      // and insulting the dead player appropriately
      if (%sourceClient.name == "") {
         messageAll('MsgClientKilled','%1 needs training wheels...',%this.name,%sourceClient.name);
         messageAll('MsgClientKilled','...or an ambulance...',%this.name,%sourceClient.name);
         messageAll('MsgClientKilled','...or maybe a hearse.',%this.name,%sourceClient.name);
      }
      else
         messageAll('MsgClientKilled','%1 gets nailed by %2!',%this.name,%sourceClient.name);
         
      if (%sourceClient.score >= $Game::EndGameScore)
         cycleGame();
   }
}

Now, I echoed the %sourceObject in HoverVehicleData::damage() to make sure the right object ID was populating the variable, which it is (in this case it's 1495), but when %this.player.setShapeName(""); gets called, it seems to be a null value.

Any and all advice and help is appreciated. I WILL get this d@mn namespace/ value passing thing down... even if it kills me. =\

#1
12/30/2005 (10:27 am)
Nevermind...

I got it.

[edit]

For posterity, I'll post my fix:

Since I'm using the racing mod as a base, and it used %this.car to instantiate vehicles (a variable I changed as I moded the scripts) I was calling for the wrong object type, i.e. %this.player... should have been %this.bike (my own variable name.

Funny when you bite your own self in the butt eh? =)
#2
12/31/2005 (6:54 pm)
Awesome, glad you got it fixed!