Game Development Community

Player handle

by Tom Perry · in Torque Game Engine · 08/06/2007 (6:35 pm) · 0 replies

Hello everyone,
I'm been strugling with this for hours and so I finally thought to seek some help. I'm not a C++ coder and so I'm working on trial and error here, and there is probably a much easier way to do this.
Basically I need to be able to get a handle for the player from the gameConnection. Using getControlObject was fine except that it returns a ShapeBase, and I need to use some of the Player methods in the code. Bascially Ive added these 2 functions to gameConnection.cc:

ConsoleMethod( GameConnection, setPlayerObject, bool, 3, 3, "(Player object)")
{
   Player *gb;
   if(!Sim::findObject(argv[2], gb))
      return false;

   object->setPlayerObject(gb);
   return true;
}

void GameConnection::setPlayerObject(Player *obj)
{
   if(mPlayerObject == obj)
      return;
   mPlayerObject = obj;
}

Bascially the same as the control object couterparts. I then call setPlayer Object in the script when setControl object is called.

My gameConnection.h now looks like this:

SimObjectPtr<ShapeBase> mControlObject;
   SimObjectPtr<Player> mPlayerObject;
   SimObjectPtr<ShapeBase> mCameraObject;
.
.
.
.
   void setControlObject(ShapeBase *co);
   void setPlayerObject(Player *co);
   ShapeBase* getControlObject()  { return  mControlObject; }
   Player* getPlayerObject()  { return  mPlayerObject; }

i.e. added the setPlayerObject stuff (not even sure if that works but it compiles).

Now in the file I'm currently writing I have:

GameConnection* conn = GameConnection::getConnectionToServer();
      if (!conn)
         return;
      Player* control = conn->getPlayerObject();
      if (control==0)
         return;

I've debugged it and mPlayerObject does get set to the same value as mControlObject when the console method setPlayerObject is called. However when it gets the the new file mControlObject is still fine and referencing the player but mPlayerObject is now 0, so it returns.

I think I've outlined all the changes there. Like I said I'm not a C++ coder (or any sort of coder really) and I dont really understand what I'm doing! Any help would be greatly appriciated :)

(For reference heres where the console methods are called in script:

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

In the gameConnection::createPlayer function in server/game.cs (ive jsut added the last line).

Thanks again.)