Anatomy of a GameType, volume 5, setting up the new gameType

Anatomy of a GameType, volume 5, setting up the new gameType

Gibby
Posts: 72
Joined: Wed Feb 11, 2015 2:40 pm
Creating a new gameType

T3D by default has its game funtionality built into gameCore.cs and all other gameTypes inherit or are 'parented' to it.
One little trick I use to make my game modder-friendly is to setup a folder for new gameTypes that is auto-executed. This allows modders to simply save a new gameType as a torque script in this folder and the new type will be in-game. Thus,

In server/scriptExec.cs at line 57:
// Load our gametypes
exec("./gameCore.cs"); // This is the 'core' of the gametype functionality.
exec("./gameDM.cs"); // Overrides GameCore with DeathMatch functionality.

Becomes:
// Game files
exec("./gameCore.cs"); // Parent to all, want this loaded first
%search = "./gameType/game*.cs";
for(%file = findFirstFile(%search); %file !$= ""; %file = findNextFile(%search)) { %type = fileBase(%file); if(%type !$= gameCore)
exec("./gameType/" @ %type @ ".cs");
}
Now anything in server/gameType will be autoexec'd. You'll likely need to add some checks and balances in there for a released game to prevent cheating but for now we can quickly develop our new gameType.

Next, I move gameDM.cs to this new folder, and create another script this one called gameNAR.cs, for our 'Narrative' gameType.
I copy the contents of gameDM.cs and paste them into gameNAR.cs, and then use the 'replace' function in my editor to replace any instance of 'deathmatch' with 'narrative' and gameDM with gameNAR.

What makes most gameTypes different from each other is scoring, spawning and dying. So what I'm going to do is copy some functions from our parent gameCore, paste them into gameNAR.cs and then modify them to suit my new gameType. For now these functions are:

startGame
onClientEnterGame
preparePlayer
onDeath

To make a mission use the new gameType, I add this line to theLevelInfo at the top of the .mis file:
gameType = "Narrative"; //Gibby added
levelName = "Ice Cubes";

Now I have a new gameType, identical to deathmatch. After testing my new script to make sure it all works, I start with the real modding.

In preparation for making my project feel like a 'game', I added two resources to the stock code:

Walkable Shapes

guiOnObject

Now players can stand on moving platforms, and can use guis to flip 'switches' that are built into the level - very basic stuff but the kind of things any real game should have. As I explained in an earlier installment, my concept is to have players spawn mounted to a submarine, which dives under the Polar ice. Once near the objective the sub will surface, breaking through the polar icecap and disembark the player(s). They will then play through the three objectives seeking the 'MacGuffin'. Once found, they will have to find their way back to the sub and get to safety, winning the game. I began by creating a level using stock models and the sketch tool. I used vehicle models as the PathShapes so I could see my paths in action.

Once the functionality is in place, I will replace the pathShapes with aiVehicles but for now they're simple moving shapes. I setup quite a few of them in multiple areas of the level - underwater, water level, ground level, aerial and orbital. From script I can start/stop these pathshapes and even give them rudimentary behaviours. For now I've created two simple scripts that will launch two subs, an aircraft carrier and a destroyer and have them orbit the objectives. I then execute the scripts in the startGame function;
function NarrativeGame::startGame(%game)
{
...
fleetWar();
subWar();
}
Now once the level is loaded, there will be ships out on the ocean just on the periphery of the players vision.

One of the paths I setup generates a submarine called 'IceSub'. In my new preparePlayer function, I replace the stock line:

Stock:
%playerSpawnPoint = pickPlayerSpawnPoint(\$Game::DefaultPlayerSpawnGroups);
// Spawn a camera for this client using the found %spawnPoint
//%client.spawnPlayer(%playerSpawnPoint);
%game.spawnPlayer(%client, %playerSpawnPoint);

// Starting equipment
%game.loadOut(%client.player);
Narrative:
// Gibby: Need to add the ability to have multiple spawn types
// For now we're just testing this one:
if(!isObject(IceSub))
{
%playerSpawnPoint = pickPlayerSpawnPoint(%group);
// Spawn a camera for this client using the found %spawnPoint
//%client.spawnPlayer(%playerSpawnPoint);
%game.spawnPlayer(%client, %playerSpawnPoint, false);

// Starting equipment
%client.setControlObject(%client.player);
}
else
{
echo(">>>gameNAR.cs->NarrativeGame::onClientEnterGame, IceSub exists. ");

%playerSpawnPoint = IceSub.getPosition();
// Spawn a camera for this client using the found %spawnPoint
//%client.spawnPlayer(%playerSpawnPoint);
%game.spawnPlayer(%client, %playerSpawnPoint, false);

// Starting equipment
%client.setControlObject(%client.player);
IceSub.mountObject(%client.player, 0);
//for now this will only work single player
IceSub.player = %client.player;
}
echo("gameNAR.cs->preparePlayer Player is "@%client.player@ " spawned at: " @%playerSpawnPoint@ " Client ID: "@%client@ " Team #: " @%client.player.team@ " Class: "@%client.playerClass.playerClassName);
Before testing the game/level, I added player spawnpoints at the position my sub would disembark players at. Just in case something goes wrong, I can still spawn in game. If there are no errors, my player will spawn in a sub about a mile away from the objective. I'm still testing this to see how long the first submarine ride should be. I want it long enough for the player to hear a voice message from the commander, in the fashion of the original 'Halo' opening scene. I'll tinker with this untill the ride is long enough to hear the message but still short enough to get players into the action without getting bored first.

Here's a video sketch of our narrativeGame in action.

As you see, I have some rendering issues with the pathShapes being underwater and having a staticShape mounted to it, and our player mounted to that. While I'll be replacing these with vehicles that don't have rendering issues, this is an issue I'll address at some point. Despite the glitches, I've added some drama to my fps by forcing players into my story's plot as they enter the game, and by adding simple dynamic movement in the background, having increased the immersion of my level without too much of a performance loss...

..stay tuned, more vehicles coming...

Who is online

Users browsing this forum: No registered users and 12 guests