Game Development Community

Displaying/Hiding Player Names

by Will Burgers · in Torque Game Engine · 08/03/2005 (9:00 am) · 10 replies

Hello,

At the moment every player's name is displayed in green above them. I was wondering how I would go about drawing only the names of the players on your team, and not displaying the names of enemy teammates.

Take Care,
Will

#1
08/03/2005 (9:08 am)
A good place to start would be looking at

engine/games/fps/guiShapeNameHud.cc
#2
08/05/2005 (12:31 pm)
I have looked in there, but let me explain my problem more thoroughly. I set up teams as global variables in the scripts, and each GameConnection has a team variable. Since player names are rendered in the C++, however, my problem is twofold:

1. Given that I have a pointer to the client's GameConnection ("conn" in GuiShapeNameHud::onRender), I need a way to access its script variables from the code to determine the client player's team.
2. For every PlayerObjectType that it finds, I need to find a way to get the GameConnection that owns that player, and then check its team against the client's team.

Thanks for any insight you can provide,
Will
#3
08/05/2005 (3:30 pm)
1. Hmm, maybe make the team a C++ side variable in the GameConnection class, then just add it to the initpersist so you can update it via script ... then just reference the C++ side variable attached to gameconnectin ?
#4
08/05/2005 (4:34 pm)
Try something like

int team = Con::getIntVariable("ServerConnection.team", 0);

It's a little... no... a lot slower than doing what King Tut suggested, though.
#5
08/06/2005 (4:49 pm)
Thanks, I'm looking into implementing the teams in the engine. By the way, is there a ConsoleType I can specify in addField() to expose a struct? Or do I have to expose every variable seperately?
#6
08/06/2005 (5:23 pm)
Actually, would the addGroup() function do something similar in initPersistFields()? I can't find a lot of documentation about it, but it looks like it groups several fields under a heading.
#7
08/06/2005 (7:53 pm)
Alright, I've exposed a simple "teamNumber" variable which should do the trick as far as team comparison, but I still need some way to get at the GameConnection object that owns a particular ShapeBase object, if such a thing is possible. In the scripts, I can use "%obj.client", but I haven't seen anything similar in the ShapeBase class. Anyone have an idea?
#8
08/06/2005 (9:10 pm)
You could add a console type to expose the struct... or just expose the members if it makes sense to do that instead.

addGroup just implements a grouping. Nothing special there, just a convenience.
#9
08/08/2005 (8:25 am)
First, you're probably heading down the wrong track if you plan on things other than players being on teams. I put a team number in ShapeBase, which allows me to figure out the team number of each PlayerType object, but it also allows me to figure out the team number of everything else in the game as well.

Your last question didn't make sense to me, though, although I'd like to help answer it. The problem is that %obj.client only works on the server side, but you're talking about a task / function which takes place on the client. (i.e. displaying player names) You cannot get the client connection of all of the client objects from another client machine. You'll notice that all references to %obj.client only exist under the server directory in the scripts directory.

I'm sure that doesn't help too much, but hopefully it'll help enough to get you going the right direction.

This link has more information on teams, but it doesn't look complete.
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2312

Somewhere in gameTypes.cs, if you don't already have it (maybe it's in the core implementation?) you need:
function coreGame::createPlayer( %game, %client, %spawnPoint )
{
    ....

   // Update the team
   %player.setTeamId(%client.team);	// this is for the shapenamehud I believe?  -Q
   %client.camera.setTeamId(%client.team); // Might not be necessary

    ....
}

Also, http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4943 is another good place to continue.
#10
08/08/2005 (6:09 pm)
Wow! Thank you, Tony! Yeah, I was beginning to think that I was doing it the wrong way when the teamNumber variable kept showing up 0 when guiShapeNameHud checked it. I was just looking into the network code when I noticed your post, and this is just what I needed! I haven't seen the second resource before, but it did exactly what I was trying to do. Thanks again!

Will