Game Development Community

Character Selection screen

by Jason Wee · in Torque Game Engine · 01/22/2011 (7:43 am) · 1 replies

I use the code from http://www.garagegames.com/community/resources/view/11733 but i can't seems to make it work on starter.fps (TGE 1.5.2). Can anyone help me please? What i did is shown below.

I just want a simple character selection screen that allow players to choose the model they want to play as.



In game.cs:

<code>
function GameConnection::createPlayer(%this, %spawnPoint)
{
if (%this.player > 0) {
// The client should not have a player currently
// assigned. Assigning a new one could result in
// a player ghost.
error( "Attempting to create an angus ghost!" );
}


switch ($playerClass)
{
// Class 1
case 1:
%classDatablock = PlayerBody; // change to another datablock for new models

// Class 2
case 2:
%classDatablock = PlayerBody2;

}


// Create the player object
%player = new Player() {
dataBlock = %classDatablock;
client = %this;
};
MissionCleanup.add(%player);

// Player setup...
%player.setTransform(%spawnPoint);
%player.setShapeName(%this.name);

// Starting equipment
//%player.setInventory(Crossbow,1);
//%player.setInventory(CrossbowAmmo,10);
//%player.mountImage(CrossbowImage,0);

// Update the camera to start with the player
%this.camera.setTransform(%player.getEyeTransform());

// Give the client control of the player
%this.player = %player;
%this.setControlObject(%player);
}



function GameConnection::joinPlayerClass(%this, %classid)
{
if (%classid > 2 || %classid < 0) //We only have 2 player classes
return false;

if (%this.respawn == 1)
return false; // If player is spawning then dont spawn again!

if (%classid == 1)
$playerClass = "1";

if (%classid == 2)
$playerClass = "2";

%this.spawnPlayer(%this);
}
</code>

In player.cs:
<code>

datablock PlayerData(PlayerBody2)
{
renderFirstPerson = false;
shapeFile = "~/data/shapes/player/player2.dts";

className = Armor; // Apply armor class to all bot and player
}

datablock PlayerData(PlayerBody)
{
renderFirstPerson = false;
shapeFile = "~/data/shapes/player/player.dts";

className = Armor; // Apply armor class to all bot and player
}

</code>

In commands.cs:
<code>

function serverCmdJoinPlayerClass(%client, %classid)
{
%client.joinPlayerClass(%classid);
}

function joinclass(%classid)
{
commandtoserver('JoinPlayerClass', %classid);
//Canvas.popDialog(ClassSelectDlg); //Hide the dialog once selection was made
}

</code>



#1
01/23/2011 (9:15 am)
I don't recall how that specific Resource worked but have you also set up your GUI to pass along the relevant information that your scripts will need?