Please help a newbie - *hopefully* a basic scripting question
by gamer_goof · in Torque Game Engine · 12/20/2007 (7:41 pm) · 3 replies
Hey all, I am a newbie to c and torque scripting and have been trying to
make a modification to the starter.fps for a few days now and cant figure it out.
I have been looking through as many scripts and documentation as I can and it quickly goes over
my head in most cases. Please help!
Here is what I want to do.
In the starter.fps you can log in and so can others. stating the obvious if you shoot another person who is logged in and kill them you get a point added to your score, and vice versa. (you can then see the score displayed when you hit f2 in the score board)
Also in the map is a little bot named kork who runs around and thats all he seems to do...
which is fine...
SO what I want to make happen is, when any player shoots kork and kills him
a point gets added to their player score, just as if they had shot a live player.
After some searching I finally found the block of code in the
D:\example\game\server\scripts\game.cs file that is responsible for adding
a point to someones score when they shoot another live player.
//-----------------------------------------------------------------------------
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();
}
}
//-----------------------------------------------------------------------------
I have tried adding this block of code to the D:\example\game\server\scripts\aiPlayer.cs
hoping I could modify the function GameConnection::onDeath
to function DemoPlayer::onDeath and tons of other combos that are abviously wrong...
but I am way too lost to guess further how to modify this,
I was wondering if someone out there knew a way to add a value in here for the kork bot
to add to the player score when it is destroyed?
Any help would be greatly appreciated.
make a modification to the starter.fps for a few days now and cant figure it out.
I have been looking through as many scripts and documentation as I can and it quickly goes over
my head in most cases. Please help!
Here is what I want to do.
In the starter.fps you can log in and so can others. stating the obvious if you shoot another person who is logged in and kill them you get a point added to your score, and vice versa. (you can then see the score displayed when you hit f2 in the score board)
Also in the map is a little bot named kork who runs around and thats all he seems to do...
which is fine...
SO what I want to make happen is, when any player shoots kork and kills him
a point gets added to their player score, just as if they had shot a live player.
After some searching I finally found the block of code in the
D:\example\game\server\scripts\game.cs file that is responsible for adding
a point to someones score when they shoot another live player.
//-----------------------------------------------------------------------------
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();
}
}
//-----------------------------------------------------------------------------
I have tried adding this block of code to the D:\example\game\server\scripts\aiPlayer.cs
hoping I could modify the function GameConnection::onDeath
to function DemoPlayer::onDeath and tons of other combos that are abviously wrong...
but I am way too lost to guess further how to modify this,
I was wondering if someone out there knew a way to add a value in here for the kork bot
to add to the player score when it is destroyed?
Any help would be greatly appreciated.
About the author
#2
function Armor::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)
{
if (%obj.getState() $= "Dead")
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.getState() $= "Dead"){
if (%sourceObject.client $= "")
%obj.client.deaths++;
if (!%obj.client){
%sourceClient = %sourceObject.client;
%sourceClient.incScore(1);
%sourceClient.kills++;
if (%sourceClient.score >= $Game::EndGameScore){
$Server::Roundwinner = %sourceClient.name;
tallyScores();
if ($AllTimeTeamDM)
updateClanWin("",%sourceClient.team);
%rawName = stripChars( detag( getTaggedString( %sourceClient.name ) ), "\cp\co\c6\c7\c8\c9" );
centerPrintAll(%rawName @ " Wins The Game!!!",2,2);
messageAll('MsgClientKilled','%1 pwns %2 for the win!',%sourceClient.name,%obj.getShapeName());
%messaged=1;
}
}
%client.onDeath(%sourceObject, %sourceClient, %damageType, %location);
}
}
And in game.cs this
function GameConnection::onDeath(%this, %sourceObject, %sourceClient, %damageType, %damLoc)
{
%this.active = 0;
%this.key[1] = 0;
%this.key[2] = 0;
//%this.spawntimer = schedule(35000, 0, "SetSpawnToZero",%this);
%royalSpanking = 0;
//before clearing the name on the corpse, check to see if the dude has the flag
if (%this.name $= $LastonewithFlag)
{
// keep track of who the flag snatcher is
if (%this.name $= $SmackerBacker && %sourceObject.name $= $GuywhowantsRevenge)
%royalSpanking = 1;
$SmackerBacker = "";
$GuywhowantsRevenge = %this.name;
}
// 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",%sourceClient.player);
%this.setControlObject(%this.camera);
}
//%this.player = 0;
// Doll out points and display an appropriate message
if (%damageType $= "Suicide" || %sourceClient == %this)
{
if ($Game::EndGameTimer == 0)
%this.incScore(-1);
// spawn behind first if a race
if ($GameType $= "FlagRace")
GetCheckpoint(%this);
%this.deaths++;
messageAll('MsgClientKilled','%1 spontaneously combusts!',%this.name);
}
else if (%sourceClient.name !$= "")
{
%messaged = 0;
%sourceClient.player.setDamageLevel(0);
if ($Game::EndGameTimer == 0)
{
// dish out spankings
if ($SpankinGiver $= %sourceClient.name){
if ($CryinName $= %this.name){
$CryinCounter++;
if ($CryinCounter >= 4){ // like this will ever get called, we'll see
messageAll('MsgGame','%1 Hammers on %2 Time for revenge!',%sourceClient.name,%this.name);
%messaged= 1;
}
}
else{ $CryinName = %this.name; }
}
else
{
$SpankinGiver = %sourceClient.name;
$CryinName = %this.name;
$CryinCounter = 1;
}
if ($TeamDM == 1){
if (%sourceClient.team2 != %this.team2)
{
%sourceClient.incScore(1);
%sourceClient.kills++;
%this.deaths++;
}
else
{
%sourceClient.sameteamkills++;
messageAll('MsgClientKilled','%1 pwns %2!',%SourceClient.name,%this.name);
if (%sourceClient.sameteamkills > 2)
{
%spawngroup = GetSpawnCount(%this.team);
if ($Game::TeamSpawn[%this.team,%spawngroup] $= "Jail")
{
%this.injailtrigger = 1;
%this.spawngroup=%spawngroup;
messageAll('MsgClientKilled','%1 gets thrown in the slammer!',%this.name);
}
}
%messaged = 1;
}
}
else
{
%sourceClient.incScore(1);
%sourceClient.kills++;
%this.deaths++;
}
}
// messageAll extreme kill!!!! hahahahahhahaha Its time for a spanking!!!
if (%sourceClient.score > $Game::MostPoints){
$Game::MostPoints = %sourceClient.score;
$Game::MostPointsPlayer = %sourceClient.name;
if (%sourceClient.name !$= $Game::MostPointsPlayer){
messageAll('MsgClientKilled','%1 spanks %2 for the lead!',%sourceClient.name,%this.name);
%messaged=1;
}
}
else
{
if (%royalSpanking){
messageAll('MsgClientKilled','%1 royally spanks %2!',%sourceClient.name,%this.name);
%messaged=1;
}
}
if (%sourceClient.score >= $Game::EndGameScore)
{
$Server::Roundwinner = %sourceClient.name;
if ($TeamDM){
checkwinner(%sourceClient, 1);
%messaged=1;
}
else{
tallyScores();
if ($AllTimeTeamDM)
updateClanWin("",%sourceClient.team);
%rawName = stripChars( detag( getTaggedString( %sourceClient.name ) ), "\cp\co\c6\c7\c8\c9" );
centerPrintAll(%rawName @ " Wins The Game!!!",2,2);
messageAll('MsgClientKilled','%1 pwns %2 for the win!',%sourceClient.name,%this.name);
%messaged=1;
}
}
if (%messaged == 0){
messageAll('MsgClientKilled','%2 pwns %1 with a %3!',%this.name,%sourceClient.name, %damageType);
if (%sourceClient.score >= $Game::EndGameScore - 6){
if (%sourceClient.score+3 >= $Game::MostPoints){
if(%sourceClient.name !$= $Game::MostPointsPlayer){
if (%sourceClient.score == $Game::EndGameScore - 2)
messageAll('MsgGame','ITS DOWN TO THE WIRE!!!');
else
messageAll('MsgGame','Its a close game!!!');
}
}
}
}
}
//else updateGod();
}
//thats mine anyway
12/20/2007 (9:45 pm)
Change your player.cs function Armor::damage(%this, %obj, %sourceObject, %position, %damage, %damageType) to thisfunction Armor::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)
{
if (%obj.getState() $= "Dead")
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.getState() $= "Dead"){
if (%sourceObject.client $= "")
%obj.client.deaths++;
if (!%obj.client){
%sourceClient = %sourceObject.client;
%sourceClient.incScore(1);
%sourceClient.kills++;
if (%sourceClient.score >= $Game::EndGameScore){
$Server::Roundwinner = %sourceClient.name;
tallyScores();
if ($AllTimeTeamDM)
updateClanWin("",%sourceClient.team);
%rawName = stripChars( detag( getTaggedString( %sourceClient.name ) ), "\cp\co\c6\c7\c8\c9" );
centerPrintAll(%rawName @ " Wins The Game!!!",2,2);
messageAll('MsgClientKilled','%1 pwns %2 for the win!',%sourceClient.name,%obj.getShapeName());
%messaged=1;
}
}
%client.onDeath(%sourceObject, %sourceClient, %damageType, %location);
}
}
And in game.cs this
function GameConnection::onDeath(%this, %sourceObject, %sourceClient, %damageType, %damLoc)
{
%this.active = 0;
%this.key[1] = 0;
%this.key[2] = 0;
//%this.spawntimer = schedule(35000, 0, "SetSpawnToZero",%this);
%royalSpanking = 0;
//before clearing the name on the corpse, check to see if the dude has the flag
if (%this.name $= $LastonewithFlag)
{
// keep track of who the flag snatcher is
if (%this.name $= $SmackerBacker && %sourceObject.name $= $GuywhowantsRevenge)
%royalSpanking = 1;
$SmackerBacker = "";
$GuywhowantsRevenge = %this.name;
}
// 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",%sourceClient.player);
%this.setControlObject(%this.camera);
}
//%this.player = 0;
// Doll out points and display an appropriate message
if (%damageType $= "Suicide" || %sourceClient == %this)
{
if ($Game::EndGameTimer == 0)
%this.incScore(-1);
// spawn behind first if a race
if ($GameType $= "FlagRace")
GetCheckpoint(%this);
%this.deaths++;
messageAll('MsgClientKilled','%1 spontaneously combusts!',%this.name);
}
else if (%sourceClient.name !$= "")
{
%messaged = 0;
%sourceClient.player.setDamageLevel(0);
if ($Game::EndGameTimer == 0)
{
// dish out spankings
if ($SpankinGiver $= %sourceClient.name){
if ($CryinName $= %this.name){
$CryinCounter++;
if ($CryinCounter >= 4){ // like this will ever get called, we'll see
messageAll('MsgGame','%1 Hammers on %2 Time for revenge!',%sourceClient.name,%this.name);
%messaged= 1;
}
}
else{ $CryinName = %this.name; }
}
else
{
$SpankinGiver = %sourceClient.name;
$CryinName = %this.name;
$CryinCounter = 1;
}
if ($TeamDM == 1){
if (%sourceClient.team2 != %this.team2)
{
%sourceClient.incScore(1);
%sourceClient.kills++;
%this.deaths++;
}
else
{
%sourceClient.sameteamkills++;
messageAll('MsgClientKilled','%1 pwns %2!',%SourceClient.name,%this.name);
if (%sourceClient.sameteamkills > 2)
{
%spawngroup = GetSpawnCount(%this.team);
if ($Game::TeamSpawn[%this.team,%spawngroup] $= "Jail")
{
%this.injailtrigger = 1;
%this.spawngroup=%spawngroup;
messageAll('MsgClientKilled','%1 gets thrown in the slammer!',%this.name);
}
}
%messaged = 1;
}
}
else
{
%sourceClient.incScore(1);
%sourceClient.kills++;
%this.deaths++;
}
}
// messageAll extreme kill!!!! hahahahahhahaha Its time for a spanking!!!
if (%sourceClient.score > $Game::MostPoints){
$Game::MostPoints = %sourceClient.score;
$Game::MostPointsPlayer = %sourceClient.name;
if (%sourceClient.name !$= $Game::MostPointsPlayer){
messageAll('MsgClientKilled','%1 spanks %2 for the lead!',%sourceClient.name,%this.name);
%messaged=1;
}
}
else
{
if (%royalSpanking){
messageAll('MsgClientKilled','%1 royally spanks %2!',%sourceClient.name,%this.name);
%messaged=1;
}
}
if (%sourceClient.score >= $Game::EndGameScore)
{
$Server::Roundwinner = %sourceClient.name;
if ($TeamDM){
checkwinner(%sourceClient, 1);
%messaged=1;
}
else{
tallyScores();
if ($AllTimeTeamDM)
updateClanWin("",%sourceClient.team);
%rawName = stripChars( detag( getTaggedString( %sourceClient.name ) ), "\cp\co\c6\c7\c8\c9" );
centerPrintAll(%rawName @ " Wins The Game!!!",2,2);
messageAll('MsgClientKilled','%1 pwns %2 for the win!',%sourceClient.name,%this.name);
%messaged=1;
}
}
if (%messaged == 0){
messageAll('MsgClientKilled','%2 pwns %1 with a %3!',%this.name,%sourceClient.name, %damageType);
if (%sourceClient.score >= $Game::EndGameScore - 6){
if (%sourceClient.score+3 >= $Game::MostPoints){
if(%sourceClient.name !$= $Game::MostPointsPlayer){
if (%sourceClient.score == $Game::EndGameScore - 2)
messageAll('MsgGame','ITS DOWN TO THE WIRE!!!');
else
messageAll('MsgGame','Its a close game!!!');
}
}
}
}
}
//else updateGod();
}
//thats mine anyway
#3
Thanks you so much!!!! This works perfect!!
Merry Christmas :)
12/21/2007 (9:36 am)
Holy crap you are like santa clause! Thanks you so much!!!! This works perfect!!
Merry Christmas :)
Associate William Lee Sims
Machine Code Games
In player.cs (I hope) is a function that applies damage. It's probably here that will tell you when Kork dies (or any player dies). You might need to move the scoring to here.
If I get a chance before I head out of town, I'll do a quick check, but it's a place to start in the meantime.