Game Development Community

Player Selection

by Louis Dufresne · in Artist Corner · 01/09/2004 (8:23 am) · 85 replies

I have a GUI that allows you to select from 4 players. I have all the DTS's for each model and im using the Orc's animations at this time for each player model. Ive added to prefs.cs -> prefs::player::character = ""
In the selection GUI I just change this value to correspond to the player I want. Also I have a separate CS file for each player, all of which are included in the game.cs. Now im just not sure on how or where to tell the game, in script, which player model to load when the game starts. Anyone know where this is? Or how its done?
#41
06/12/2005 (6:02 am)
Cause it works in the offline modus, i think that isn't a problem in general.
Perhaps the problem with the dedicated server are somewhere else?
#42
06/12/2005 (7:14 am)
There is always a client and a server side of things, regardless of the type of game--even single player games, in a single executable, still have a "server side" and a "client" side.
#43
06/12/2005 (3:29 pm)
And what that means in this case?
#44
06/14/2005 (11:39 am)
I told you in my first post!
#45
06/17/2005 (12:47 am)
Sorry, i am a stupid german and dont understand everything you told :(
Perhaps a example will help me to solve my problems?
#46
11/19/2005 (12:26 pm)
In Realm Wars is all the coding needed to make it so you can select a player all in the script files and or is there actual code that needs to be compiled with in the engine it self .

I can't get my engine to compile a new exe at all so i guess i'm out of luck there if there is coding that needs to be implemented into the actaull exe until i can sort that problem out.
#47
02/06/2006 (12:42 pm)
HI Guys,

I am running TGE 1.4 and i have tried to get this working but i am having some issues. Before i start i have used the resourse that allows you to select teams now i want to be about to select players. in my game there are only 2 Male and female. Now I have tried one of the above resourse and it don't. is there a tutorial written up on this? I think the bit i have gone wrong is on the GUI part as when i start the game it asks me for the team i select i but no player not even an error lol.

any ideas would be welcome.

Cheers
John
#48
06/25/2006 (8:46 am)
Realm Wars is mixing the team and model select. That makes it difficult to strip out 1 or the other. It is also using an older (outdated) version of torque. It still works in 1.4 (take the 1.4 exe and plop it in the realmwars folder and click. It works) but there is a lot of code that is no longer needed.

Here's what I've got in game.cs and the error I am still getting:

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

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!" );
   }

   // Create the player object
   %player = new Player() {
      dataBlock = %this.armor;         //added armor choice here
      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);
}

Error message:
Quote:
starter.fps/server/scripts/game.cs (297): Register object failed for object (null) of class Player.
Set::add: Object "0" doesn't exist
starter.fps/server/scripts/game.cs (301): Unable to find object: '0' attempting to call function 'setTransform'
starter.fps/server/scripts/game.cs (302): Unable to find object: '0' attempting to call function 'setShapeName'
starter.fps/server/scripts/game.cs (305): Unable to find object: '0' attempting to call function 'setInventory'
starter.fps/server/scripts/game.cs (306): Unable to find object: '0' attempting to call function 'setInventory'
starter.fps/server/scripts/game.cs (307): Unable to find object: '0' attempting to call function 'mountImage'
starter.fps/server/scripts/game.cs (310): Unable to find object: '0' attempting to call function 'getEyeTransform'

For reference, I'm using the stock "starter.fps" tutorial to test this.
If I can get this all working, I'll post the changed files.
I'm thinking I'm doing something wrong on the gui side, but don't know yet.
I'll keep working on this today and see what I can come up with. If anyone has any ideas, Please let me know.
oh, and I'm using the example from Gonzo and Realmwars to work thru this.
Thanks.

edit to add: I took the armor function out and placed %model in and got rid of the error messages. :)
I even finally got the demo to load again, but only with the default avatar. I'm having problems understanding other parts that I will place in another thread.
#49
06/25/2006 (8:28 pm)
I actually got this to work. It only took this newbie 14 hours of straight hair pulling and knashing of teeth, and a few questions of this forum to get it.
Eccept I'm getting 2 avatars spawned. I'm working on it and have asked in the sdk forum for help.
#50
06/28/2006 (6:02 am)
Mike, I am work on this but I cant to find the thread in the sdk forum. I believe the zip was model choice.
#51
06/29/2006 (6:24 pm)
Here's the code for version 1.4 that works.

First of all, thanks to all the people who helped me with this code. Especially Juan Aramburu, who actually gave me this code and helped me get it implemented.


Create a file in client/scripts/ (name it whatever you want) and add the following to it:

//===========================================================================
//added this function for model selection
//===========================================================================

 function clientCmdstartSpawn()  {
     %spawnModel = "MaleModel";
       //set your default
          if ($pref::model::female)
                %spawnModel = "FemaleModel";
       //you could check $pref::model::male [else if...] here, but since it's the default, no need to
          commandToServer('spawnPlayer', %spawnModel);
          }
//----------------------------------------------------------------------------

Then, in server/scripts/game.cs
Find and replace the following:

//-----------------------------------------------------------------------------
// GameConnection Methods
// These methods are extensions to the GameConnection class. Extending
// GameConnection make is easier to deal with some of this functionality,
// but these could also be implemented as stand-alone functions.
//-----------------------------------------------------------------------------
 //=====Added startSpawn  here===========================
//-----------------------------------------------------------------------------

function GameConnection::onClientEnterGame(%this)
{
   commandToClient(%this, 'SyncClock', $Sim::Time - $Game::StartTime);

   // Create a new camera object.
   %this.camera = new Camera() {
      dataBlock = Observer;
   };
   MissionCleanup.add( %this.camera );
   %this.camera.scopeToClient(%this);

   // Setup game parameters, the onConnect method currently starts
   // everyone with a 0 score.
   %this.score = 0;

   // Create a player object.
   //%this.spawnPlayer();
   //===Added this=====================
   commandToClient(%this, 'startSpawn');
   //---------------------------------
}

Lower down, find and replace with this:

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

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!" );
   }

   // Create the player object
   //*************Changed to datablock for selection*****************
   %player = new Player() {
      dataBlock = getClientSpawnDataBlock(%this);
      client = %this;
    };
    
   MissionCleanup.add(%player);

   // Player setup...
   %player.setTransform(%spawnPoint);
   %player.setShapeName(%this.name);
   
   // Starting equipment
   %player.setInventory(Crossbow,1);
   %player.setInventory(CrossbowAmmo,20);
   %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);
}

 // add this function
function getClientSpawnDataBlock(%client) {
         if (!isObject(%client.model))
               %client.model = HumanMale;  //put the default datablock you want here
                  return %client.model;
      }

     function serverCmdSpawnPlayer(%client, %model)
     {
     //   more secure would be to tell the client to pass a 'description' as %model,
     //   server switches the %model (switch$ (%model)), and sets the right datablock
     //   accordingly
       switch$ (%model) {
              case MaleModel:
                       %client.model = HumanMale;
              case FemaleModel:
                       %client.model = HumanFemale;
        }
           %client.spawnPlayer();
           }

    //================End add here===============

At the very end of the file, add:
//Added to Kill the "On need relight" error in the console.
   function onNeedRelight() { }
This stops the error messagein your console warning that it doesn't know what that is.

Ok, back to model selection...

Now, in client/ui/startMission.gui, add:

//Check boxes for our players
      //these checkboxes are directly under the players name entry
      
      new GuiCheckBoxCtrl(ckBxMale) {
         profile = "GuiCheckBoxProfile";
         horizSizing = "right";
         vertSizing = "bottom";
         position = "102 36";
         extent = "147 23";
         minExtent = "8 8";
         visible = "1";
         variable = "pref::model::male";
         text = " Male";
         groupNum = "-1";
         buttonType = "ToggleButton";
            helpTag = "0";
            maxLength = "255";
      };
      new GuiCheckBoxCtrl(ckBxFemale) {
         profile = "GuiCheckBoxProfile";
         horizSizing = "right";
         vertSizing = "bottom";
         position = "152 36";
         extent = "147 23";
         minExtent = "8 8";
         visible = "1";
         variable = "pref::model::female";
         text = " Female";
         groupNum = "-1";
         buttonType = "ToggleButton";
            helpTag = "0";
            maxLength = "255";
      };
      //Thats it. No other changes made. You can change this to be buttons if you like
      //replacing the start game button with these. I chose to use prefs.

Add the same code to joinServerGui.gui as well and you are good to go.

You can change the check boxes with buttons, add other avatars, whatever you want.
#52
07/14/2006 (5:12 am)
In case anyone cares, the if(%armor) line in Gonzo's original code doesn't seem to work as it's meant to (maybe the newer version of Torque) so I had to change it to if(%armor !$= "") to get everything working. Of course you should eventually use that better switch statement but I was trying to start as simple as possible and thought someone else might have the same problem.
#53
08/23/2006 (2:33 pm)
Mike R.

Thanks for the post. It gives me a few leads as to how to implement this in my own meanderings...

Ok, I do have a question relating to this part:

//===========================================================================
//added this function for model selection
//===========================================================================

function clientCmdstartSpawn() {
%spawnModel = "MaleModel";
//set your default
if ($pref::model::female)
%spawnModel = "FemaleModel";
//you could check $pref::model::male [else if...] here, but since it's the default, no need to
commandToServer('spawnPlayer', %spawnModel);
}
//----------------------------------------------------------------------------

I've saved it and named it avatarChoice.cs. What exactly does it do? Does it get called from another part of code that isn't shown?

As well, how does this code correlate to the .dts files of my models. For example, I have an orc and I have a male avatar. I currently have them residing in the default Starter FPS Kit locations. Namely, in the /data/shapes/player directory. I would like to be able to choose between the orc or the male avatar.

I'm wondering how exactly are the different .dts files are being called based on your examples.

...hmm...has anyone got a good link about this?

Thanks everyone :)
#54
08/23/2006 (7:56 pm)
This whole topic has driven me bonkers for a long time, I've been told it cant be done, then it can, cant, etc.

Here's my code that, well it works, but I need to clean it up a little.

In baseGame.cs I changed this:
//creates a player without a team, always an orc!
function GameConnection::createSinglePlayer(%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!" );
   }

   // Create the player object
   
   %playerCreated = skinChoice(%this); // function at bottom of script.  The client is in %this.    
   if(%playerCreated == 0) { // If we didn't create the player in skinchoice, then we need to create it here.

      %player = new Player() {
         dataBlock = orc;
         client = %this;
      };

      // default ammo/weapon gift.
      %player.setInventory(Crossbow,1);
      %player.setInventory(CrossbowAmmo,20); 
      //%player.setInventory(Poison,1);
      //%player.setInventory(PoisonAmmo,20);
      %player.setInventory(firebow,1);
      %player.setInventory(fireAmmo,20);
      //%player.setInventory(Flamebow,1);
      //%player.setInventory(FlameAmmo,20);
      %player.setInventory(CoCo,1);
      %player.setInventory(CoCoAmmo,20);
      %player.use(Crossbow); 
      commandToClient(%this,'SetWeaponMappings',"orc");
   }

   MissionCleanup.add(%player);

The function I use is this pasted at the bottom of the baseGame.cs:
// skinChoice:
//
// The client is passed in.
// We check the IP address of the client.
// If we have the IP address we want, we create the player so 
// we can assign a specific skin datablock.
//
// If we don't recognize the IP address we return a zero
// and the player will be created later.
//
function skinChoice( %client ){ 
  %plyr = 0;

  if(strStr(%client.getAddress(), "IP:192.168.1.100") > -1 ) //Uni
    %plyr = 1;

  if(%plyr == 0) 
    return 0; 

  %player = new Player() {
    dataBlock = elf;
     client = %this;
  };
  // default ammo/weapon gift.
  %player.setInventory(Crossbow,1);
  %player.setInventory(CrossbowAmmo,20); 
  //%player.setInventory(Poison,1);
  //%player.setInventory(PoisonAmmo,20);
  %player.setInventory(firebow,1);
  %player.setInventory(fireAmmo,20);
  //%player.setInventory(Flamebow,1);
  //%player.setInventory(FlameAmmo,20);
  %player.setInventory(CoCo,1);
  %player.setInventory(CoCoAmmo,20);
  %player.use(Crossbow); 
  commandToClient(%this,'SetWeaponMappings',"elf");
  return;
}

This works great for me and I have no problems. This allows me to set skins based upon player's ip's that commonly log on to my server. Using the the code however, it could easily be modified based upon names, passwords, etc.
#55
08/24/2006 (8:10 am)
Would anybody be interested in a resource on how to select your model, then the skin for that model?

I can then extend the resource to the following:
- Select your weapon after you selected your model (If there's that interest)
- Incorporate the Teams selection resource, and make weapons/players specific to a team.

All in script off course, using a very basic GUIs.

EDIT: This is in the wrong section, but seems people struggling with this.
#56
08/24/2006 (8:54 am)
James :)

re:"Would anybody be interested in a resource on how to select your model, then the skin for that model?"

Yes, I would be interested. To be honest, I've been grappling with this one for a bit as I get my feet wet with Torque script etc.

As well, when I work with the tutorials and resources, I find myself wondering if I have the correct setup. I am still on TGE 1.3 and currently learning the ropes with the starter.fps files. It would be good to know during the instruction, what framework or the version of TGE that is being used and any additional resource files being used. Otherwise, a tutorial can be rendered useless.

Thanks everyone.
#57
08/24/2006 (9:00 am)
James: Yes, i would love to that resource!
#58
08/24/2006 (12:15 pm)
Sure ... I'd like it too... any extra knowledge is a good thing....
#59
08/24/2006 (1:31 pm)
I would love that. I have been waiting for a resource on this forever than constantly trying to figure it out for myself. Have the gui's would make it a lot easier. So, I suport a resource 1000%
#60
08/24/2006 (4:56 pm)
Yes, I love too. Same here been waiting.