mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-13 11:43:49 +00:00
Cleans up the ExampleModule to have up-to-date examples of module init'ing, game modes, levels and basic input logic
Cleans up prototyping module to trim unneeded extra scripts and files Adds PlayerBot model to Prototyping module Adds metalGray material to Prototyping module Fixes issue where logic wasn't changed for forcing AB preview images to regenerate Removes unneeded legacy lines from editor template level Removes unneeded extra asset import config Disables terrain material name field from editing in terrain material editor for now to prevent bad behavior Adds mapTo line to newly created material asset definitions to ensure shapes doing mapTo lookups can properly utilize the materials
This commit is contained in:
parent
e896e663d4
commit
27b20c14d7
98 changed files with 1337 additions and 1725 deletions
|
|
@ -1,6 +0,0 @@
|
|||
<ScriptAsset
|
||||
canSave="true"
|
||||
canSaveDynamicFields="true"
|
||||
AssetName="ExampleGamemodeScript"
|
||||
scriptFile="@assetFile=ExampleGamemodeScript.cs"
|
||||
VersionId="1" />
|
||||
|
|
@ -1,156 +0,0 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// The server has started up so do some game start up
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//This file implements game mode logic for an Example gamemode. The primary functions:
|
||||
//ExampleGameMode::onMissionStart
|
||||
//ExampleGameMode::onMissionReset
|
||||
//ExampleGameMode::onMissionEnd
|
||||
//Are the primary hooks for the server to start, restart and end any active gamemodes
|
||||
//onMissionStart, for example is called from core/clientServer/scripts/server/levelLoad.tscript
|
||||
//It's called once the server has successfully loaded the level, and has parsed
|
||||
//through any active scenes to get GameModeNames defined by them. It then iterates
|
||||
//over them and calls these callbacks to envoke gamemode behaviors. This allows multiple
|
||||
//gamemodes to be in effect at one time. Modules can implement as many gamemodes as you want.
|
||||
//
|
||||
//For levels that can be reused for multiple gammodes, the general setup would be a primary level file
|
||||
//with the Scene in it having the main geometry, weapons, terrain, etc. You would then have subScenes that
|
||||
//each contain what's necessary for the given gamemode, such as a subScene that just adds the flags and capture
|
||||
//triggers for a CTF mode. The subscene would then have it's GameModeName defined to run the CTF gamemode logic
|
||||
//and the levelLoad code will execute it.
|
||||
|
||||
function ExampleGameMode::onCreateGame()
|
||||
{
|
||||
// Note: The Game object will be cleaned up by MissionCleanup. Therefore its lifetime is
|
||||
// limited to that of the mission.
|
||||
new ScriptObject(ExampleGameMode){};
|
||||
|
||||
return ExampleGameMode;
|
||||
}
|
||||
|
||||
//This function is called when the level finishes loading. It sets up the initial configuration, variables and
|
||||
//spawning and dynamic objects, timers or rules needed for the gamemode to run
|
||||
function ExampleGameMode::onMissionStart(%this)
|
||||
{
|
||||
//set up the game and game variables
|
||||
%this.initGameVars();
|
||||
|
||||
if (%this.running)
|
||||
{
|
||||
error("onMissionStart: End the game first!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Start the game timer
|
||||
if (%this.duration)
|
||||
%this.gameSchedule = schedule(%this.duration * 1000, 0, "onGameDurationEnd");
|
||||
|
||||
%this.running = true;
|
||||
}
|
||||
|
||||
//This function is called when the level ends. It can be envoked due to the gamemode ending
|
||||
//but is also kicked off when the game server is shut down as a form of cleanup for anything the gamemode
|
||||
//created or is managing like the above mentioned dynamic objects or timers
|
||||
function ExampleGameMode::onMissionEnded(%this)
|
||||
{
|
||||
if (!%this.running)
|
||||
{
|
||||
error("onMissionEnded: No game running!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Stop any game timers
|
||||
cancel(%this.gameSchedule);
|
||||
|
||||
%this.running = false;
|
||||
}
|
||||
|
||||
//This function is called in the event the server resets and is used to re-initialize the gamemode
|
||||
function ExampleGameMode::onMissionReset(%this)
|
||||
{
|
||||
// Called by resetMission(), after all the temporary mission objects
|
||||
// have been deleted.
|
||||
%this.initGameVars();
|
||||
}
|
||||
|
||||
//This sets up our gamemode's duration time
|
||||
function ExampleGameMode::initGameVars(%this)
|
||||
{
|
||||
// Set the gameplay parameters
|
||||
%this.duration = 30 * 60;
|
||||
}
|
||||
|
||||
//This is called when the timer runs out, allowing the gamemode to end
|
||||
function ExampleGameMode::onGameDurationEnd(%this)
|
||||
{
|
||||
//we don't end if we're currently editing the level
|
||||
if (%this.duration && !(EditorIsActive() && GuiEditorIsActive()))
|
||||
%this.onMissionEnded();
|
||||
}
|
||||
|
||||
//This is called to actually spawn a control object for the player to utilize
|
||||
//A player character, spectator camera, etc.
|
||||
function ExampleGameMode::spawnControlObject(%this, %client)
|
||||
{
|
||||
//In this example, we just spawn a camera
|
||||
if (!isObject(%client.camera))
|
||||
{
|
||||
if(!isObject(Observer))
|
||||
{
|
||||
datablock CameraData(Observer)
|
||||
{
|
||||
mode = "Observer";
|
||||
};
|
||||
}
|
||||
|
||||
%client.camera = spawnObject("Camera", Observer);
|
||||
}
|
||||
|
||||
// If we have a camera then set up some properties
|
||||
if (isObject(%client.camera))
|
||||
{
|
||||
MissionCleanup.add( %this.camera );
|
||||
%client.camera.scopeToClient(%client);
|
||||
|
||||
%client.setControlObject(%client.camera);
|
||||
|
||||
%client.camera.setTransform("0 0 1 0 0 0 0");
|
||||
}
|
||||
}
|
||||
|
||||
//This is called when the client has initially established a connection to the game server
|
||||
//It's used for setting up anything ahead of time for the client, such as loading in client-passed
|
||||
//config stuffs, saved data or the like that should be handled BEFORE the client has actually entered
|
||||
//the game itself
|
||||
function ExampleGameMode::onClientConnect(%this, %client)
|
||||
{
|
||||
}
|
||||
|
||||
//This is called when a client enters the game server. It's used to spawn a player object
|
||||
//set up any client-specific properties such as saved configs, values, their name, etc
|
||||
//These callbacks are activated in core/clientServer/scripts/server/levelDownload.tscript
|
||||
function ExampleGameMode::onClientEnterGame(%this, %client)
|
||||
{
|
||||
//Set the player name based on the client's connection data
|
||||
%client.setPlayerName(%client.connectData);
|
||||
|
||||
%this.spawnControlObject(%client);
|
||||
}
|
||||
|
||||
//This is called when the player leaves the game server. It's used to clean up anything that
|
||||
//was spawned or setup for the client when it connected, in onClientEnterGame
|
||||
//These callbacks are activated in core/clientServer/scripts/server/levelDownload.tscript
|
||||
function ExampleGameMode::onClientLeaveGame(%this, %client)
|
||||
{
|
||||
// Cleanup the camera
|
||||
if (isObject(%client.camera))
|
||||
%client.camera.delete();
|
||||
}
|
||||
|
||||
//This is called when the player has connected and finaly setup is done and control is handed
|
||||
//over to the client. It allows a point to special-case setting the client's canvas content
|
||||
//(Such as a gamemode-specific GUI) or setting up gamemode-specific keybinds/control schemes
|
||||
function ExampleGameMode::onInitialControlSet(%this)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -1,25 +1,3 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$RemapName[$RemapCount] = "Forward";
|
||||
$RemapCmd[$RemapCount] = "moveforward";
|
||||
$RemapActionMap[$RemapCount] = "ExampleMoveMap";
|
||||
|
|
@ -92,21 +70,9 @@ ExampleMoveMap.humanReadableName = "Example Movement";
|
|||
// Non-remapable binds
|
||||
//------------------------------------------------------------------------------
|
||||
ExampleMoveMap.bind( keyboard, F2, showPlayerList );
|
||||
|
||||
ExampleMoveMap.bind(keyboard, "ctrl h", hideHUDs);
|
||||
|
||||
ExampleMoveMap.bind(keyboard, "alt p", doScreenShotHudless);
|
||||
|
||||
function openPauseMenu(%val)
|
||||
{
|
||||
if(%val && PauseMenu.isAwake() == false)
|
||||
{
|
||||
echo("PUSHING PAUSE MENU");
|
||||
Canvas.pushDialog(PauseMenu);
|
||||
}
|
||||
}
|
||||
|
||||
ExampleMoveMap.bind(keyboard, "escape", openPauseMenu);
|
||||
ExampleMoveMap.bindCmd(keyboard, "escape", "", "Canvas.pushDialog(PauseMenu);");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Movement Keys
|
||||
|
|
@ -128,21 +94,27 @@ ExampleMoveMap.bind( keyboard, space, jump );
|
|||
ExampleMoveMap.bind( mouse, xaxis, yaw );
|
||||
ExampleMoveMap.bind( mouse, yaxis, pitch );
|
||||
|
||||
ExampleMoveMap.bind( gamepad, rxaxis, "D", "-0.23 0.23", gamepadYaw );
|
||||
ExampleMoveMap.bind( gamepad, ryaxis, "D", "-0.23 0.23", gamepadPitch );
|
||||
ExampleMoveMap.bind( gamepad, xaxis, "D", "-0.23 0.23", gamePadMoveX );
|
||||
ExampleMoveMap.bind( gamepad, yaxis, "D", "-0.23 0.23", gamePadMoveY );
|
||||
ExampleMoveMap.bind( gamepad, thumbrx, "D", "-0.23 0.23", gamepadYaw );
|
||||
ExampleMoveMap.bind( gamepad, thumbry, "D", "-0.23 0.23", gamepadPitch );
|
||||
ExampleMoveMap.bind( gamepad, thumblx, "D", "-0.23 0.23", gamePadMoveX );
|
||||
ExampleMoveMap.bind( gamepad, thumbly, "D", "-0.23 0.23", gamePadMoveY );
|
||||
|
||||
ExampleMoveMap.bind( gamepad, btn_a, jump );
|
||||
ExampleMoveMap.bind( gamepad, btn_x, moveup );
|
||||
ExampleMoveMap.bind( gamepad, btn_y, movedown );
|
||||
ExampleMoveMap.bindCmd( gamepad, btn_start, "Canvas.pushDialog(PauseMenu);", "" );
|
||||
ExampleMoveMap.bindCmd( gamepad, btn_back, "disconnect();", "" );
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Demo recording functions
|
||||
//------------------------------------------------------------------------------
|
||||
ExampleMoveMap.bind( keyboard, F3, startRecordingDemo );
|
||||
ExampleMoveMap.bind( keyboard, F4, stopRecordingDemo );
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helper Functions
|
||||
//------------------------------------------------------------------------------
|
||||
GlobalActionMap.bind(keyboard, "ctrl F3", doProfile);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Misc.
|
||||
//------------------------------------------------------------------------------
|
||||
GlobalActionMap.bind(keyboard, "tilde", toggleConsole);
|
||||
GlobalActionMap.bindCmd(keyboard, "alt k", "cls();","");
|
||||
GlobalActionMap.bindCmd(keyboard, "alt enter", "", "Canvas.toggleFullscreen();");
|
||||
GlobalActionMap.bindCmd(keyboard, "F1", "", "contextHelp();");
|
||||
ExampleMoveMap.bindCmd(keyboard, "n", "toggleNetGraph();", "");
|
||||
|
|
@ -1,29 +1,35 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
function escapeFromGame()
|
||||
{
|
||||
disconnect();
|
||||
}
|
||||
|
||||
function showPlayerList(%val)
|
||||
{
|
||||
if (%val)
|
||||
PlayerListGui.toggle();
|
||||
}
|
||||
|
||||
function hideHUDs(%val)
|
||||
{
|
||||
if (%val)
|
||||
HudlessPlayGui.toggle();
|
||||
}
|
||||
|
||||
function doScreenShotHudless(%val)
|
||||
{
|
||||
if(%val)
|
||||
{
|
||||
canvas.setContent(HudlessPlayGui);
|
||||
//doScreenshot(%val);
|
||||
schedule(10, 0, "doScreenShot", %val);
|
||||
}
|
||||
else
|
||||
{
|
||||
%playGUIName = ProjectSettings.value("UI/playGUIName");
|
||||
Canvas.setContent(%playGUIName);
|
||||
}
|
||||
}
|
||||
|
||||
$movementSpeed = 1; // m/s
|
||||
|
||||
function setSpeed(%speed)
|
||||
|
|
@ -147,8 +153,6 @@ function gamePadMoveX( %val )
|
|||
|
||||
function gamePadMoveY( %val )
|
||||
{
|
||||
%val *= -1;
|
||||
|
||||
if(%val > 0)
|
||||
{
|
||||
$mvForwardAction = %val * $movementSpeed;
|
||||
|
|
@ -185,8 +189,6 @@ function gamepadYaw(%val)
|
|||
|
||||
function gamepadPitch(%val)
|
||||
{
|
||||
%val *= -1;
|
||||
|
||||
%pitchAdj = getGamepadAdjustAmount(%val);
|
||||
if(ServerConnection.isControlObjectRotDampedCamera())
|
||||
{
|
||||
|
|
@ -205,4 +207,118 @@ function gamepadPitch(%val)
|
|||
$mvPitchDownSpeed = 0;
|
||||
$mvPitchUpSpeed = -%pitchAdj;
|
||||
}
|
||||
}
|
||||
|
||||
function toggleZoomFOV()
|
||||
{
|
||||
$Player::CurrentFOV = $Player::CurrentFOV / 2;
|
||||
|
||||
if($Player::CurrentFOV < 5)
|
||||
resetCurrentFOV();
|
||||
|
||||
if(ServerConnection.zoomed)
|
||||
setFOV($Player::CurrentFOV);
|
||||
else
|
||||
{
|
||||
setFov(ServerConnection.getControlCameraDefaultFov());
|
||||
}
|
||||
}
|
||||
|
||||
function resetCurrentFOV()
|
||||
{
|
||||
$Player::CurrentFOV = ServerConnection.getControlCameraDefaultFov() / 2;
|
||||
}
|
||||
|
||||
function turnOffZoom()
|
||||
{
|
||||
ServerConnection.zoomed = false;
|
||||
setFov(ServerConnection.getControlCameraDefaultFov());
|
||||
Reticle.setVisible(true);
|
||||
zoomReticle.setVisible(false);
|
||||
|
||||
// Rather than just disable the DOF effect, we want to set it to the level's
|
||||
// preset values.
|
||||
//DOFPostEffect.disable();
|
||||
ppOptionsUpdateDOFSettings();
|
||||
}
|
||||
|
||||
function setZoomFOV(%val)
|
||||
{
|
||||
if(%val)
|
||||
toggleZoomFOV();
|
||||
}
|
||||
|
||||
function toggleZoom(%val)
|
||||
{
|
||||
if (%val)
|
||||
{
|
||||
ServerConnection.zoomed = true;
|
||||
setFov($Player::CurrentFOV);
|
||||
Reticle.setVisible(false);
|
||||
zoomReticle.setVisible(true);
|
||||
|
||||
DOFPostEffect.setAutoFocus( true );
|
||||
DOFPostEffect.setFocusParams( 0.5, 0.5, 50, 500, -5, 5 );
|
||||
DOFPostEffect.enable();
|
||||
}
|
||||
else
|
||||
{
|
||||
turnOffZoom();
|
||||
}
|
||||
}
|
||||
|
||||
function mouseButtonZoom(%val)
|
||||
{
|
||||
toggleZoom(%val);
|
||||
}
|
||||
|
||||
function startRecordingDemo( %val )
|
||||
{
|
||||
if ( %val )
|
||||
startDemoRecord();
|
||||
}
|
||||
|
||||
function stopRecordingDemo( %val )
|
||||
{
|
||||
if ( %val )
|
||||
stopDemoRecord();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Debugging Functions
|
||||
//------------------------------------------------------------------------------
|
||||
function showMetrics(%val)
|
||||
{
|
||||
if(%val)
|
||||
{
|
||||
if(!Canvas.isMember(FrameOverlayGui))
|
||||
metrics("fps gfx shadow sfx terrain groundcover forest net");
|
||||
else
|
||||
metrics("");
|
||||
}
|
||||
}
|
||||
GlobalActionMap.bind(keyboard, "ctrl F2", showMetrics);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// Start profiler by pressing ctrl f3
|
||||
// ctrl f3 - starts profile that will dump to console and file
|
||||
//
|
||||
function doProfile(%val)
|
||||
{
|
||||
if (%val)
|
||||
{
|
||||
// key down -- start profile
|
||||
echo("Starting profile session...");
|
||||
profilerReset();
|
||||
profilerEnable(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// key up -- finish off profile
|
||||
echo("Ending profile session...");
|
||||
|
||||
profilerDumpToFile("profilerDumpToFile" @ getSimTime() @ ".txt");
|
||||
profilerEnable(false);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,237 @@
|
|||
function ExampleGameMode::onCreateGame()
|
||||
{
|
||||
// Note: The Game object will be cleaned up by MissionCleanup. Therefore its lifetime is
|
||||
// limited to that of the mission.
|
||||
new ScriptObject(ExampleGameMode){};
|
||||
|
||||
return ExampleGameMode;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The server has started up so do some game start up
|
||||
//-----------------------------------------------------------------------------
|
||||
function ExampleGameMode::onMissionStart(%this)
|
||||
{
|
||||
//set up the game and game variables
|
||||
%this.initGameVars();
|
||||
|
||||
if (%this.Running)
|
||||
{
|
||||
error("onMissionStart: End the game first!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Inform the client we're starting up
|
||||
for (%clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++)
|
||||
{
|
||||
%cl = ClientGroup.getObject(%clientIndex);
|
||||
commandToClient(%cl, 'GameStart');
|
||||
}
|
||||
|
||||
%this.Running = true;
|
||||
}
|
||||
|
||||
function ExampleGameMode::onMissionEnded(%this)
|
||||
{
|
||||
if (!%this.Running)
|
||||
{
|
||||
error("onMissionEnded: No game running!");
|
||||
return;
|
||||
}
|
||||
|
||||
for (%clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++)
|
||||
{
|
||||
%cl = ClientGroup.getObject(%clientIndex);
|
||||
commandToClient(%cl, 'GameEnd', %this.EndGamePause);
|
||||
}
|
||||
|
||||
%this.Running = false;
|
||||
}
|
||||
|
||||
function ExampleGameMode::onMissionReset(%this)
|
||||
{
|
||||
// Called by resetMission(), after all the temporary mission objects
|
||||
// have been deleted.
|
||||
%this.initGameVars();
|
||||
}
|
||||
|
||||
function ExampleGameMode::initGameVars(%this)
|
||||
{
|
||||
//-----------------------------------------------------------------------------
|
||||
// What kind of "camera" is spawned is either controlled directly by the
|
||||
// SpawnSphere or it defaults back to the values set here. This also controls
|
||||
// which SimGroups to attempt to select the spawn sphere's from by walking down
|
||||
// the list of SpawnGroups till it finds a valid spawn object.
|
||||
// These override the values set in core/scripts/server/spawn.cs
|
||||
//-----------------------------------------------------------------------------
|
||||
%this.defaultCameraClass = "Camera";
|
||||
%this.defaultCameraDataBlock = "Observer";
|
||||
%this.defaultCameraSpawnGroups = "CameraSpawnPoints PlayerSpawnPoints PlayerDropPoints";
|
||||
}
|
||||
|
||||
function ExampleGameMode::onGameDurationEnd(%this)
|
||||
{
|
||||
}
|
||||
|
||||
function ExampleGameMode::onClientEnterGame(%this, %client)
|
||||
{
|
||||
// This function currently relies on some helper functions defined in
|
||||
// core/scripts/spawn.cs. For custom spawn behaviors one can either
|
||||
// override the properties on the SpawnSphere's or directly override the
|
||||
// functions themselves.
|
||||
|
||||
//echo (%game @"\c4 -> "@ %game.class @" -> GameCore::onClientEntergame");
|
||||
|
||||
// Sync the client's clocks to the server's
|
||||
commandToClient(%client, 'SyncClock', $Sim::Time - %this.StartTime);
|
||||
|
||||
//Set the player name based on the client's connection data
|
||||
%client.setPlayerName(%client.connectData);
|
||||
|
||||
// Find a spawn point for the camera
|
||||
// This function currently relies on some helper functions defined in
|
||||
// core/scripts/server/spawn.cs. For custom spawn behaviors one can either
|
||||
// override the properties on the SpawnSphere's or directly override the
|
||||
// functions themselves.
|
||||
%cameraSpawnPoint = %this.pickCameraSpawnPoint(%this.DefaultCameraSpawnGroups);
|
||||
// Spawn a camera for this client using the found %spawnPoint
|
||||
%this.spawnCamera(%client, %cameraSpawnPoint);
|
||||
|
||||
// Inform the client of all the other clients
|
||||
%count = ClientGroup.getCount();
|
||||
for (%cl = 0; %cl < %count; %cl++)
|
||||
{
|
||||
%other = ClientGroup.getObject(%cl);
|
||||
if ((%other != %client))
|
||||
{
|
||||
// These should be "silent" versions of these messages...
|
||||
messageClient(%client, 'MsgClientJoin', "",
|
||||
%other.playerName,
|
||||
%other,
|
||||
%other.sendGuid,
|
||||
%other.team,
|
||||
%other.score,
|
||||
%other.kills,
|
||||
%other.deaths,
|
||||
%other.isAIControlled(),
|
||||
%other.isAdmin,
|
||||
%other.isSuperAdmin);
|
||||
}
|
||||
}
|
||||
|
||||
// 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.score,
|
||||
%client.kills,
|
||||
%client.deaths,
|
||||
%client.isAiControlled(),
|
||||
%client.isAdmin,
|
||||
%client.isSuperAdmin);
|
||||
|
||||
// Inform all the other clients of the new guy
|
||||
messageAllExcept(%client, -1, 'MsgClientJoin', '\c1%1 joined the game.',
|
||||
%client.playerName,
|
||||
%client,
|
||||
%client.sendGuid,
|
||||
%client.team,
|
||||
%client.score,
|
||||
%client.kills,
|
||||
%client.deaths,
|
||||
%client.isAiControlled(),
|
||||
%client.isAdmin,
|
||||
%client.isSuperAdmin);
|
||||
}
|
||||
|
||||
function ExampleGameMode::onClientLeaveGame(%this, %client)
|
||||
{
|
||||
// Cleanup the camera
|
||||
if (isObject(%client.camera))
|
||||
%client.camera.delete();
|
||||
}
|
||||
|
||||
function ExampleGameMode::onInitialControlSet(%this)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
function ExampleGameMode::spawnCamera(%this, %client, %spawnPoint)
|
||||
{
|
||||
// Set the control object to the default camera
|
||||
if (!isObject(%client.camera))
|
||||
{
|
||||
if (%this.defaultCameraClass !$= "")
|
||||
%client.camera = spawnObject(%this.defaultCameraClass, %this.defaultCameraDataBlock);
|
||||
}
|
||||
|
||||
// If we have a camera then set up some properties
|
||||
if (isObject(%client.camera))
|
||||
{
|
||||
MissionCleanup.add( %client.camera );
|
||||
%client.camera.scopeToClient(%client);
|
||||
|
||||
%client.setControlObject(%client.camera);
|
||||
|
||||
if(!isObject(%spawnPoint))
|
||||
%spawnPoint = %this.pickCameraSpawnPoint(%this.defaultCameraSpawnGroups);
|
||||
|
||||
if (isObject(%spawnPoint))
|
||||
{
|
||||
// Attempt to treat %spawnPoint as an object
|
||||
if (getWordCount(%spawnPoint) == 1 && isObject(%spawnPoint))
|
||||
{
|
||||
%client.camera.setTransform(%spawnPoint.getTransform());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Treat %spawnPoint as an AxisAngle transform
|
||||
%client.camera.setTransform(%spawnPoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// pickCameraSpawnPoint() is responsible for finding a valid spawn point for a
|
||||
// camera.
|
||||
//-----------------------------------------------------------------------------
|
||||
function ExampleGameMode::pickCameraSpawnPoint(%this, %spawnGroups)
|
||||
{
|
||||
// Walk through the groups until we find a valid object
|
||||
for (%i = 0; %i < getWordCount(%spawnGroups); %i++)
|
||||
{
|
||||
%group = getWord(%spawnGroups, %i);
|
||||
|
||||
%count = getWordCount(%group);
|
||||
|
||||
if (isObject(%group))
|
||||
%spawnPoint = %group.getRandom();
|
||||
|
||||
if (isObject(%spawnPoint))
|
||||
return %spawnPoint;
|
||||
}
|
||||
|
||||
// Didn't find a spawn point by looking for the groups
|
||||
// so let's return the "default" SpawnSphere
|
||||
// First create it if it doesn't already exist
|
||||
if (!isObject(DefaultCameraSpawnSphere))
|
||||
{
|
||||
%spawn = new SpawnSphere(DefaultCameraSpawnSphere)
|
||||
{
|
||||
dataBlock = "SpawnSphereMarker";
|
||||
spawnClass = $Game::DefaultCameraClass;
|
||||
spawnDatablock = $Game::DefaultCameraDataBlock;
|
||||
};
|
||||
|
||||
// Add it to the MissionCleanup group so that it
|
||||
// doesn't get saved to the Mission (and gets cleaned
|
||||
// up of course)
|
||||
MissionCleanup.add(%spawn);
|
||||
}
|
||||
|
||||
return DefaultCameraSpawnSphere;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue