Game Development Community

Scoring problem?

by Graham Mcrobbie · in Torque Game Engine · 02/03/2006 (8:02 am) · 2 replies

I'm working with a modified version of the FPS starter kit (I'm using the wheeled flying vehicle resource with a weapon mounted to it). It's all going ok, except that my scoring system isn't working properly, I've tried various fixes which other people seem to have used but have had no success with them.

The problem is that it always displays "player1 gets nailed by !", with no other player name, and this happens even if player1 commits suicide. The error in the log file is -
"game.cs (280): Unable to find object: '0' attempting to call function 'incScore'"
Code for the on death function in game.cs looks like this -
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();
   }
}

And the code for the damage functions -
function WheeledFlyingVehicleData::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)
{
	%sourceClient = isObject(%sourceObject) ? %sourceObject.client : 0;

   if (%obj.getDamageState() $= "Destroyed")
      return;

   %obj.applyDamage(%damage);
   %location = "Body";

   // 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;

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

function WheeledFlyingVehicleData::onDamage(%this, %obj, %delta)
{
  %damage = %obj.getDamageLevel();

   if (%damage >= %this.destroyedLevel)
   {
      if(%obj.getDamageState() !$= "Destroyed")
      {
         %obj.setDamageState(Destroyed);
      }
   }
   else
   {
      if(%obj.getDamageState() !$= "Enabled")
         %obj.setDamageState(Enabled);
   }
}

Perhaps somebody more knowledgeable than myself can help out? It's driving me nuts!

About the author

Recent Threads


#1
02/12/2006 (5:29 pm)
This thread in the public mod forum might help. I haven't implemented it myself, but the explanation of retrieving the vehicle's client to determine the damage sourceObject seems pretty logical.

www.garagegames.com/mg/forums/result.thread.php?qt=23131
#2
02/20/2006 (1:22 pm)
Yeah I checked that out earlier but it didn't seem to solve my problems, thanks for the reply anyway!