Score Keeping
by BroZebub · in Torque Game Engine · 04/17/2005 (1:21 pm) · 4 replies
I'm developing a single player fps game. I want to have scoring that keeps track of deaths and kills. I tried utilizing the following code from Kenneth Finney's 3DGPAi1:
However; no matter how many bots I kill it never records them as kills and after the first player death it won't update the score and recycle the game if if max game points is set for more than one death. Has anyone else had this problem with this code and solved it, or has anyone developed their own code that actually does keep score? Your help will be greatly appreciated.
function GameConnection::DoScore(%client)
{
%client.score =
(%client.deaths * $Game::Deaths_Multiplier) +
(%client.kills * $Game::Kills_Multiplier) ;
%scoreString = %client.score @
" D:" @ %client.deaths @
" K:" @ %client.kills;
echo("Score" @%scoreString);
commandToClient(%client, 'UpdateScore', %scoreString);
if (%client.score >= $Game::MaxPoints)
{
cycleGame();
}
}
function GameConnection::incScore(%this,%delta)
{
%this.score += %delta;
}
function GameConnection::onDeath(%this, %sourceObject, %sourceClient, %damageType, %damLoc)
{
%this.player.setShapeName("");
if (IsObject(%this.camera) && IsObject(%this.player))
{
%this.camera.setMode("Death", %this.player);
%this.setControlObject(%this.camera);
}
%this.player = 0;
%this.deaths++;
%this.DoScore();
%sourceClient = %sourceObject ? %sourceObject.client : 0;
if (%obj.getState() $= "Dead")
{
if (IsObject(%sourceClient))
{
%sourceClient.incScore(1);
if (IsObject(%client))
{
%client.onDeath(%sourceObject, %sourceClient, %damageType, %location);
}
}
}
}However; no matter how many bots I kill it never records them as kills and after the first player death it won't update the score and recycle the game if if max game points is set for more than one death. Has anyone else had this problem with this code and solved it, or has anyone developed their own code that actually does keep score? Your help will be greatly appreciated.
#2
For those interested , I've solved my scoring problem. I couldn't make Finney's code work, so I started with a clean slate and wrote my own. It is very specific for my particular application, non-multiplayer and non-network, so it probably won't work on the majority of games out there.
To keep score of Player deaths I inserted this code into the server.cs file:
I then called the Dead() function in the player.cs file from the HumanMaleAvatar::onDisabled(%this,%obj,%state) function
To score Player kills I inserted this code into the ai.cs file:
I then called the Killed() function from the onDisabled function in each of my AIPlayer files.
The last thing I did was to use the Gui Editor to modify the player interface. I added another scorebox to correspond to kills and appropriately reworded their titles.
05/03/2005 (11:17 am)
Seems like every problem I solve two new ones pop up! However, Trevor, I haven't had anything resembling like what you mentioned.For those interested , I've solved my scoring problem. I couldn't make Finney's code work, so I started with a clean slate and wrote my own. It is very specific for my particular application, non-multiplayer and non-network, so it probably won't work on the majority of games out there.
To keep score of Player deaths I inserted this code into the server.cs file:
$scorePlayer = %deaths; //Set score string equall to number of deaths
function IncreaseScore()
{
%value = GetWord($scorePlayer, 0); //Obtain value of deaths in score string
Scorebox.SetValue(%value+=1); //Increment number of deaths and set it on scoreboard
$scorePlayer++; //Increment score string value
if (%value >= $Game::MaxPoints) //Cycle game if preset value is reached...
{
cycleGame();
Scorebox.SetValue($scorePlayer-=%value); //...and reset scoreboard to 0
}
}
function Dead()
{
%this.deaths++;
IncreaseScore();
}I then called the Dead() function in the player.cs file from the HumanMaleAvatar::onDisabled(%this,%obj,%state) function
To score Player kills I inserted this code into the ai.cs file:
$scoreAIPlayer = %deaths; //Set score string equall to number of deaths
function UpdateScore()
{
%value = GetWord($scoreAIPlayer, 0); //Obtain value of deaths in score string
Scorebox2.SetValue(%value+=1); //Increment number of deaths and set it on scoreboard
$scoreAIPlayer++; //Increment score string value
if (%value >= $Game::MaxKills) //Cycle game if preset value is reached...
{
cycleGame();
Scorebox2.SetValue($scoreAIPlayer-=%value); //...and reset scoreboard to 0
}
}
function Killed()
{
%this.deaths++;
UpdateScore();
}I then called the Killed() function from the onDisabled function in each of my AIPlayer files.
The last thing I did was to use the Gui Editor to modify the player interface. I added another scorebox to correspond to kills and appropriately reworded their titles.
#3
05/03/2005 (8:55 pm)
Everything that happens in a function happens in an instant. So making two calls to the same function will result in the product of the second call. Also, when setting the score back to Zero, set it back to ZERO. Do not use any other method. To do so is just asking for trouble. Also, since there is only one word in your string to get, you don't need to get the word at all, just use it. To clean your functionality up a little, might I suggest...function UpdateScore()
{
// Increase the AI score by one
$scoreAIPlayer++;
// Check for winner, end match if neccesary
if($scoreAIPlayer >= $Game::MaxKills)
{
// Zero the scores
$scorePlayer = 0;
$scoreAIPlayer = 0;
// Cycle the game
cycleGame();
}
// Update the scorebox
Scorebox2.setValue($scoreAIPlayer);
}
#4
05/04/2005 (8:37 am)
Thanks for the advice Gonzo.
Trevor Gall