Game Development Community

Spawning weirdness.

by Phil Carlisle · in Torque Game Engine · 03/05/2002 (3:07 pm) · 9 replies

Ok, I'm doing a quick team spawn code hack.

I am in game.cs around line 96 and see:

// Create a player object.
%this.spawnPlayer();

this normally finds a spawn point, then calls create player.

So, I comment that out, and instead call:

Canvas.pushDialog(chooseteam);

In the chooseteam's button, I call:

serverconnection.spawnPlayer();

buuuut!, it doesnt work. It seems like its not finding a camera when I spawn the player so it cant set its transform to the players.

Anyone any idea's?

Phil.

#1
03/05/2002 (4:02 pm)
Are you calling Canvas.pushDialog(chooseteam) in game.cs then? I wouldn't think that trying to do that from a server script would work. Or am I misunderstanding something (which is entirely likely)?

Dave Myers
21-6 Productions
#2
03/05/2002 (4:45 pm)
Actually, thats a point. It is from the server side isnt it :))

But it works ok :)

Yeah, its from game.cs

Even if Ive sent a client message to push the dialog there though, its still not spawned me properly.

Phil.
#3
03/05/2002 (5:42 pm)
The way you're doing it will work only for the person hosting.

replace %this.spawnPlayer(); with commandToClient(%this, 'showTeamDLG');

then in the client scripts, make a function:

function ClientCmdShowTeamDLG()
{
	Canvas.pushDialog(chooseteam); 
}

Set the choose team button to setChosenTeam();

Make another function on the client:

function setChosenTeam()
{
	%team = "1"; // set this to the correct team.
	commandToServer('setChosenTeam', %team); 
}

Then make a function for the server:

function serverCmdSetChosenTeam(%client, %team)
{
	%client.setTeam(%team); // A made up function, you get the idea.
	%client.spawnPlayer(); 
}


This is kind of how we're doing it. In our game you set the race, sex, and name of your player, then it spawns you appropriately.
#4
03/05/2002 (5:50 pm)
Beat me to it there, Chris. I was JUST going to post almost the exact same thing. ;)

Actually, I tried what Phil did and it doesn't even work if you are the one hosting. But Chris's solution is what I would use.

Dave Myers
21-6 Productions
#5
03/05/2002 (6:28 pm)
Chris' method is the one I use.
#6
03/06/2002 (2:21 am)
Hy Phil,
Here is how we did it. First in our selection team panel, we triggers this function when player has made its selection.
function STP_SelectPlane(%nb)
{
   // TODO: Check if team is full
   if( $TeamSelect $= 0 ) %plane = $Team1.info[%nb];
   if( $TeamSelect $= 1 ) %plane = $Team2.info[%nb];
   Canvas.popDialog(SelectTeamPanel);
   commandToServer('AddPlayer', $TeamSelect, %plane );
}
Here is the command AddPlayer :
function serverCmdAddPlayer(%client,%team,%plane)
{
   if(isObject(%client.player)) %client.player.kill("Suicide");
   %client.spawnPlayer(%team,%plane);
}
And here is the command to find the right spawn point regarding the team:
function GameConnection::spawnPlayer(%this,%team,%plane)
{
   // Combination create player and drop him somewhere
   // Pick a spawnpoint depending on player team
   %spawnPoint = pickSpawnPoint(%team);
   %this.createPlayer(%spawnPoint,%team,%plane);
   commandToClient( %this, 'SetCompassHUD', $CompassHudBitmap );
}
function pickSpawnPoint(%team)
{
   // Checks if player is observer or joining a team
   // If joining a team then look for team spaw points
   if(%team !$= -1) {
   %groupName = "MissionGroup/Team" @ %team @ "DropPoints";
   %group = nameToID(%groupName);

   if(%group != -1) {
      %count = %group.getCount();
      if(%count != 0 ) {
         %index = getRandom(%count-1);
         %spawn = %group.getObject(%index);
         return %spawn.getTransform();
      }
      else
         echo("No spawn points found in " @ %groupName);
   }
   else
      echo("Missing spawn points group " @ %groupName);
   }

   %groupName = "MissionGroup/PlayerDropPoints";
   %group = nameToID(%groupName);

   if (%group != -1) {
      %count = %group.getCount();
      if (%count != 0) {
         %index = getRandom(%count-1);
         %spawn = %group.getObject(%index);
         return %spawn.getTransform();
      }
      else
         error("No spawn points found in " @ %groupName);
   }
   else
      error("Missing spawn points group " @ %groupName);

   // Could be no spawn points, in which case we'll stick the
   // player at the center of the world.
   return "0 0 300 1 0 0 0";
}
In your mission file, you should have things like that :
new SimGroup(Team0DropPoints) {

      new SpawnSphere() {
         position = "773.305 -794.761 342";
         rotation = "0 0 -1 28";
         scale = "1 1 1";
         dataBlock = "SpawnSphereMarker";
         radius = "1";
         sphereWeight = "10";
         indoorWeight = "0";
         outdoorWeight = "100";
            homingCount = "0";
            locked = "false";
            lockCount = "0";
      };
}
   new SimGroup(Team1DropPoints) {

      new SpawnSphere() {
         position = "-825.933 821.185 365.4";
         rotation = "0 0 1 145";
         scale = "1 1 1";
         dataBlock = "SpawnSphereMarker";
         radius = "1";
         sphereWeight = "10";
         indoorWeight = "0";
         outdoorWeight = "100";
            homingCount = "0";
            locked = "false";
            lockCount = "0";
      };
}

Hope it helps you.
[note[The compassHUD things is here to be able in the future to set a different HUD per plane[/note]

Frank
#7
03/06/2002 (4:49 pm)
Thanks guys.

I'd kind of gotten round to doing it right after a bit of messing :))

HOWEVER! i still have one thing thats got me going.

Ive got a client function ChooseTeam() which pops up the chooseteam dialog which gets called in PlayGui.onWake

So when you first join a game, you have an observer screen covered with the choose team screen (as i intended).

Now, i want to pop that dialog back up again once the player dies (so they can choose a different team).

I can use the trigger call to do it when a button is pressed, but i ideally wanted to have it so that you observe your dead body for a few seconds, THEN it pops up the choose team dialog again.

Here's my problem. I cant get a schedule call to work to pop up the dialog!

Here's a snippet at the end of gameconnection::onDeath:
// snip
%this.schedule(5000,'ShowChooseTeam',%this);
};


function ShowChooseTeam(%this)
{
echo("scheduled call got to choose team\n");
commandToClient(%this,'ChooseTeam');
}

Now, all i really want to do, is setup a scheduled call to send that second line in ShowChooseTeam so tha it pushes the dialog.

But unfortunately, that schedule doesnt work.

I cant see anything immediately wrong with the schedule call. But am i looking at the problem wrong?

Thanks for the other input guys.

Phil.
#8
03/06/2002 (10:11 pm)
Phil, instead of making the server manage the schedule, how about have the server punt to the client, who then does schedule( %delay, 0, xxx);
#9
03/07/2002 (1:35 am)
Excellent idea. Didnt really think of it :)) but it makes sense.

Any idea why the schedule didnt work tho? it's a good idea though in any case.

Phil.