Вы находитесь на странице: 1из 261

Pre-Class

Letter to Educators
Letter to Educators:

The First Person Shooter(FPS) Tutorial and the Torque 3D game


engine version 1.2 were designed from the ground up to
facilitate a better introduction to 3D game development.
The Torque 3D Educational Materials have been developed by
former game program educators and game developers to
facilitate the teaching of high school and college introductory
design, programming, and game development courses.
For over 10 years, we at GarageGames have helped others
make games. We also hope to help educators teach game
development.
Pre-Class

Letter to Educators
To provide feedback on the educational materials, contact
Dexter Chow at dexterchow@garagegames.com or post at
http://www.garagegames.com/community/forums/34. Dexter
Chow is the lead writer and is a former game design instructor
at the Art Institute. He is currently on the advisory committees
of the Art Institute and International Academy of Design and
Technology.
All documentation and educational materials associated with
Torque 3D 1.2 are free to use, modify, and distribute. Educators
are encouraged to use these educational materials for their
own classes.

GarageGames Documentation Team


Pre-Class

Information and Licensing of


Torque 3D for Education
For support and more information:
Education Website: http://www.garagegames.com/education
Education Forums:
http://www.garagegames.com/community/forums/34

For lab packs, full version instructor licenses, or bulk purchases,


please contact:
Email: education@garagegames.com
Phone: 702-727-1915
Pre-Class

GarageGames Associates
Become a GarageGames Associate if youre an educator who
wants to:
Assist in the development of curriculum materials.
Get an advanced peek at upcoming education initiatives.
Help steer future game pedagogies and curricula.

To become a GarageGames Associate, please contact Dexter


Chow at dexterchow@garagegames.com
Pre-Class

Setup and Class Preparation:


Registration
All students and instructors can register on
GarageGames.com to obtain access to demos and forums.
Registration is free.
Pre-Class

Setup and Class Preparation:


Downloads
Download Torque 3D 1.2
Download Torsion
Download Direct X 9c
Pre-Class

Setup and Class Preparation:


Resources
There are several social sites to which you can direct students
for more information about Torque technology including :
YouTube (http://www.youtube.com/garagegames)
Vimeo (http://vimeo.com/31815313)
Twitter (https://twitter.com/#!/garagegames)
Facebook (http://www.facebook.com/GarageGames)
The GarageGames community site
(http://www.garagegames.com/community/resources)

You can also direct students to search on the internet for third-
party tutorials and videos about Torque products.
Class 1
Class 1

Introduction to Game
Development: Lecture
1. Introduction to the Course
Teacher and class overview
Class administration
Syllabus review
Teacher and student introductions
What are class expectations?

2. What Will be Taught in this Class?


Moving around in a 3D environment
How to change and add objects
How to change behavior
What is scripting?
Programming terminology
Whats involved in making a multiplayer game
How to create a fun game!
Class 1

Introduction to Game
Development: Lecture
3. How will students be graded?
Midterm and Final Tests 25%
Homework and Quizzes 25%
Labs and Final Project 25%
Participation and Presentations 25%

4. What to Expect on the Midterm?

5. What to Expect on the Final?

6. How is the Final Project and Presentation Graded?

7. Introduction to Torque 3D (demonstration)


Class 1

Class Materials:
What is This Class About?
Game Design Level Design
Class 1

Class Materials:
What is This Class About?
Art Scripting and Programming
Class 1

Class Materials:
Introduction Torque 3D
Class 1

Introduction to Game
Development: Conclusion
1. Lab:
Do a one-page description of a favorite game and a
memorable moment in that game

2. Presentation:
Take 5 minutes to describe your game and memorable
moment
Tell the class what you want to accomplish in taking
this class and in future game classes

3. Homework:
Read Lesson 1 and review class materials including
the Class Syllabus
Class 2
Class 2

3D Technology and Building a


Game World: Lecture
1. Play the Torque 3D Demos
2. What Does a Game Development Team Look Like?
Various Size Teams
Types of Jobs
Programmers
Artists
Designers
Managers
3. What is a 3D World?
Introduce class to Torque 3D and the World Editor
Cover basic terminology
Class 2

Class Materials:
Jobs in the Games Industry
Programming and Art
Class 2

Class Materials:
Jobs in the Games Industry
Design
Class 2

Class Materials:
Game and Level Design
Class 2

World Editor: Modifying a


Game in a 3D World
Class 2

World Editor: Camera Control


and Viewpoints
Class 2

World Editor: Camera Control


and Viewpoints Continued
Class 2

World Editor: Changing


Properties of Objects
Class 2

Class Materials:
3D Technology Resources
Class 2

3D Technology and Building a


Game World: Conclusion
1. Lab: Host 1-4 multiplayer Deathmatch games.
Have fun playing and fragging your teammates

2. Presentation: Take 5 minutes to describe what


part of game development you want to learn the
most about and describe in more detail what you
want to do in game development

3. Quiz: Lesson 1

4. Homework: Read Lesson 2 and review examples


Class 3
Class 3

Developing an FPS in a 3D
World: Lecture
1. Basics of World Building in 3D
Cover Terminology while pointing out features of
the editor including scripting, datablocks, spawn
points, geometry and materials
Show characters and talk about collision, animation
and the differences between properties and
datablocks
Show weapon fire and weapon changes, describe
the concept of properties attached to objects
Class 3

Create Your Own Project


Class 3

Start the Chinatown Day


Level
Class 3

Camera Features
Changing Views 1st and 3rd Free and Orbit
Class 3

Object Editor: Search for and


Select Objects
Object Editor Inspector Scene Tree
Class 3

Object Editor: Selecting


Objects
Class 3

Top Down View of Chinatown


Class 3

Find and Select Objects


Scene Tab: Building_38 Inspector: Building_38
Class 3

Editor Control: Move and


Resize Windows
Class 3

Defensive Cover
Class 3

Choke Point
Class 3

Sniper Point
Class 3

Practical Exercise: Dumpster


Placement for Cover
Class 3

Consider AI Turret Line of


Sight
Class 3

Add Dumpster
Class 3

Placement: Snap to Grid


Class 3

Placement: Resize and Rotate


Class 3

Test Your Placement


Class 3

Developing an FPS in a 3D
World: Conclusion
1. Lab:
Create a checklist of items for the team to complete the
examples in the lab
Lab work will be verified. For example, the dumpster
must been added on each students computer

2. Quiz: Lesson 2

3. Homework: Read Lesson 4 and review examples


Class 4
Class 4

Adding and Customizing


Players: Lecture
1. Viewing, manipulating and adding to a level
Camera control in a 3D editor
Character structure and customizing
Object editor to look and modify the current level
Spawn points; Understanding and adding a spawn point
Introduce the Torque 3D Script Manual
Objects and properties
Datablock Library and Datablock panel
ShapeEditor, material changes and importation of
graphics, diffuse, normal and specular materials
Create a new character with a new model
Add animations to the new model
Give your new model a weapon
Class 4

Game vs. Editor Mode


Game Mode World Editor Mode
Class 4

Detailed Character and Level


Viewing
Class 4

Spawn Points - SpawnSphere


Class 4

Documentation: Keyword
Search
Class 4

Datablock Editor

Copy Existing
Data and Set
Data
Properties
Class 4

Shape Editor

Modify Your
Character Model
and Set Nodes
Class 4

Character Spawn Process


Class 4

Change Model Materials


Class 4

Diffuse, Normal, and Specular


Maps
Class 4

Changing Models
Gideon Changing Materials
Class 4

Adding a New Character


in the Scene
Class 4

Add a New Weapon


in the Scene
Class 4

Adding and Customizing


Players: Conclusion
1. Lab:
Step through the lesson exercises to create a customized
character of the students choice
Have a volunteer package their game for a class deathmatch

2. Presentation: Have each team show off their own


characters, even if it was a simple texture change
Take 5 minutes to have each team member describe what part
of game development interests them and what they want to
accomplish

Quiz: Lesson 4

Homework: Study for the midterm test, which covers


Lesson 1, Lesson 2, and Lesson 4
Class 5
Class 5

Midterm
1. Lecture (part 1): Recap the first half of the course

2. Midterm: Test covers Lessons 1,2, and 4

3. Lecture (part 2): Primer on Scripting

4. Lab: Start early on Lesson 3 to allow questions to be


asked in a group setting

5. Homework: Read Lesson 3 (up to step 16 in the second


exercise) and review examples
Class 6
Class 6

Introduction to Scripting Part


1:
Lecture
1. What are Scripts?
What gets controlled in the world?
What is TorqueScript?
Level Files
Static Mesh
Game Play
Breakpoints
Function
Concatenating
Variables: Global ($), Local (%)
Syntax for comments (/*, */)
Namespace (set or group of values)
Class 6

Torsion

Torsion is an Interactive Development


Environment (IDE) completely focused on
viewing, editing and debugging.
Class 6

TorqueScript
TorqueScript is the
name of the scripting
language used by the
Torque game engines.

A scripting language is
like a programming
language, but a
scripting language is
easier to use.
Class 6

Torsion: Step Through


Code
Class 6

Functions

$appName
$appName == FPS
FPS Tutorial;
Tutorial;

This line will tell the game engine,


"Store the string 'FPS Tutorial' in
memory, and give that location in
memory the name 'appName' so that I
can get the string later."
Class 6

Introduction to Scripting Part


1:
Conclusion
1.Lab: Have the class run through the homework
exercises
Set Breakpoints, Step through code, and file
structures for .mis and .cs files etc.

2. Quiz: Scripting Part 1

3. Homework: Read Lesson 3 from step 16 in Exercise 2,


Learn TorqueScript Basics, to the end of Exercise 2
Class 7
Class 7

Scripting Part 2: Lecture


1. Continue Scripting
Special Operators (@ and concatenate strings)
Mathematical Operators (<, <=, ++ and %)
Multiple Arguments
If Then Statements
Loops
Arrays
Switch Statements
Setting Properties on Objects like the Location property
Class 7

Canvas.setWindowTitle(getEngineName()@-@
Canvas.setWindowTitle(getEngineName()@-@ $appName);
$appName);

This line sets the title bar of the game window by


concatenating (or joining) three strings together:
The engine name
A hyphen
The value stored in the $appName variable.

The @ character is what concatenates


the strings. This line of script results in the
following title bar when the game
window finally appears:
Class 7

Variables
Global variable A value that you will want
to access from any script file or any function.
To identify a variable as a global variable, put
a dollar sign ($) in front of the variable name.
Local variable A value that you will want to
access only in the scope of where the variable
was created. To identify a variable as a local
variable, put a percent sign (%) in front of the
variable name.
Class 7

Important Scripting
Standards
The echo() function is one of the logging
functions that you can use to print
information to the console window
Semi-colons in script are the equivalent of a
period in a sentence: they end the
instruction. Every instruction in TorqueScript
must end in a semi-colon
Double slashes tell the game engine to ignore
the text that comes after the slashes on the same
line. This is how you add comments to your code
Class 7

Exec()
The exec() function is used to tell the game engine about
other script files.

exec(core/parseArgs.cs);

The exec() console function merely causes the game


engine to step through the file that is listed between the
brackets (core\parseArgs.cs)
Class 7

Breakpoints
Click in the grey area to the left of the line number to
identify this line as a breakpoint.
Class 7

Stepping
Line 68 is a call to the defaultParseArgs() function.
Press F11 to step into the function.
Class 7

Stepping
The core/parseArgs.cs file opens and the yellow
arrow stops at the first line being executed in the
function definition.
Class 7

Echo()
The echo() function is one of the logging functions
that prints information to the console window.
Class 7

//
// Load
Load the
the functions
functions in
in the
the myScriptingTests.cs
myScriptingTests.cs file.
file.
//
// Remove
Remove this
this script
script later.
later.

exec("./myScriptingTests.cs");
exec("./myScriptingTests.cs");

Note: Make sure your myScriptingTests.cs file


is in the same folder as the
game\scripts\main.cs file, otherwise the file
path in the exec() call will be wrong.
Class 7

Consider a file called File1.cs in the


game\scripts
exec("./myScriptingTests.cs");

Both files are in the same folder


(game\scripts): exec("./File2.cs")

File2.cs is in the game\scripts\client subfolder:


exec("./client/Files2.cs")

File2.cs is in the game folder:


exec("~/File2.cs")

File2.cs is in the game\core\scripts folder:


exec("~/core/scripts/File2.cs")
Class 7

Open your new game/scripts/myScriptingTests.cs


file for editing by double clicking on it. Add the following
line of script:

echo("
echo(" -----
----- myScriptingTests.cs
myScriptingTests.cs file
file was
was
executed!
executed! -----
----- ");
");
Class 7

When the game window appears, press the tilde key (~)
to open the console window, and look for the string that
you passed in the echo() function.
Class 7

To round out your understanding of functions, add the


following new function to your
game/scripts/myScriptingTests.cs file. This function
includes an argument. Arguments enable you to pass
values into your function. The argument is stored in a local
variable named myString.

function
function testArgs(%myString)
testArgs(%myString)
{{
echo(">>>>>
echo(">>>>> myString
myString == "" SPC
SPC %myString
%myString SPC
SPC
"<<<<<");
"<<<<<");
}}
Class 7

testArgs(Hello);
testArgs(Hello);
Class 7

The ability to pass arguments into functions enables


you to make all-purpose functions that can handle
multiple situations. For example, if you wanted to
create a set of barricades that were an equal
distance apart, you could create a function like the
following:
Function
Function
creatBarricades(%numBarricades,
creatBarricades(%numBarricades,
%distanceApart,
%distanceApart, %startPos)
%startPos)
Class 7

Add the following new function to your


game/scripts/myScriptingTests.cs file. This
function uses a For loop.
function
function testForLoop(%myNumber)
testForLoop(%myNumber)
{{
echo(""
echo("" NL
NL "First
"First loop:
loop: from
from 11 to"
to" SPC
SPC
%myNumber);
%myNumber);
for
for (%count
(%count == 1;
1; %count
%count <=
<= %myNumber;
%myNumber; %count++)
%count++)
{{
echo(""
echo("" SPC
SPC %count);
%count);
}}
for
for (%count
(%count == 0;
0; %count
%count << %myNumber;
%myNumber; %count++)
%count++)
{{
echo(""
echo("" SPC
SPC %count);
%count);
}}
}}
Class 7

In your For loop, relational operators ( <= and < )


are used to limit how many loops are executed. The
mathematical operator (++) is used to increment the
loop counter. ++ is used because it's faster to type
than %count = %count +1.

for
for (%count
(%count =
= 0;
0; %count
%count <
< %myNumber;
%myNumber;
%count++)
%count++)

for
for (%count
(%count =
= %myNumber;
%myNumber; %count
%count >
> 0;
0;
%count--)
%count--)
Class 7

testForLoop(5)
testForLoop(5)
;;
Class 7

Arrays
Arrays are variables that are used to store a set of values
of the same type (number, string, Boolean, and so on). To
access one of the values in the set, you use its index
number.
Class 7

function
function testArray()
testArray()
{{
//
// Create
Create the
the array.
array.
$dummyText[0]
$dummyText[0] == "Lorum";
"Lorum";
$dummyText[1]
$dummyText[1] == "ipsum";
"ipsum";
$dummyText[2]
$dummyText[2] == "dolor";
"dolor";
$dummyText[3]
$dummyText[3] == "sit";
"sit";
$dummyText[4]
$dummyText[4] == "amet";
"amet";

//
// Print
Print out
out the
the array.
array.
for
for (%count
(%count == 0;
0; %count
%count << 5;
5; %count++)
%count++)
{{
Class 7

testArray();
testArray();
Class 7

While Loop

function
function testWhile(%myNumber)
testWhile(%myNumber)
{{
while
while (%myNumber
(%myNumber << 10)
10)
{{
echo("%myNumber
echo("%myNumber ="
=" SPC
SPC %myNumber);
%myNumber);

//
// Remember
Remember to
to make
make whatever
whatever change
change necessary
necessary
//
// to
to update
update the
the counter
counter variable!
variable!
%myNumber++;
%myNumber++;
}}
}}
Class 7

Scripting Part 2:
Conclusion
Lab: Lab: Have the class run through the homework
1.
exercises
Test For Loop, Array, While, Streetlight, etc.
Step through Lesson 3 as a group and set breakpoints,
create/load in scripts, echo data, concatenate data, for loop,
++ to add 1, array, while loop, control statements, nested
loops, if then, getClassName, If Then, Switch and Brightness

Quiz: Scripting Part 2

Homework: Read Lesson 3 from Exercise 3, Make


Something Happen in the Game, to the end of the
lesson, and review exercises
Class 8
Class 8

Scripting Part 3: Lecture


1. How to make something happen in the game
Explain Callback Functions
Recap Datablocks
Create an object in the game, and attach code to it via
one of the callback functions
Change your code to be more robust and have more
functionality
Debug without Torsion
Debug with Torsion
Class 8

Make Something Happen


In this lesson, you will learn how to attach code to an
object by creating functions that the game engine will
look for when an event occurs that affects that object.
Your code will make something happen in the game.
You will use the World Editor to add a particle emitter
object and a trigger object to the game, and then you
will add script that will make the particle emitter start to
spray bubbles when the player walks into the trigger.

Please reference the full exercise, Lesson 3 Exercise 3


Make Something Happen in the Game.
Class 8

Datablocks
A datablock is a set of properties that can be attached to an object.
Datablocks are a convenient way to set the same properties on
multiple objects of the same type. Additionally, datablocks only
contain properties that will not be modified during a game. This
means that the game engine can download datablocks once, before
your game starts, and then never need to download them again,
which saves network bandwidth during gameplay. In contrast,
properties that are expected to change during gameplay are set
directly on objects. Datablocks are like a suitcase that you travel
with, that arrives at your destination before you do.
For more information about datablocks, see Datablock Editor in the
online documentation. You also learned about datablocks in the
character lesson. In this lesson, the triggers datablock object is the
one that contains the callback function you will use.
Class 8

Datablocks
The panels on the right side of the World Editor change to
the Datablock Library and the Datablock properties
panels.
Class 8

Scripting Part 3:
Conclusion
Lab: Lesson 3 Part 3
1.
Follow the steps in exercise 3 to set up the trigger.
Follow the steps in exercise 4 to change the code
and place a boulder in the trigger.
Follow the steps in exercise 6 to see how you can
use Torsion to fool the game engine into thinking
there is more than one object in the trigger.

2. Quiz: Scripting Part 3

3. Homework: Read Lesson 5 and review examples


Class 9
Class 9

Adding and Customizing


Weapons: Lecture
1. Weapons:
The Shape Editor, viewing the soldier and weapon model
Projectiles, player inventory, loaded and firing
Datablocks (sounds)
EnvironmentAmbientLight, mountPoint, RetractionPoint,
Muzzlepoint, Ejectpoint, MuzzleFlash, Eye and Biped Nodes
Third Person Weapons
Handgun
Ammunition, reloading
COLLADA and DAE file format
Hooking up a weapon
State Machine and weapon states
Class 9

Shape Editor
Open the Shape Editor Load Soldier Model
Class 9

Shape Editor
Load Arms Load Weapon
Class 9

Key Terminology
EnvironmentAmbientLight is the lighting
inside of the Shape Editor. The bn_Gun_Root
node is the top node for the Weapon
mountPoint is where the weapon mounts to
the player so that they appear to be holding the
weapon
RetractionPoint is a combination of collision
and force. If the retraction point collides with an
object, it will retract the direction of movement
Muzzlepoint is the area of the muzzle where
the muzzle flash effect will occur
Class 9

Key Terminology
Ejectpoint is the node where the shell
casing will be ejected after firing
MuzzleFlash_LOD300 is the reference
point for a further muzzle flash on the
soldier gun at a specific level of detail
(LOD)
The Eye node is the default camera
placement for the eye in first-person
The Bip001 nodes are the biped nodes
that correspond with the soldiers skeleton
Class 9

Weapon Sounds
Inthe
Datablock
Library, select
the New tab
and scroll down
to SFXProfile
Class 9

Weapon Sounds
Create New Datablock
dialog
Name your new datablock
RyderFireSound
Select
WeaponTemplateFireSo
und in the Copy values
from dropdown
Press Create
Class 9

Weapon Sounds
Create another SFXProfile and name it
RyderReloadSound
Assign
art/sound/weapons/wpn_ryder_reload.wav to the
fileName property
Create a third SFXProfile and name it
RyderSwitchinSound
Use the WeaponTemplateSwitchinSound from
the Copy values from dropdown
Assign
art/sound/weapons/wpn_ryder_switchin.wav for
the sound file
Class 9

Ammunition
In the New tab of the
Datablock Library double-click
on ItemData to make a new
datablock
Name it RyderClip
Select WeaponTemplateAmmo
from the Copy values from
dropdown and press Create
Scroll down to the Render
section and click the browse
button ( ) next to the
shapeFile property
Class 9

Ammunition
Scroll down to the Render
section and click the browse
button ( ) next to the
shapeFile property.

Find
art/shapes/weapons/
Ryder/TP_Ryder.DAE
and click Open . Ensure
you have the file type
set to COLLADA Files
in the file browser.
Class 9

Ammunition
Scroll down to the
Scripting section
Set the category to
AmmoClip by clicking
in the box to the right
of category and typing
in 'AmmoClip'
In the Object section
set the class to
AmmoClip (it is case
sensitive you must use
a capital A and capital
C)
Class 9

Ammunition
Scroll down to the Dynamic
Fields section and set
maxInventory to 10
Click the Add Dynamic Field
button ( ) to add a new field.
Name it pickUpName and
set the value to Ryder clip
Add another field called
count and set the value to 1
Class 9

Ammunition
In the Datablock
Library on the New
tab, find ItemData and
double-click it to make
another new ItemData
datablock
Name it RyderAmmo
Select
WeaponTemplateAm
mo from the Copy
values from dropdown
Class 9

Ammunition
In the Dynamic Fields
section set the
maxInventory Dynamic
Field to 8
Click the Add Dynamic
Field button ( ) to add a
new field
Name it clip and set the
value to RyderClip.
Create a Dynamic Field
called pickUpName and
set the value to Ryder
ammo
Class 9

Weapon
The type of datablock here is
ItemData again since it is an item.
This time, though, instead of an
ammunition item (picking up a clip in
the world, for example), it will be for
the handgun itself.

On the New tab of the Datablock


Library, double-click the ItemData
entry to create a new datablock
Name it Ryder
Select WeaponTemplateItem
from the Copy values from
dropdown
Class 9

Weapon
On the New tab of the Datablock
Library, double-click the ItemData
entry to create a new datablock
Name it Ryder
Select WeaponTemplateItem from
the Copy values from dropdown
Scroll down to the Render section
and browse to
art/shapes/weapons/ryder/TP_Ry
der.DAE for the shapeFile property
Make sure that the file type filter is
set to COLLADA Files in the Open
file dialog
Click Open
Class 9

Weapon
Scroll down to the Dynamic Fields
section
Set the description to Ryder
Set image to RyderWeaponImage
Set pickUpName to Ryder pistol
Click the Add Dynamic Field button (
), name the new field PreviewImage,
and set the value to ryder.png
If you pop back into Torsion and peek
at your
art/datablocks/managedDatablock
s.cs file you'll see that it has
continued to keep pace with your work
Class 9

datablock
datablock ItemData(Ryder
ItemData(Ryder :: WeaponTemplateItem)
WeaponTemplateItem)
{{
shapeFile
shapeFile ==
"art/shapes/weapons/Ryder/TP_Ryder.DAE";
"art/shapes/weapons/Ryder/TP_Ryder.DAE";
cameraMaxDist
cameraMaxDist == "0.305344";
"0.305344";
category
category == "Weapon";
"Weapon";
class
class == "Weapon";
"Weapon";
pickUpName
pickUpName == "Ryder
"Ryder pistol";
pistol";
emap
emap == "1";
"1";
image
image == "RyderWeaponImage";
"RyderWeaponImage";
Reticle
Reticle == "crossHair";
"crossHair";
PreviewImage
PreviewImage == "ryder.png";
"ryder.png";
description
description == "Ryder";
"Ryder"; (dont
(dont forget
forget };
}; ))
Class 9

The next part covers how to


set up the correct object for
the useable weapon
Navigate to the New tab of
the Datablock Library
and create a new
ShapeBaseImageData
datablock
Name it
RyderWeaponImage and
select
WeaponTemplateImage
from the Copy values
from dropdown
Class 9

Now you can find your new


RyderWeaponImage in the
Existing tab of the
Datablock Library
Note the * after
RyderWeaponImage to
denote unsaved data
Save your new datablock ( )
Class 9

Scroll to the General section


Check the emap box
Set the shapeFile property to
art/weapons/Ryder/TP_Ryder.DAE
Set the shapeFileFP property to
art/weapons/Ryder/FP_Ryder.DAE
Set the imageAnimPrefix property
to Pistol
Set the imageAnimPrefixFP
property to Pistol
Check the animateOnServer box
Select BulletProjectile in the
Projectile dropdown
Class 9

Scroll down and


Check the
useEyeNode
property
Select
WeaponFireLight
in the lightType
dropdown
Class 9

Scroll down and select


BulletShell for the casing
property
This sets the appearance of
the ejected shell casings
Set shellExitDir to 1 0.3 1
Set shellExitVariance to
15
Set shellVelocity to 3
Check useRemainderDT
Class 9

Click the + next to the


States property to
open the state list
Open state [1] by
clicking on the +
You'll see that the
stateName is
Activate
Class 9

Scroll down to
stateSound and select
RyderSwitchinSound
from the dropdown list
of available
SFXProfiles
Class 9

Open state [5]. Note


that the stateName
is Fire
Class 9

Scroll to the
stateSound and
stateEmitter properties
Select RyderFireSound
for the stateSound
Select
GunFireSmokeEmitter
for the stateEmitter
property
Class 9

Open state [9]. This is


the ReloadClip state
When you no longer
have ammunition in
your current clip your
weapon will enter the
ReloadClip state and
there is no change to
be made here
Class 9

Scroll
down to the
stateSound
property and select
RyderReloadSou
nd from the
dropdown list
Class 9

Save your datablock ( ) and scroll to


the Dynamic Fields section
Set item to Ryder
Set ammo to RyderAmmo
Click the Add Dynamic Field button
( ) and name your new field clip and
set the value to RyderClip
Create another named
shellExitOffset and set the value to
0.15 -0.56 -0.1
Create another named
projectileSpread set the value to
0.005
Create a last named projectileType
set the value to Projectile
Class 9

datablock
datablock ShapeBaseImageData(RyderWeaponImage
ShapeBaseImageData(RyderWeaponImage ::
WeaponTemplateImage)
WeaponTemplateImage)
{{
emap
emap == "1";
"1";
shapeFile
shapeFile ==
"art/shapes/weapons/Ryder/TP_Ryder.DAE";
"art/shapes/weapons/Ryder/TP_Ryder.DAE";
shapeFileFP
shapeFileFP ==
"art/shapes/weapons/Ryder/FP_Ryder.DAE";
"art/shapes/weapons/Ryder/FP_Ryder.DAE";
animateOnServer
animateOnServer == "1";
"1";
projectile
projectile == BulletProjectile;
BulletProjectile;
projectileType
projectileType == Projectile;
Projectile;
lightType
lightType == "WeaponFireLight";
"WeaponFireLight";
lightColor
lightColor == "0.992126
"0.992126 0.992126
0.992126 0.740157
0.740157 1";
1";
ammo
ammo == "RyderAmmo";
"RyderAmmo";
Item
Item == "Ryder";
"Ryder";
Class 9

shellExitDir
shellExitDir == "1
"1 0.3
0.3 1";
1";
shellExitVariance
shellExitVariance == "15";
"15";
shellVelocity
shellVelocity =
= "3";
"3";
shellExitOffset
shellExitOffset =
= "0.15
"0.15 -0.56
-0.56 -0.1";
-0.1";
clip
clip =
= "RyderClip";
"RyderClip";
projectileSpread
projectileSpread == "0.005";
"0.005";
stateSound[5]
stateSound[5] = = "RyderFireSound";
"RyderFireSound";
stateSound[1]
stateSound[1] = =
"RyderSwitchinSound";
"RyderSwitchinSound";
stateSound[9]
stateSound[9] = =
"RyderReloadSound";
"RyderReloadSound";
imageAnimPrefix
imageAnimPrefix = = "Pistol";
"Pistol";
imageAnimPrefixFP
imageAnimPrefixFP = = "Pistol";
"Pistol";
useEyeNode
useEyeNode = = "1";
"1";
};
};
Class 9

Using a Weapon
Datablocks are
controlled by the
server side and are
created at server
start, so you can't
actually test any of
this in the game until
you restart it. Save
the level and then quit
the World Editor
Class 9

In order to get your new weapon set up so that the player can
actually equip and use it you'll need to edit two script files:
art/datablocks/player.cs and scripts/server/gameCore.cs.
You can edit these files in Torsion or another text editor.

Open art/datablocks/player.cs. At the end of the file you should


find the following code block:

//
// Allowable
Allowable Inventory
Inventory Items
Items
Class 9

mainWeapon
mainWeapon == Lurker;
Lurker;

maxInv[Lurker]
maxInv[Lurker] =
= 1;
1;
maxInv[LurkerClip]
maxInv[LurkerClip] =
= 20;
20;

maxInv[LurkerGrenadeLauncher]
maxInv[LurkerGrenadeLauncher] = =
1;
1;
maxInv[LurkerGrenadeAmmo]
maxInv[LurkerGrenadeAmmo] = = 20;
20;

maxInv[DeployableTurret]
maxInv[DeployableTurret] == 5;
5;

maxInv[ProxMine]
maxInv[ProxMine] == 5;
5;
Class 9

After the line mainWeapon =


Lurker; insert the following:

maxInv[Ryder]
maxInv[Ryder] == 1;
1;
maxInv[RyderClip]
maxInv[RyderClip] == 10;
10;

This sets all of your players up so that


they can carry one of your
weapon items (maxInv[Ryder]) and
a maximum of 10 of your clip
items (maxInv[RyderClip]).
Class 9

State Machine
Class 9

State Machine
The first thing to notice about the way the state system
works is that each action is represented by a number in
square brackets [ ]
These need to stay consistent with the states that you
are creating so that Torque 3D can figure out how you
need the weapon to perform
After the stateName field, each state section has
several stateTransition fields to account for various
conditions. This allows us to design our system to
transition to other states based on these conditions.
Farther down there are several fields that dictate various
effects of the state such as stateEnergyDrain for
things like laser weapons, or stateEjectShell to indicate
that this state should cause the weapon to eject a shell
casing
Class 9

Add a New Wait State


Set the stateName field to
WaitForRelease
In the
stateTransitionOnTriggerUp
field enter reload
Leave the stateTimeoutValue to
0
Ensure that stateWaitForTimeout
is not checked
Close state [13] and open state [5]
In the stateTransitionOnTimeout field
enter WaitForRelease
Class 9

Wait State Conclusion


Save your level, exit the game and
restart it. Now, when you try your pistol it
should only fire one round for each time
you press the fire button
State machines are a quick and handy
way to set up behaviors and transition
between them. Now that you've seen
how to use them for weapons you might
find more creative uses for them
Class 9

Adding and Customizing


Weapons: Conclusion
1. Lab:
Change to Ryder Weapon, change ammunition,
set weapon parameters and state for weapon
(2 hours) Start work on Team Project

2. Quiz: Lesson 5

3. Homework: Read Lesson 6 and review exercises


Class
10
Class 10

Keeping Players in Sync:


Lecture
1. Lecture: Lesson 6
Tracking a message from client to server
Cover Client/Server architecture, Instance, keeping
players in sync, messageClient, ServerMessage
Client side functions vs. server side functions
GameConnect to start a multiplayer game
Cover ClientGroup and getCount for tracker a list of
server objects
Cover myClientCommands.cs and
myServerCommands.cs
Cover function sendTeleportSignal, TeleportReady,
%client
Try teleporting a player and tracking the data
SendTeleportSignal()
Class 10

Synchronization
Synchronization such as this is built into Torque 3D
games. However, when you start adding custom gameplay
features to your game, you might also need to add custom
synchronization for those features
Client/Server
When multiple players are playing the same mission in a Torque
3D game, each player sees the same game world, but on their
own computer. A change to the game world caused by one
player is sent, as data, to the other players. The part of the
game that passes data between players is called the server
instance. The part of the game that players interact with on
their computers is called the client instance. The server
instance keeps track of the state of the game and updates the
clients on a need-to-know basis
Class 10

Server Exercise
In this example, a welcome message is sent to the
client when the mission begins, and the message is
displayed in the client's game window
View the location of the core script files for the
server instance
In Windows Explorer, with a standard installation it
will be the folder C:\Torque\Torque 3D
1.2\MyProjects\FPSTutorial\game\core\scripts\
server
In Torsion, with the FPSTutorial project open, the path
is FPSTutorial\core\scripts\server
Open the message.cs file
Class 10

Server Exercise
Look for the following messageClient function definition:

function
function clientCmdServerMessage(%msgType,
clientCmdServerMessage(%msgType,
%msgString,
%msgString, %a1,
%a1, %a2,
%a2, %a3,
%a3, %a4,
%a4, %a5,
%a5, %a6,
%a6, %a7,
%a7, %a8,
%a8, %a9,
%a9, %a10)
%a10)
{{
//
// ...(code
...(code removed,
removed, partial
partial example)
example)
}}

The server can send a command to the client asking it to


run a function that exists on the client side. That way, the
client does all the work. In this case, the client will do the
work of displaying the message in their game window.
Class 10

Whenever the server wants to call a function on the client


side, it uses the commandToClient function.
View the location of the core script files for the client instance.
In Windows Explorer, with a standard installation it will be
the folder C:\Torque\Torque 3D
1.2\MyProjects\FPSTutorial\game\core\scripts\clien
t
In Torsion, with the FPSTutorial project open, the path is
FPSTutorial\core\scripts\client
Any client-side function that will be called by the server is
identified by the "clientCmd" prefix. When the server sends a
command to the client to call this function, the server doesn't
need to use the "clientCmd" prefix. As you saw in step 3, the
server script refers the above function as 'ServerMessage',
and not as 'clientCmdServerMessage'.
Class 10

Server Exercise
View the location of the non-core script files for the
server instance
In Windows Explorer, with a standard installation it will
be the folder C:\Torque\Torque 3D
1.2\MyProjects\FPSTutorial\game\scripts\server.
In Torsion, with the FPSTutorial project open, the path
is FPSTutorial\scripts\server
Open the gameCore.cs file
Look for the following
GameCore::onClientEnterGame callback function
Class 10

function
function GameCore::onClientEnterGame(%game,
GameCore::onClientEnterGame(%game, %client)
%client)
{{
//
// ...(code
...(code removed
removed to
to save
save space)
space)

//
// Inform
Inform the
the client
client we've
we've joined
joined up
up
messageClient(%client,
messageClient(%client,
'MsgClientJoin',
'MsgClientJoin', '\c2Welcome
'\c2Welcome to
to the
the Torque
Torque demo
demo app
app
%1.',
%1.',
%client.playerName,
%client.playerName,
%client,
%client,
%client.sendGuid,
%client.sendGuid,
%client.team,
%client.team,
%client.isSuperAdmin);
%client.isSuperAdmin);
Class 10

%client.score,
%client.score,
%client.kills,
%client.kills,
%client.deaths,
%client.deaths,
%client.isAiControlled(),
%client.isAiControlled(),
%client.isAdmin,
%client.isAdmin,

Whenever a client joins the game, they will see the


ServerMessage. Even when you play the game alone and
without choosing to Host, you will see the message because
our local client instance still has to connect to the server
instance in your game application.
Class 10

Server Exercise
Class 10

Server Exercise

In the preceding exercise, you saw how the server


sends a command to a client in order to execute a
special client-side function. In the next exercise, you
will modify the commands to see how your changes
take effect in the game.
Class 10

Synchronization Exercise
View the location of the non-core script files for the
server instance.
In Windows Explorer, with a standard installation it
will be the folder C:\Torque\Torque 3D
1.2\MyProjects\FPSTutorial\game\scripts\serve
r. In Torsion, with the FPSTutorial project open, the
path is FPSTutorial\scripts\server.

Open the gameCore.cs file.

Look for the following GameCore::onClientEnterGame


function:
Class 10

function
function GameCore::onClientEnterGame(%game,
GameCore::onClientEnterGame(%game,
%client)
%client)
{{
//
// ...(code
...(code removed
removed to
to save
save space)
space)

//
// Inform
Inform the
the client
client we've
we've joined
joined up
up
messageClient(%client,
messageClient(%client,
'MsgClientJoin',
'MsgClientJoin', '\c2Welcome
'\c2Welcome to
to the
the
Torque
Torque demo
demo app
app %1.',
%1.',
Class 10

%client.playerName,
%client.playerName,
%client,
%client,
%client.sendGuid,
%client.sendGuid,
%client.team,
%client.team,
%client.score,
%client.score,
%client.kills,
%client.kills,
%client.deaths,
%client.deaths,
%client.isAiControlled(),
%client.isAiControlled(),
%client.isAdmin,
%client.isAdmin,
%client.isSuperAdmin););
%client.isSuperAdmin););
Class 10

Below this code at the end of the


function add the following script
inside the closing brace:
function
function
GameCore::onClientEnterGame(%game,
GameCore::onClientEnterGame(%game,
%client)
%client)
{{
//
// ...(code
...(code removed
removed to
to save
save space)
space)

//
// Inform
Inform all
all other
other clients
clients of
of the
the
new
new arrival
arrival
messageAllExcept(%client,
messageAllExcept(%client, -1,
-1,
'MsgClientJoin',
'MsgClientJoin', '%1
'%1 joined
joined the
the game!',
game!',
%client.playerName);
%client.playerName);
}} //
// function
function closing
closing brace
brace
Class 10

Synchronization Exercise
Class 10

Synchronization Exercise

The same message is sent out by calling


messageAllExcept. This message is sent to all other
clients except for the client that just joined the game.

Find the GameCore::onClientEnterGame function


and add the following code to the end of the function
inside the closing brace.
Class 10

function
function GameCore::onClientEnterGame(%game,
GameCore::onClientEnterGame(%game, %client)
%client)
{{
//
// code
code omitted
omitted in
in example
example
//
// Inform
Inform all
all other
other clients
clients of
of the
the new
new arrival
arrival
messageAllExcept(%client,
messageAllExcept(%client, -1,-1, 'MsgClientJoin',
'MsgClientJoin',
'%1
'%1 joined
joined the
the game!',
game!',
%client.playerName);
%client.playerName);
messageClient(%client,
messageClient(%client, 'MsgClientJoin',
'MsgClientJoin',
'Everyone
'Everyone has
has been
been informed
informed that
that you
you have
have arrived
arrived and
and
they
they will
will be
be
hunting
hunting you
you shortly!');
shortly!');

}} //
// function
function closing
closing brace
brace
Class 10

Synchronization Exercise
Save the file. If your
game is already
running, exit the
game.
To see your new
message, start the
game.
Class 10

//
// ***
*** add
add this
this code
code ***
***
//
// --------------------------------------------------
--------------------------------------------------

if(ClientGroup.getCount()
if(ClientGroup.getCount() >> 1)
1)
{{

//
// --------------------------------------------------
--------------------------------------------------
//
// ***
*** end
end add
add code
code ***
***
//
// --------------------------------------------------
--------------------------------------------------
//
// Inform
Inform all
all other
other clients
clients of
of the
the new
new arrival
arrival
messageAllExcept(%client,
messageAllExcept(%client, -1,
-1, 'MsgClientJoin',
'MsgClientJoin',
'%1
'%1 joined
joined the
the game!',
game!',
%client.playerName);
%client.playerName);
Class 10

//
// ***
*** Add
Add this
this code
code ***
***
//
// and
and tell
tell the
the new
new guy
guy he's
he's in
in trouble!
trouble!
messageClient(%client,
messageClient(%client, 'MsgClientJoin',
'MsgClientJoin',
'Everyone
'Everyone has
has been
been informed
informed that
that you
you have
have arrived
arrived and
and
they
they will
will be
be hunting
hunting you
you shortly!');
shortly!');

//
// --------------------------------------------------
--------------------------------------------------
//
// ***
*** add
add this
this code
code ***
***
//
// --------------------------------------------------
--------------------------------------------------

}} //
// Don't
Don't forget
forget this
this closing
closing bracket.
bracket.
Class 10

Synchronization Exercise
The ClientGroup is a server object that keeps a list of all
the clients that are playing the game. The getCount
method of the ClientGroup object returns the number of
clients in the list. The if statement tests to see if there is
more than one client in the list
Save your file. Now if you play the game alone, you won't
see the message "Everyone has been informed that you
have arrived and they will be hunting you shortly." You will
only see the message if another player joins your game
Testing for the number of players is a common scripting
task. Also, you can obtain any client object by using the
clientGroup.getObject() function. For script examples
that do just that, see the topic "GameConnection Class
Reference" in the Torque 3D Script Manual, and search
for "ClientGroup.getObject"
Class 10

New Script Exercise


In this exercise, you will create your own
script files that will send commands. This
time, you will send a command from the client
to the server. The command will call a server-
side function that will change the position of
the player, effectively teleporting the player
You need to tell only the server about
changes to objects in the game, because the
objects are then updated automatically on all
clients. As soon as your script tells the server
to move the player, the server takes care of
updating that player's position on all clients
Class 10

New Script Exercise


In order to test your changes quickly, you will use
the console window to call the client-side teleport
function directly
View the location of the script files for the client
instance
In Windows Explorer, with a standard installation it
will be the folder C:\Torque\Torque 3D
1.2\MyProjects\FPS tutorial\game\scripts\client
In Torsion, with the FPSTutorial project open, the path
is FPSTutorial\scripts\client
Class 10

New Script Exercise


Client-side script files don't have to go in the
game\scripts\client folder. However, doing so
keeps your script files organized. You can actually
put your script files anywhere in the game folder
structure. The only subfolder you should avoid is
the game\core folder, which contains script for
all the core behavior in a game. You can over-ride
core behavior by creating new function
definitions for those functions that already exist.
You just shouldn't modify or add to the files in the
game\core folder
Class 10

New Script Exercise


By adding a new script file instead of adding
script to an existing file, you make it easier to
share that piece of functionality with other
game projects
Open the new myClientCommands.cs for
editing
Add the following script code to your empty
file:
Class 10

//
// Client
Client instance
instance script
script file:
file: myClientCommands.cs
myClientCommands.cs
//
// Companion
Companion to
to the
the server
server script
script file:
file:
myServerCommands.cs
myServerCommands.cs

//
// ------------------------------------------------
------------------------------------------------
//
// Define
Define aa function
function that
that will
will be
be called
called by
by the
the
//
// client
client
//
// instance
instance (in
(in the
the mission
mission file)
file) to
to set
set up
up
//
// teleporting.
teleporting.
//
// This
This function
function sends
sends aa command
command to
to the
the server
server
//
// instance
instance
//
// to
to start
start teleporting
teleporting the
the player
player in
in this
this client
client
//
// instance.
instance.
//
// -----------------------------------------------
-----------------------------------------------
function
function sendTeleportSignal()
sendTeleportSignal()
{{
Class 10

//
// Set
Set aa variable
variable to
to pass
pass to
to the
the function
function call
call
//
// that
that comes
comes next...
next...
%time
%time == 1000;
1000; //
// in
in milliseconds
milliseconds

//
// Call
Call the
the "TeleportReady"
"TeleportReady" function
function on
on the
the server
server side,
side,
// Pass in your variable, which represents a 1 second
// Pass in your variable, which represents a 1 second
//
// delay.
delay.
commandToServer('TeleportReady',
commandToServer('TeleportReady', %time);
%time);

}}
Class 10

Keeping Players in Sync

The sendTeleportSignal function, which will be run


on the client side, sends a command to the server,
asking the server to call the TeleportReady
function. The TeleportReady function will exist on
the server side. You will create the definition for the
TeleportReady function next.
The TeleportReady function will take one argument
(%time). This argument becomes the second
argument of the commandToServer function call
above.
Class 10

Keeping Players in Sync

Save your myClientCommands.cs file.

You just created the definition for a function that will


be called on the client side. This function sends a
command to the server to execute a function on the
server side (TeleportReady). Next, you will add a
definition for the serverCmdTeleportReady
function that will be called on the server side, as
well as definitions for supporting functions.
Class 10

Keeping Players in Sync

View the location of the script files for the server instance. In
Windows Explorer, with a standard installation it will be the
folder C:\Torque\Torque 3D 1.2\MyProjects\FPS
Tutorial\game\scripts\server. In Torsion, with the
FPSTutorial project open, the path is
FPSTutorial\scripts\server.
Create a file in the server folder, named myServerCommands.cs

Open the new myServerCommands.cs for editing

Add the following script code to your empty file


Class 10

Keeping Players in Sync

function
function serverCmdTeleportReady(%client,
serverCmdTeleportReady(%client, %time)
%time)
{{

schedule(%time,
schedule(%time, 0,
0, "beginTeleport",
"beginTeleport", %client);
%client);

}}
//
// ---------------------------------------------------------
---------------------------------------------------------
//
// Define aa function
Define function that
that is
is called
called after
after aa delay.
delay.
//
// This
This function
function manually
manually changes
changes the
the position
position ofof the
the player
player
//
// on
on the
the server.
server. The
The server
server then
then takes
takes care
care of
of updating
updating
//
// all
all the
the clients
clients with
with the
the new
new position
position of
of the
the player.
player.
//
// ---------------------------------------------------------
---------------------------------------------------------
function
function beginTeleport(%cl)
beginTeleport(%cl)
{{
Class 10

Keeping Players in Sync

function
function beginTeleport(%cl)
beginTeleport(%cl)
{{
//
// Generate
Generate aa random
random distance
distance byby using
using the
the Torque
Torque 3D
3D
//
// getRandom()
getRandom() function.
function.
%dist
%dist == 55 ++ (getRandom()
(getRandom() ** 5);
5);

//
// Get
Get aa reference
reference to
to this
this client's
client's control
control object
object
by
by
//
// using
using the
the Torque
Torque 3D
3D getControlObject()
getControlObject() function.
function.
//
// The
The control
control object
object is
is the
the player.
player.
%controlObject
%controlObject == %cl.getControlObject();
%cl.getControlObject();
Class 10

Keeping Players in Sync

//
// Get
Get the
the player's
player's physical
physical position
position and
and height.
height.
%pos
%pos == %controlObject.position;
%controlObject.position;
%height
%height == getWord(%pos,
getWord(%pos, 2);
2);

//
// Add
Add the
the distance
distance to
to the
the value
value already
already in
in the
the
//
// height
height variable.
variable.
%height
%height +=
+= %dist;
%dist;

//
// Set
Set %pos
%pos variable
variable to
to the
the new
new position
position value.
value.
%pos
%pos == setWord(%pos,
setWord(%pos, 2,
2, %height);
%height);
Class 10

Keeping Players in Sync

//
// In
In the
the object
object that
that represents
represents the
the current
current player,
player,
//
// set
set the
the position
position property
property to
to your
your %pos
%pos value.
value.
//
// It's
It's by
by modifying
modifying the
the position
position property
property of
of the
the
// actual player object that you physically
// actual player object that you physically movemove
//
// the
the player.
player.
%controlObject.position
%controlObject.position == %pos;
%pos;

//
// Send
Send aa message
message to
to the
the client's
client's game
game window
window to
to
// tell them how far they went.
// tell them how far they went.
commandToClient(%cl,
commandToClient(%cl, 'ServerMessage',
'ServerMessage', 'MsgClientJoin',
'MsgClientJoin',
%msgString,
%msgString,
'You
'You were
were teleported!
teleported! Distance:
Distance: %1',
%1', %dist);
%dist);
}}
Class 10

Keeping Players in Sync


Always include the %client parameter as the first parameter
in a definition for a server-side command function. The server
needs to know which client sent the command. In contrast,
when you call a client-side function from a server script file, no
extra parameters are added because there's only one server.

Save your myServerCommands.cs file.


Before the client and server scripts will work, you need to add the files
to the build process so that the game engine will load the function
definitions into memory.
Class 10

Keeping Players in Sync

Open the game\scripts\main.cs file for editing.

Search for the following section:

//
// Load
Load the
the scripts
scripts that
that start
start it
it all...
all...
exec("./client/init.cs");
exec("./client/init.cs");
exec("./server/init.cs");
exec("./server/init.cs");

Add the following script after the exec("./server/init.cs"); line. These lines will execute your
script files and load all of the functions into memory.

//
// Add
Add your
your own
own command
command scripts.
scripts.
exec("./client/myClientCommands.cs");
exec("./client/myClientCommands.cs");
exec("./server/myServerCommands.cs");
exec("./server/myServerCommands.cs");

Save the game\scripts\main.cs file.


Class 10

Keeping Players in Sync


Start the game from the Torque Toolbox. In the Torque Toolbox window, in the
Projects tab, under My Projects, select your game, FPS Tutorial (1). On the
right side of the Torque Toolbox, click Play Game (2).

After the level loads, press TAB to switch from first-person view to third-person
view so that you can see all of your character.
Class 10

Keeping Players in Sync


Press tilde (~) to open the console window overlay.
Class 10

Keeping Players in Sync


At the bottom of the console window, call your
SendTeleportSignal() client-side function and then
immediately press tilde (~) to close the console window so
that you can see your character teleport. To call your function,
type the following into the textbox at the bottom of the
console window and then press ENTER.

SendTeleportSignal();

After you press ENTER to confirm the function you typed in,
press tilde (~) to close the console window, quickly you
should see your character teleported into the air, and receive
a message on your screen that tells you how far.
Class 10

Keeping Players in Sync


You might try to call the serverCmdTeleportReady() function
directly. However, that function will expect a %client parameter, and
you don't know the ID of your client, so the function call will fail.
Class 10

Keeping Players in Sync


The following image shows the files that you created and
modified, and the flow of control through them.
Class 10

Keeping Players in Sync


In this exercise, you will modify your new script files to make a player
teleport only when they stand over a teleporter pad in the game. To trigger
the teleport, you will create a new trigger datablock and attach it to a new
trigger object in your scene that you will place over a teleporter pad. When
a player walks into the trigger space, your script will be called to teleport
the player.
Class 10

Keeping Players in Sync


In the World Editor, click the Datablock Editor button at
the top left of the screen or press F6 so that you can
modify the datablocks that are available to your level.

The panels on the


right side of the
World Editor
change to the
Datablock
Library and the
Datablock
properties panels.
Class 10

Keeping Players in Sync


In the New tab of the Datablock Library, double-click the
TriggerData base datablock to create a new datablock that will
inherit its structure from TriggerData.

The Create New Datablock


dialog box appears.

Under Your new datablock must


have a name, change the name to
TeleportTriggerData.

Click Create. Your new datablock is


created and displayed in the
Existing tab of the Datablock
Library panel.
Class 10

Keeping Players in Sync


In the Existing tab of the
Datablock Library panel, expand
the TriggerData node, and then
select the TeleportTriggerData
datablock. Notice that an asterisk
(*) appears beside the
TeleportTriggerData node and
next to the title of the Datablock
panel, which indicates that the
datablock needs to be saved.

In the Datablock panel, click the


Save Datablock button .
Class 10

Keeping Players in Sync


In the World Editor, click the Object
Editor button at the top left of the
screen or press F1 so that you can
bring up the Scene Tree panel to
modify the objects in the scene.

Using the mouse to aim, and the arrow keys (or W,


A, S, D) to move, position your camera close to the
manhole cover near the yellow van on the east side
of the courtyard. We will create a new teleporter pad
next to the van.
Class 10

Keeping Players in Sync


Class 10

Keeping Players in Sync


Create a teleporter pad by clicking
on the Library tab, then the
Meshes sub-tab and navigating to
the art/shapes/teleporter folder.
Double-click the teleporter.

If the Collada Import Dialog


appears, click 'OK' to continue.

Rename the new TSStatic to


StreetTeleporter and change the
position to 20.7 10.8 -0.13.
Class 10

Keeping Players in Sync


You are now ready to add a trigger from the library
to place over the teleporter pad.
Class 10

Keeping Players in Sync


In the Scene Tree panel, in the Library tab, in the
Level subtab, open the Level folder by double-clicking
it, or by selecting Level from the drop-down box.

Double-click the Trigger


object.

The Create Object: Trigger


dialog box appears.
Class 10

Keeping Players in Sync


Next to Object Name, type in a name, such as
StreetTeleportTrigger. Next to Data Block, select
your new TeleportTriggerData datablock.

Click Create New.


Class 10

Keeping Players in Sync


A yellow cube appears over the teleporter pad. This cube
illustrates the area that a player would have to enter to
activate the trigger.

Click Create New.

Note that the name


has been changed to
StreetTeleportTrigg
er and that it has
been positioned at
20.8 10.7 -0.1036.
This position is
squarely over the
teleporter pad.
Class 10

Keeping Players in Sync


Select the Scene tab in the Scene Tree panel to
view your new object in the list.
To make the trigger call the teleport command when
activated, you will add some trigger functions to
your script files.
Open your server-side script file,
myServerCommands.cs, for editing.
Paste in the code in the following slides at the end of
your file:
Class 10

Keeping Players in Sync

function
function TeleportTriggerData::onEnterTrigger(
TeleportTriggerData::onEnterTrigger( %this,
%this, %trigger,
%trigger, %obj
%obj ))
{{
//
// Print
Print this
this string
string to
to the
the console
console window.
window.
echo(
echo( "The
"The player
player has
has walked
walked over
over the
the teleporter
teleporter pad.");
pad.");

//
// Get
Get aa reference
reference to
to the
the client
client (ie,
(ie, this
this player)
player)
//
// from
from the
the %obj
%obj variable.
variable.
%client
%client == %obj.getControllingClient();
%obj.getControllingClient();

//
// If
If there
there is
is none,
none, exit
exit this
this function
function now.
now.
if
if (%client
(%client ==
== 0)
0) return;
return;

//
// Call
Call the
the beginTeleport()
beginTeleport() function
function to
to kick
kick off
off the
the
//
// teleportation
teleportation sequence.
sequence.
beginTeleport(%client);
beginTeleport(%client);
}}
Class 10

Keeping Players in Sync

function
function TeleportTriggerData::onLeaveTrigger(
TeleportTriggerData::onLeaveTrigger( %this,
%this, %trigger,
%trigger, %obj
%obj ))
{{
//
// Print
Print this
this string
string to
to the
the console
console window.
window.
echo(
echo( "The
"The player
player has
has left
left the
the teleporter
teleporter pad.");
pad.");
}}

//
// ---------------------------------------------------------
---------------------------------------------------------
//
// This function
This function is
is called
called every
every tickPerioMS
tickPerioMS while
while aa player
player
//
// is
is within
within the
the trigger
trigger space.
space.
//
// ---------------------------------------------------------
---------------------------------------------------------
function
function TeleportTriggerData::onTickTrigger(
TeleportTriggerData::onTickTrigger( %this,
%this, %trigger
%trigger ))
{{
//
// Print
Print this
this string
string to
to the
the console
console window.
window.
echo(
echo( "The player is still standing on
"The player is still standing on the
the teleporter
teleporter pad.");
pad.");
}}
Class 10

Keeping Players in Sync


These are the three callback functions that can be
written for a datablock that is based on the TriggerData
class, which is what you created in step 6 when you
created the TeleportTriggerData datablock. To teleport
the player as soon as they walk over the teleporter pad,
you call your server-side beginTeleport function from
the TeleportTriggerData::onEnterTrigger function.
This will update the position of the player in the server's
version of the game data, which will make the server
update the position of the player in every client game
window, including the one for the player that walked into
the trigger.
Class 10

Keeping Players in Sync

function
function <datablock
<datablock or
or object
object name>::<callback
name>::<callback function
function name>(%this,
name>(%this, <other
<other
parameters>
parameters> ))

For the trigger you're using, the function declaration looks like
this:
function
function TeleportTriggerData::onEnterTrigger(
TeleportTriggerData::onEnterTrigger( %this,
%this, %trigger,
%trigger, %obj
%obj ))

Though it's not listed in class reference topics for callback


functions, the first parameter is always a reference to the
object (%this). In the case of the script above, %this will
point to the TeleportTriggerData datablock.
Class 10

Keeping Players in Sync

In your myServerCommands.cs, file, add the following function.


function
function beginTeleportToHiddenLocation(%cl)
beginTeleportToHiddenLocation(%cl)
{{
//
// Get
Get aa reference
reference to
to this
this client's
client's control
control object
object by
by
// using the Torque 3D getControlObject() function.
// using the Torque 3D getControlObject() function.
//
// The
The control
control object
object isis the
the player.
player.
%controlObject
%controlObject == %cl.getControlObject();
%cl.getControlObject();

//
// In
In the
the object
object that
that represents
represents the
the current
current player,
player,
//
// set
set the
the position
position property
property to
to the
the hidden
hidden location.
location.
//
// It's
It's by
by modifying
modifying the
the position
position property
property of
of the
the
//
// actual player object that you physically move
actual player object that you physically move
//
// the
the player.
player.
%controlObject.position
%controlObject.position == "2
"2 -21
-21 18"
18"
Class 10

Keeping Players in Sync

//
// Send
Send aa message
message to
to the
the client's
client's game
game window
window to
to
//
// tell
tell them
them how
how far
far they
they went.
went.
commandToClient(%cl,
commandToClient(%cl, 'ServerMessage', 'MsgClientJoin',
'ServerMessage', 'MsgClientJoin',
'You
'You were
were teleported
teleported to:
to: Best
Best Sniper
Sniper Position');
Position');
}}

In your TeleportTriggerData::onEnterTrigger callback function back in


your myServerCommands.cs file, change the following lines of script:

//
// Call
Call the
the beginTeleport()
beginTeleport() function
function to
to kick
kick off
off the
the
//
// teleportation
teleportation sequence.
sequence.
beginTeleport(%client);
beginTeleport(%client);
Class 10

Keeping Players in Sync

To the following:

//
// Call
Call the
the beginTeleportToHiddenLocation()
beginTeleportToHiddenLocation() function
function
//
// to
to kick
kick off
off the
the teleportation
teleportation sequence
sequence to
to the
the rooftop.
rooftop.
beginTeleportToHiddenLocation(%client);
beginTeleportToHiddenLocation(%client);

Now your new function will be called when the player enters the trigger
space.

Save your myServerCommands.cs file.

Start your game, enter the level, and move your character over the
teleporter pad.
Class 10

Keeping Players in Sync


Teleportation Pad in Action:
Class 10

Keeping Players in Sync

Now that you are more familiar with scripting, the


client/server architecture, and using triggers, you might
want to look at the callback functions in the following
files:
game\scripts\server\teleporter.cs This file contains
trigger callback functions, and extra helper functions.
game\art\datablocks\teleporter.cs This file contains
a datablock for a trigger, named TeleporterTrigger. It also
contains some datablocks for teleportation effects.
Class 10

Keeping Players in Sync

There are two teleportation


pads in prefabs in the
Library: GroundTeleporter
and RoofTeleporter. They
use the datablocks and
code in these files.
Class 10

Keeping Players in Sync


The triggers sit on top of the
teleportation pads.
If you create one of each prefab
and explode them you can
rename the triggers. Then you
can set the exit name for each
trigger in its dynamic fields. So
if you name one Roof and one
Ground, you can set the Roof
trigger's exit field to Ground
and the Ground trigger's exit
field to Roof to make them
teleport to each other.
Class 10

Keeping Players in Sync


In this optional exercise, you learn how to build
your game and set it up on a second computer so
that you can play with a friend and see your
teleportation commands work in a multiplayer
environment

See Lesson 6 Section 5 Set Up Another


Computer to Play Your Game in order to learn
how to test code on a single computer
Class 10

Keeping Players in Sync:


Conclusion
1. Lab:
Do ManHole exercise
Do Trigger with Callback function
Package Project and run a multiplayer session
(2 hours) Work on team project

2. Quiz: Lesson 6

3. Homework: Read Lesson 7 and review examples


Class
11
Class 11

Multiplayer Experience:
Lecture
1. Lesson 7
Cover the server instance and client instance,
Client/Server architecture, different types of
FPS players
Client/Server, onConnect(), ServerMessage,
Host, Datablocks, Properties, callback function
Customize level by iterative testing and
modifications
Create a fun level with ammo points,
teleporters, and new spawn points
Class 11

Multiplayer Experience
This lesson uses the FPS Tutorial project that you
created in Lesson 1. The template for the FPS Tutorial
project comes with Torque 3D version 1.2.

In this exercise, you will use the design information in


the next section to place ammunition .

Design your Game for Different Types of Players


Player engagement is often the key element that
determines whether a game succeeds or fails in the
marketplace.
Class 11

Multiplayer Experience
Chinatown Sniper, Choke Points, and Kill zones
Class 11

Multiplayer Experience
While dragging with the right mouse button to steer, and using the
W, A, S, D or arrow keys to move, go to the location where you want
to add your first ammunition pickup. A good starting spot is the choke
point at the South West corner of the courtyard.
Class 11

Multiplayer Experience
Open the Object Editor by using one of the following methods:
Press F1.
Or in the Editors menu, click Object Editor.
Or click the Object Editor button.
Class 11

Multiplayer Experience
Double-click the Ammo folder to display the
type of ammunition that you can place in your
scene.

The types of
ammunition that you
see in this folder were
created and added by
the FPS Tutorial level
designers.
Class 11

Multiplayer Experience
Double-click the type of ammunition
that you would like to add to the level.
For this exercise, double-click
LurkerAmmo to add the ammunition
pickup to your scene.

If you want to move the ammunition


pickup, drag one of the gizmo
handles.
Class 11

Multiplayer Experience
The gizmo appears in the Object Editor when
you select one of the transformation tools.

In the Scene Tree, in the


Scene tab, scroll to the
bottom of the list, and then
select the last Item. The
LurkerAmmo that you just
added is considered an
Item object, and is listed
last and given a default
name.
Class 11

Multiplayer Experience
Remember to press ENTER after you type in the name,
using either method.

You can make sure that all new


items that you add to your scene
will be put in this folder. To do that,
right-click your new AmmoDrops
folder, and then click Add New
Objects Here.
Class 11

Multiplayer Experience
Remember to press ENTER after you type in the
name, using either method.
Press F11 to switch from
the World Editor to Play
Game mode. You should
be equipped with the
Lurker gun by default,
but if not, press Q or roll
the mouse wheel until
you equip the Lurker
gun. Fire off a few shots.
Class 11

Multiplayer Experience
In this exercise, you will place ammunition clip
pickups in your scene.

If it is not already
selected, open the
Object Editor by
pressing F1. The Scene
Tree and Inspector
panels appear on the
right.

In the Scene Tree panel,


in the Library tab, select
the Scripted subtab if it
is not already selected.
Class 11

Multiplayer Experience
Double-click the AmmoClip folder to display the type of
ammunition clips that you can place in your scene.

Double-click the LurkerClip to add


the ammunition clip to your scene.

In the Scene Tree panel, in the


Library tab, select the Scripted
subtab if it is not already selected.
Class 11

Multiplayer Experience
If you want to move the ammunition clip pickup,
drag one of the transformation handles.
In the Scene Tree, in the Scene
tab, scroll to the bottom of the
list, and then expand your
AmmoDrops folder. The
LurkerClip that you just added
is considered an Item object,
and is listed last.

Rename Item to something with


the word "ammoClip" in it so
that you'll be able to search for
it easily in the future.
Class 11

Multiplayer Experience
To rename the item, you can select it and change the name
property in the Inspector panel, or you can double-click the
item in the Scene tree, as shown in the following images:
Class 11

Multiplayer Experience
In the Project tab, navigate to the FPS Tutorial\scripts\server
folder, and then double-click the player.cs file to open it for
editing.

Search for the Armor::onDisabled


callback function by following these steps:

Press CTRL+F to open the Find
window. Type in
Armor::onDisabled, and then click
Find Next.
Class 11

Multiplayer Experience
Type Armor::onDisabled into the Find box at the top of the
editor, and then press ENTER.

The Armor::onDisabled
callback function header is
located and highlighted for you.
Class 11

Multiplayer Experience

//
// Toss
Toss current
current mounted
mounted weapon
weapon and
and ammo
ammo if
if any.
any.
//
// First,
First, check
check for
for aa weapon
weapon by
by trying
trying to
to get
get aa weapon.
weapon.
%item
%item == %obj.getMountedImage($WeaponSlot).item;
%obj.getMountedImage($WeaponSlot).item;

//
// If
If the
the %item
%item variable
variable was
was set
set to
to an
an object
object by
by the
the
//
// preceding
preceding line,
line, then
then the
the player
player had
had aa weapon.
weapon.
if
if (isObject(%item))
(isObject(%item))
{{
//
// Check
Check for
for ammo
ammo in
in the
the same
same way
way that
that you
you checked
checked
//
// for
for aa weapon.
weapon.
%amount
%amount == %obj.getInventory(%item.image.ammo);
%obj.getInventory(%item.image.ammo);
Class 11

Multiplayer Experience

//
// If
If the
the %amount
%amount variable
variable was
was set,
set, then
then
there
there is
is
//
// ammo.
ammo.
if(%amount)
if(%amount)
{{
//
// Throw
Throw down
down the
the ammo.
ammo.
%obj.throw(%item.image.ammo,
%obj.throw(%item.image.ammo, %amount);
%amount);
}}
}}
Class 11

Multiplayer Experience

function
function Armor::onDisabled(%this,
Armor::onDisabled(%this, %obj,
%obj, %state)
%state)
{{
//
// Release
Release the
the main
main weapon
weapon trigger
trigger
%obj.setImageTrigger(0,
%obj.setImageTrigger(0, false);
false);

//
// -----------------------------------------------
-----------------------------------------------
//
// add
add this
this code
code
//
// -----------------------------------------------
-----------------------------------------------
//
// Toss
Toss current
current mounted
mounted weapon
weapon and
and ammo
ammo if
if any.
any.
//
// First,
First, check
check for
for aa weapon
weapon by
by trying
trying to
to get
get aa weapon.
weapon.
%item
%item == %obj.getMountedImage($WeaponSlot).item;
%obj.getMountedImage($WeaponSlot).item;

//
// If
If the
the %item
%item variable
variable was
was set
set to
to an
an object
object by
by the
the
//
// preceding
preceding line,
line, then
then the
the player
player had
had aa weapon.
weapon.
if
if (isObject(%item))
(isObject(%item))
{{
Class 11

Multiplayer Experience

//
// Check
Check for
for ammo
ammo in
in the
the same
same way
way that
that you
you checked
checked
//
// for
for aa weapon.
weapon.
%amount
%amount == %obj.getInventory(%item.image.ammo);
%obj.getInventory(%item.image.ammo);

//
// If
If the
the %amount
%amount variable
variable was
was set,
set, then
then there
there is
is
//
// ammo.
ammo.
if(%amount)
if(%amount)
{{
//
// Throw
Throw down
down the
the ammo.
ammo.
%obj.throw(%item.image.ammo,
%obj.throw(%item.image.ammo, %amount);
%amount);
}}
}}
Class 11

Multiplayer Experience

//
// -----------------------------------------------
-----------------------------------------------
//
// end
end add
add code
code
//
// -----------------------------------------------
-----------------------------------------------

%obj.playDeathCry();
%obj.playDeathCry();
%obj.playDeathAnimation();
%obj.playDeathAnimation();
//%obj.setDamageFlash(0.75);
//%obj.setDamageFlash(0.75);

//
// Schedule
Schedule corpse
corpse removal.
removal. Just
Just keeping
keeping the
the place
place clean.
clean.
%obj.schedule($CorpseTimeoutValue
%obj.schedule($CorpseTimeoutValue -- 1000,
1000, "startFade",
"startFade", 1000,
1000,
0,
0, true);
true);
%obj.schedule($CorpseTimeoutValue,
%obj.schedule($CorpseTimeoutValue, "delete");
"delete");
}}
Class 11

Multiplayer Experience
Select your server from the list (1), and then click Join Game (2).
Class 11

Multiplayer Experience
In the second instance of your game, move your
player to the courtyard to find the first player.
Class 11

Multiplayer Experience
The floating weapon is an ammunition pickup that is
created by the script you added to the player.cs file.
Class 11

Multiplayer Experience
Walking over the ammunition pickup will increase your
current ammunition if you have room in your inventory.
Class 11

Multiplayer Experience
To get a list of all of the objects for which you can create
these callback functions, look at the Script Manual topic
for the ShapeBaseData Class, and click the
Inheritance diagram link.
Class 11

Multiplayer Experience
All of the classes that point to ShapeBaseData have
access to the callback functions that are defined in
the ShapeBaseData class.
Class 11

Multiplayer Experience
In this exercise, you will add script that will send a boastful message to
every player when one player gets on a kill streak.

Deathmatch Victory Conditions


In the classic deathmatch game type, there are two primary types of
victory conditions:
The player has killed a set number of opposing players in the time allotted
The player has killed the most opponents in the time allotted
These two conditions are intimately tied to two concepts:
Kill count The number of opponents that the player has killed during a
deathmatch. The kill count of every player is displayed in the Score GUI that appears
when you hold the K key
Countdown timer Determines the duration of the match. The countdown timer
appears at the top of the game window, and also appears in the Score GUI
Class 11

Multiplayer Experience
In the Project tab, navigate to the FPSTutorial\scripts\server
folder, and then double-click the gameCore.cs file to open it for
editing.

Search for the GameCore::incKills function using


one of the following methods:

Press CTRL+F to open the Find window.


Type in GameCore::incKills, and then click
Find Next.
Type GameCore::incKills into the Find box
at the top of the editor, and then press
ENTER.

In the Class and Function filter dropdown


boxes at the top of the editor, select
GameCore, and incKills, respectively.
Class 11

Multiplayer Experience
The GameCore::incKills function header is located
and highlighted for you.
Class 11

Multiplayer Experience

Add the following script after the first line inside the function. It's only 6 lines of
code. The rest of the lines are comments to help you understand what's going on.

%client.lastKillCount
%client.lastKillCount +=
+= %kill;
%kill;

//
// The
The %client.lastKillDeathCount
%client.lastKillDeathCount variable
variable contains
contains the
the
//
// number of times this player had died the last time they
number of times this player had died the last time they
//
// killed
killed someone.
someone.
//
// If
If the
the client's
client's last
last death
death count
count is
is less
less than
than the
the
//
// client's
client's current
current death
death count,
count, then
then they
they have
have died
died since
since
//
// the
the last
last time
time they
they killed
killed someone,
someone, and
and they
they aren't
aren't inin
//
// the
the running
running for
for aa kill
kill streak/victory
streak/victory message.
message.
if
if (%client.lastKillDeathCount
(%client.lastKillDeathCount << %client.deaths)
%client.deaths)
Class 11

Multiplayer Experience

{{
//
// This
This player
player isn't
isn't in
in the
the running
running for
for aa kill
kill streak.
streak.
//
// So,
So, reset
reset the
the client's
client's last
last death
death count
count to
to be
be the
the
//
// client's
client's current
current death
death count,
count, in
in preparation
preparation for
for the
the
// next time they kill someone and this function
// next time they kill someone and this function is is
//
// called.
called.
%client.lastKillDeathCount
%client.lastKillDeathCount == %client.deaths;
%client.deaths;

//
// Set
Set their
their lastKillCount
lastKillCount to
to the
the number
number of
of players
players they
they
// just killed.
// just killed.
%client.lastKillCount
%client.lastKillCount == %kill;
%kill;
}}
Class 11

Multiplayer Experience

//
// If
If they
they killed
killed 2+
2+ players
players this
this time,
time, or
or 2+
2+ total
total players
players
//
// last
last time
time and
and this
this time,
time, the
the %client.lastKillCount
%client.lastKillCount will
will
//
// be
be greater
greater than
than or
or equal
equal to
to 2.
2.
if
if (%client.lastKillCount >=
(%client.lastKillCount >= 2) 2)
{{
//
// This
This player
player has
has had
had aa kill
kill streak!
streak! Send
Send the
the victory
victory
// message on the same channel as the killed message.
// message on the same channel as the killed message.
messageAll('MsgClientKilled',
messageAll('MsgClientKilled',
'%1
'%1 is
is on
on aa killing
killing streak!',
streak!',
%client.playerName);
%client.playerName);
}}
Class 11

Multiplayer Experience

function
function GameCore::incKills(%game,
GameCore::incKills(%game, %client,
%client, %kill,
%kill, %dontMessageAll)
%dontMessageAll)
{{
%client.kills
%client.kills +=
+= %kill;
%kill;

//
// Info:
Info:
//
// The
The %client
%client variable
variable is
is pointing
pointing to
to the
the player
player who
who did
did
//
// the killing.
the killing.
//
// The
The %kill
%kill variable
variable contains
contains the
the number
number of
of kills
kills this
this
//
// player
player just made, typically no more than 1 or
just made, typically no more than 1 or 2.
2.
//
// The
The %client.deaths
%client.deaths variable
variable contains
contains the
the number
number ofof times
times
//
// this player has died.
this player has died.

//
// Add
Add %kill
%kill to
to the
the client's
client's lastKillCount.
lastKillCount. This
This is
is not
not the
the
// total kill count. The %client.lastKillCount variable
// total kill count. The %client.lastKillCount variable
//
// keeps
keeps track
track of
of the
the number
number of
of players
players this
this player
player killed
killed
//
// this
this time,
time, and
and the
the last
last time
time they
they killed
killed someone.
someone.
%client.lastKillCount
%client.lastKillCount += += %kill;
%kill;
Class 11

Multiplayer Experience

//
// The
The %client.lastKillDeathCount
%client.lastKillDeathCount variable
variable contains
contains the
the
//
// number
number of
of times
times this
this player
player had
had died
died the
the last
last time
time they
they
//
// killed
killed someone.
someone.
//
// If
If the
the client's
client's last
last death
death count
count is
is less
less than
than the
the
//
// client's
client's current
current death
death count,
count, then
then they
they have
have died
died since
since
//
// the
the last time they killed someone, and they aren't in
last time they killed someone, and they aren't in
//
// the
the running
running for
for aa kill
kill streak/victory
streak/victory message.
message.
if
if (%client.lastKillDeathCount
(%client.lastKillDeathCount << %client.deaths)
%client.deaths)
{{
//
// This
This player
player isn't
isn't in
in the
the running
running for
for aa kill
kill streak.
streak.
//
// So,
So, reset
reset the
the client's
client's last
last death
death count
count to
to be
be the
the
//
// client's current death count, in preparation for the
client's current death count, in preparation for the
//
// next
next time
time they
they kill
kill someone
someone and
and this
this function
function is
is
//
// called.
called.
%client.lastKillDeathCount
%client.lastKillDeathCount == %client.deaths;
%client.deaths;
Class 11

%client.lastKillCount
%client.lastKillCount == %kill;
%kill;
}}
//
// If
If they
they killed
killed 2+2+ players
players this
this time,
time, or
or 2+
2+ total
total players
players
//
// last
last time
time and
and this
this time,
time, the
the %client.lastKillCount
%client.lastKillCount will
will
// be greater than or equal
// be greater than or equal to 2. to 2.
if
if (%client.lastKillCount
(%client.lastKillCount >= >= 2)
2)
{{
//
// This
This player
player has
has had
had aa kill
kill streak!
streak! Send
Send the
the victory
victory
// message on the same channel as the killed
// message on the same channel as the killed message.message.
messageAll('MsgClientKilled',
messageAll('MsgClientKilled',
'%1
'%1 is
is on
on aa killing
killing streak!',
streak!',
%client.playerName);
%client.playerName);
}}
if(
if( !%dontMessageAll
!%dontMessageAll ))
messageAll('MsgClientScoreChanged',
messageAll('MsgClientScoreChanged', "", "", %client.score,
%client.score, %client.kills,
%client.kills,
%client.deaths,
%client.deaths, %client);
%client);
}}
Class 11

Multiplayer Experience
Running the game to see the message:

Start the first instance of your game by double-clicking the


FPSTutorial.exe file in your game folder. If you installed Torque on
your C: drive, your game folder might be in the path, C:\Torque\Torque
3D 1.2\MyProjects\FPSTutorial\game. Open Windows Explorer by
pressing Windows Key + E, navigate to your game folder, and then
double-click the FPSTutorial.exe file

When the first instance of your game starts, click Multiplayer in the
first menu screen, and then click Host in the second menu screen

Press ALT+TAB and switch back to Windows Explorer

In Windows Explorer again, double-click the FPSTutorial.exe again


to load a second instance of your game
Class 11

Multiplayer Experience
When the second instance of your game starts, click
Multiplayer in the first menu screen, and then click
Join in the second menu screen.
Class 11

Multiplayer Experience
In this exercise, you learned how to add code to an
existing function to display a victory message in a
specific situation.
Class 11

Multiplayer Experience
Class 11

Multiplayer Experience

Open the Torque Toolbox using one of the following methods:


On the Start menu, expand the folder for the version of Torque that
you have installed, and then click Torque 3D Toolbox

Open the Object Editor by pressing F1

While dragging with the right mouse button to steer, and using the
W, A, S, D or arrow keys to move, go to the location where you want to
add a new spawn point

In the Scene Tree panel, in the Library tab, select the Level
subtab, and then select the Level folder from the dropdown box
Class 11

Multiplayer Experience

Player Spawn Point to open the drop


point dialog box.

In the Object Name field, type


FFADrop1, and then click Create
New. A new spawn point appears in
the world editor in front of you.

The prefix "FFA" stands for free-for-all, a


deathmatch gametype.
Class 11

Multiplayer Experience
You can make sure that all new items that you add to your scene will
be put in the PlayerSpawnPoints folder. To do that, right-click the
PlayerSpawnPoints folder, and then click Add New Objects Here.
Class 11

Multiplayer Experience
To place these spawn points quickly, use the
following abbreviated steps:

In the Scene Tree panel, in the Library


tab, in the Level subtab, in the Level
folder, double-click

Player Spawn Point to open the drop point


dialog box. In the Object Name field, type a
name from the table below, and then click
Create New.

With your new spawn point selected in the


Scene tab, change the position property in the
Inspector panel to the corresponding value in
the table below, and then press ENTER to lock
in the value.

The value is in three parts, for X, Y, and Z


coordinates. To move your World Camera
(CTRL+1) to the location of the selected spawn
point, press CTRL+Q.
Class 11

Multiplayer Experience:
Conclusion
Lab (2 hours):
1.
Teleport player, teleport pad, work on team project
Add Ammo Pickup points, put down 4 more ammo pickup
points in strategically fun places
Put in Deathmatch Victory Conditions and add spawn
points
2. Presentation:
Present (preview) a team level with custom teleporters and
weapon/ammo pickups
Give a preview of the level to get feedback from the class
Have team talk about the game play reasons for design of
the level
Quiz: Lesson 7
Homework: Finish Final Project
Class
12
Class 12

Team Project Presentation


1. Quiz: None
2. Lecture: Cover preparation for the final exam. What is
on the test?
3. Presentation: (3 hours)
Each team presents their level (1/2 hour each)
Modifications of the Chinatown level: Each team presents
their modification to the scripts, gameplay and artwork.
Critique of each project by peers and may include industry
judge.
Presentation done in PowerPoint the goals of the project,
what was presented at midterms, and highlights of their
final game.
4. Homework: Study for Finals
Class
13
Class 13

Finals
1. Finish Presentations
2. Lecture: Review course
3. Talk about the game industry, jobs and talk to the
students about the class. What did they get out
of it? What would they change? Did it meet their
expectations? Any recommendations on the
content or execution of the class?
4. Final Test: (2 hours)
Class 13

Copyright Info
Torque 3D 1.2 Educational Materials are provided
free of charge for educational purposes. All or part of
materials are freely distributable and use for any
individual, school, or workshop for learning and
educational purposes.

Torque 3D is a trademark and GarageGames is a


registered trademark of GarageGames, LLC. All
other trademarks or registered trademarks belong to
their respective owners.

Вам также может понравиться