Sunteți pe pagina 1din 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

3. Quiz: Lesson 4

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 = FPS 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()@-@ $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 the functions in the myScriptingTests.cs file.


// Remove this script later.

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(" ----- myScriptingTests.cs file was


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 testArgs(%myString)
{
echo(">>>>> myString = " SPC %myString SPC
"<<<<<");
}
Class 7

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 creatBarricades(%numBarricades,
%distanceApart, %startPos)
Class 7

Add the following new function to your


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

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


Class 7

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 testArray()
{
// Create the array.
$dummyText[0] = "Lorum";
$dummyText[1] = "ipsum";
$dummyText[2] = "dolor";
$dummyText[3] = "sit";
$dummyText[4] = "amet";

// Print out the array.


for (%count = 0; %count < 5; %count++)
{
Class 7

testArray();
Class 7

While Loop

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

// Remember to make whatever change necessary


// to update the counter variable!
%myNumber++;
}
}
Class 7

Scripting Part 2: Conclusion


1. Lab: Lab: Have the class run through the homework
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

2. Quiz: Scripting Part 2

3. 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


1. Lab: Lesson 3 Part 3
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
In the
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
WeaponTemplateFireSound
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
WeaponTemplateAmmo
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_Ryder.
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/managedDatablocks.cs
file you'll see that it has continued to
keep pace with your work
Class 9

datablock ItemData(Ryder : WeaponTemplateItem)


{
shapeFile =
"art/shapes/weapons/Ryder/TP_Ryder.DAE";
cameraMaxDist = "0.305344";
category = "Weapon";
class = "Weapon";
pickUpName = "Ryder pistol";
emap = "1";
image = "RyderWeaponImage";
Reticle = "crossHair";
PreviewImage = "ryder.png";
description = "Ryder"; (dont 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

Scrolldown to the
stateSound property
and select
RyderReloadSound
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 ShapeBaseImageData(RyderWeaponImage :
WeaponTemplateImage)
{
emap = "1";
shapeFile =
"art/shapes/weapons/Ryder/TP_Ryder.DAE";
shapeFileFP =
"art/shapes/weapons/Ryder/FP_Ryder.DAE";
animateOnServer = "1";
projectile = BulletProjectile;
projectileType = Projectile;
lightType = "WeaponFireLight";
lightColor = "0.992126 0.992126 0.740157 1";
ammo = "RyderAmmo";
Item = "Ryder";
Class 9

shellExitDir = "1 0.3 1";


shellExitVariance = "15";
shellVelocity = "3";
shellExitOffset = "0.15 -0.56 -0.1";
clip = "RyderClip";
projectileSpread = "0.005";
stateSound[5] = "RyderFireSound";
stateSound[1] = "RyderSwitchinSound";
stateSound[9] = "RyderReloadSound";
imageAnimPrefix = "Pistol";
imageAnimPrefixFP = "Pistol";
useEyeNode = "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 Inventory Items


Class 9

mainWeapon = Lurker;

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

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

maxInv[DeployableTurret] = 5;

maxInv[ProxMine] = 5;
Class 9

After the line mainWeapon = Lurker;


insert the following:

maxInv[Ryder] = 1;
maxInv[RyderClip] = 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\My Projects\FPS Tutorial\game\core\scripts\
server
In Torsion, with the FPS Tutorial project open, the
path is FPS Tutorial\core\scripts\server
Open the message.cs file
Class 10

Server Exercise
Look for the following messageClient function definition:

function clientCmdServerMessage(%msgType,
%msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10)
{
// ...(code removed, partial 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\My Projects\FPS Tutorial\game\core\scripts\client
In Torsion, with the FPS Tutorial project open, the path is
FPS Tutorial\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\My Projects\FPS Tutorial\game\scripts\server.
In Torsion, with the FPS Tutorial project open, the path is
FPS Tutorial\scripts\server
Open the gameCore.cs file
Look for the following GameCore::onClientEnterGame
callback function
Class 10

function GameCore::onClientEnterGame(%game, %client)


{
// ...(code removed to save space)

// Inform the client we've joined up


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

%client.score,
%client.kills,
%client.deaths,
%client.isAiControlled(),
%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\My Projects\FPS Tutorial\game\scripts\server. In
Torsion, with the FPS Tutorial project open, the path is
FPS Tutorial\scripts\server.

Open the gameCore.cs file.

Look for the following GameCore::onClientEnterGame function:


Class 10

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

// Inform the client we've joined up


messageClient(%client,
'MsgClientJoin', '\c2Welcome to the
Torque demo app %1.',
Class 10

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

Below this code at the end of the


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

// Inform all other clients of the


new arrival
messageAllExcept(%client, -1,
'MsgClientJoin', '%1 joined the game!',
%client.playerName);
} // function closing 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 GameCore::onClientEnterGame(%game, %client)


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

} // function closing 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 this code ***


// --------------------------------------------------

if(ClientGroup.getCount() > 1)
{

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

// *** Add this code ***


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

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

} // Don't forget this closing 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\My Projects\FPS tutorial\game\scripts\client
In Torsion, with the FPS Tutorial project open, the path
is FPS Tutorial\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 instance script file: myClientCommands.cs


// Companion to the server script file:
myServerCommands.cs

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

// Set a variable to pass to the function call


// that comes next...
%time = 1000; // in milliseconds

// Call the "TeleportReady" function on the server side,


// Pass in your variable, which represents a 1 second
// delay.
commandToServer('TeleportReady', %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\My Projects\FPS
Tutorial\game\scripts\server. In Torsion, with the FPS Tutorial
project open, the path is FPS Tutorial\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 serverCmdTeleportReady(%client, %time)


{

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

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

Keeping Players in Sync

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

// Get a reference to this client's control object


by
// using the Torque 3D getControlObject() function.
// The control object is the player.
%controlObject = %cl.getControlObject();
Class 10

Keeping Players in Sync

// Get the player's physical position and height.


%pos = %controlObject.position;
%height = getWord(%pos, 2);

// Add the distance to the value already in the


// height variable.
%height += %dist;

// Set %pos variable to the new position value.


%pos = setWord(%pos, 2, %height);
Class 10

Keeping Players in Sync

// In the object that represents the current player,


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

// Send a message to the client's game window to


// tell them how far they went.
commandToClient(%cl, 'ServerMessage', 'MsgClientJoin',
%msgString,
'You were teleported! Distance: %1', %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 the scripts that start it all...


exec("./client/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 your own command scripts.


exec("./client/myClientCommands.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
StreetTeleportTrigger
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 TeleportTriggerData::onEnterTrigger( %this, %trigger, %obj )


{
// Print this string to the console window.
echo( "The player has walked over the teleporter pad.");

// Get a reference to the client (ie, this player)


// from the %obj variable.
%client = %obj.getControllingClient();

// If there is none, exit this function now.


if (%client == 0) return;

// Call the beginTeleport() function to kick off the


// teleportation sequence.
beginTeleport(%client);
}
Class 10

Keeping Players in Sync

function TeleportTriggerData::onLeaveTrigger( %this, %trigger, %obj )


{
// Print this string to the console window.
echo( "The player has left the teleporter pad.");
}

// ---------------------------------------------------------
// This function is called every tickPerioMS while a player
// is within the trigger space.
// ---------------------------------------------------------
function TeleportTriggerData::onTickTrigger( %this, %trigger )
{
// Print this string to the console window.
echo( "The player is still standing on the teleporter 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 <datablock or object name>::<callback function name>(%this, <other


parameters> )

For the trigger you're using, the function declaration looks like this:

function TeleportTriggerData::onEnterTrigger( %this, %trigger, %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 beginTeleportToHiddenLocation(%cl)
{
// Get a reference to this client's control object by
// using the Torque 3D getControlObject() function.
// The control object is the player.
%controlObject = %cl.getControlObject();

// In the object that represents the current player,


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

Keeping Players in Sync

// Send a message to the client's game window to


// tell them how far they went.
commandToClient(%cl, 'ServerMessage', 'MsgClientJoin',
'You were teleported to: Best Sniper Position');
}

In your TeleportTriggerData::onEnterTrigger callback function back in your


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

// Call the beginTeleport() function to kick off the


// teleportation sequence.
beginTeleport(%client);
Class 10

Keeping Players in Sync

To the following:
// Call the beginTeleportToHiddenLocation() function
// to kick off the teleportation sequence to the rooftop.
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 current mounted weapon and ammo if any.


// First, check for a weapon by trying to get a weapon.
%item = %obj.getMountedImage($WeaponSlot).item;

// If the %item variable was set to an object by the


// preceding line, then the player had a weapon.
if (isObject(%item))
{
// Check for ammo in the same way that you checked
// for a weapon.
%amount = %obj.getInventory(%item.image.ammo);
Class 11

Multiplayer Experience

// If the %amount variable was set, then


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

Multiplayer Experience

function Armor::onDisabled(%this, %obj, %state)


{
// Release the main weapon trigger
%obj.setImageTrigger(0, false);

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

// If the %item variable was set to an object by the


// preceding line, then the player had a weapon.
if (isObject(%item))
{
Class 11

Multiplayer Experience

// Check for ammo in the same way that you checked


// for a weapon.
%amount = %obj.getInventory(%item.image.ammo);

// If the %amount variable was set, then there is


// ammo.
if(%amount)
{
// Throw down the ammo.
%obj.throw(%item.image.ammo, %amount);
}
}
Class 11

Multiplayer Experience

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

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

// Schedule corpse removal. Just keeping the place clean.


%obj.schedule($CorpseTimeoutValue - 1000, "startFade", 1000,
0, true);
%obj.schedule($CorpseTimeoutValue, "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 FPS Tutorial\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 += %kill;

// The %client.lastKillDeathCount variable contains the


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

Multiplayer Experience

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

// Set their lastKillCount to the number of players they


// just killed.
%client.lastKillCount = %kill;
}
Class 11

Multiplayer Experience

// If they killed 2+ players this time, or 2+ total players


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

Multiplayer Experience

function GameCore::incKills(%game, %client, %kill, %dontMessageAll)


{
%client.kills += %kill;

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

// Add %kill to the client's lastKillCount. This is not the


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

Multiplayer Experience

// The %client.lastKillDeathCount variable contains the


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

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

Multiplayer Experience
Running the game to see the message:

Start the first instance of your game by double-clicking the FPS Tutorial.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\My Projects\FPS Tutorial\game. Open Windows Explorer by pressing
Windows Key + E, navigate to your game folder, and then double-click the
FPS Tutorial.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 FPS Tutorial.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
1. Lab (2 hours):
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
3. Quiz: Lesson 7
4. 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.

S-ar putea să vă placă și