Torque Scripting Language Snippets

mewstennisSoftware and s/w Development

Nov 4, 2013 (3 years and 8 months ago)

58 views

Torque Scripting Language Snippets


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
.setControlObject(%
this
.camera);



//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


schedule(9000, 0, delaySpawn, %
this
, %
this
.player);


}


%
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);



if
($Pref::Player::t
eamName $=
"Team1"
){




$team1Score
--
;




error(
"Team 1 score decreased."
);



}



else

if
($Pref::Player::teamName $=
"Team2"
){




$team2Score
--
;




error(
"Team 2 score decreased."
);



}


}


else

{


%sourceClient.incScore(1);


messageAll(
'MsgClientKilled'
,
'%1 was killed by
%2!'
,%
this
.name,%sourceClient.name);


if

(%sourceClient.score >= $Game::EndGameScore)


cycleGame();



if
($Pref::Player::teamName $=
"Team1"
){




$team2Score += 2;





error(
"Team 2 score
increased."
);



}



else

if
($Pref::Player::teamName $=
"Team2"
){




$team1Score += 2;




error(
"Team 1 score increased."
);



}


}




error(
"$Pref::Player::teamName is: "
@$Pref::Player::teamName);


error(
"OnDeath, %this is: "
@%
this
);

}


datablock TriggerData(JumpPad){


tickPeriodMS = 100;

};

function JumpPad::OnEnterTrigger(%
this
, %trigger, %obj){




error(
"Jumping."
);


findJumpPad(%trigger, %obj);

}

function findJumpPad(%trigger, %obj){




%target = MissionObjects.getObject(0);




for
(%i

= 1; %i < MissionGroup.getCount(); %i ++){




%missionObj = MissionGroup.getObject(%i);




if
(%missionObj.getClassName() $= Trigger &&
%missionObj.getName() !$= %trigger.getName()){





if
(%missionObj.getName() $= %trigger.destination){






%foundPad = %
missionObj;






%i = MissionGroup.getCount();





}




}


}




%destination = %foundpad.getTransform();




%centerx = getWord(%destination, 0);


%centery = getWord(%destination, 1);




%centerx += getWord(%foundPad.getScale(), 0)/2;


%centery
-
=
getWord(%foundPad.getScale(), 1)/2;




%desz = getWord(%destination, 2);


%desq = getWords(%destination, 3);




%randomNum = getRandom(0, 3);




error(%randomNum
@" is the random number"
);




if
(%randomNum == 0){



%centery += (getWord(%foundPad.getScale(),

1)/2) + 3;


}
else

if
(%randomNum == 1){



%centery
-
= (getWord(%foundPad.getScale(), 1)/2) + 3;


}
else

if
(%randomNum == 2){



%centerx += (getWord(%foundPad.getScale(), 0)/2) + 3;


}
else

if
(%randomNum == 3){



%centerx
-
= (getWord(%foundPad.getScale(), 0)/
2) + 3;


}




%obj.setTransform(%centerx
@" "
@%centery
@" "
@getTerrainHeight(%centerx
@"
"
@%centery)
@" "
@%desq);

}