Torque TeamId
by Sam Guffey · 12/16/2003 (6:14 am) · 11 comments
Download Code File
It will show you how to add teamId's to your shapeBase objects and show you how to setup the GuiShapeNameHud control to display friendly players in green and enemies in red.

It will show you how to add teamId's to your shapeBase objects and show you how to setup the GuiShapeNameHud control to display friendly players in green and enemies in red.

About the author
#2
12/16/2003 (12:28 pm)
Cool resource Sam. I will try this out soon as I get the chance.
#3
12/16/2003 (2:04 pm)
Excellente! Thanks Sam! Haven't had a chance to try but is something I need and was going to have to code myself. I think this is a very useful enhancement.
#4
BTW, I have a team 1 & 2 seperated in guiShapeNameHud.cc, and I'm working with the latest CVS of Realm Wars...
12/16/2003 (5:52 pm)
What version of Torque? I got lost finding the drawName call. I found one, but I don't think it's correct one...BTW, I have a team 1 & 2 seperated in guiShapeNameHud.cc, and I'm working with the latest CVS of Realm Wars...
#5
12/16/2003 (7:41 pm)
This is using the latest non-head version of Torque. The drawName call is in guiShapeNameHud.cc->onRender function near the bottom right under.. // Render the shapes name
#6
is wrong :
you must use :
But neither I can see the teamId nor the colors are changing .....
02/15/2005 (12:25 am)
Who got working this resource ??? I didn't get an error during the rebuild. What I found at least is that thisis wrong :
# in (GameConnection::createPlayer) # at the very bottom add.. %player.setTeamId(%this.team);
you must use :
%player.setTeamId(%this.team.teamId);
But neither I can see the teamId nor the colors are changing .....
#7
08/10/2006 (11:37 am)
this was really usefull and a great learning experience. I can now add all kind of things to shapebase (or anything).
#8
This resource is terribly inefficent with bandwidth and how it manages packing/unpacking of the teamID which for some reason has been implemented as a 32 bit floating point number which is extremely heavy for its purpose.
Just a heads up for anyone that considers adding this to their game. It needs some work, although the changes needed are quite trivial - I just want to point it out.
01/31/2007 (7:21 am)
NOTEThis resource is terribly inefficent with bandwidth and how it manages packing/unpacking of the teamID which for some reason has been implemented as a 32 bit floating point number which is extremely heavy for its purpose.
Just a heads up for anyone that considers adding this to their game. It needs some work, although the changes needed are quite trivial - I just want to point it out.
#9
01/14/2009 (9:34 pm)
since the resource link is down (temporaily) I thought I'd paste the contents of the instructions here # This is best viewed with Tribal-IDE
# This tut will show you how to add a teamId to TGE.
# Here I will show you how to add teamId's to your shapeBase objects and,
# show you how to setup the GuiShapeNameHud control to display friendly players
# in green and enemies in red.
# I'll be placing functions in parentheses so you can see them easy.
# Open shapeBase.cc, shapeBase.h and GuiShapeNameHud.cc in the engine
# and game.cs in your server/scripts folder
# !WARNING! Back up your work first, I will not take responsibility for your
# games destruction.
# shapeBase.h
#-------------------------------------------------------------------------------
# in (class ShapeBase) below..
F32 mEnergy;
# add..
F32 mTeamId;
# find (enum ShapeBaseMasks)
# re-number
SoundMaskN = Parent::NextFreeMask << 8,
#to
SoundMaskN = Parent::NextFreeMask << 9,
#then, above it add..
TeamMask = Parent::NextFreeMask << 8,
# next, below..
bool onNewDataBlock(GameBaseData* dptr);
# add..
// TeamId
F32 getTeamId() { return mTeamId; }
void setTeamId(F32 team);
# Move to shapeBase.cc
# shapeBase.cc
#-------------------------------------------------------------------------------
# In (ShapeBase::ShapeBase)
# below..
mLastRenderDistance = 0;
# add..
mTeamId = 0;
# In (ShapeBase::packUpdate)
# above..
if (stream->writeFlag(mask & DamageMask))
# add..
if(stream->writeFlag(mask & TeamMask)) {
stream->write(mTeamId);
}
# In (ShapeBase::unpackUpdate)
# below..
Parent::unpackUpdate(con, stream);
mLastRenderFrame = sLastRenderFrame; // make sure we get a process after the event...
if(!stream->readFlag())
return;
# add..
if(stream->readFlag()) {
stream->read(&mTeamId);
}
# below.. (ShapeBase::setSkinName)
# add these functions..
void ShapeBase::setTeamId(F32 teamId)
{
if(teamId < 0)
teamId = 0;
mTeamId = teamId;
setMaskBits(TeamMask);
}
ConsoleMethod( ShapeBase, setTeamId, void, 3, 3, "(float team)")
{
object->setTeamId(dAtof(argv[2]));
}
ConsoleMethod( ShapeBase, getTeamId, F32, 2, 2, "(returns - teamId)")
{
return object->getTeamId();
}
# If you do not wish to add targetColors based on teamId, then you can
# skip the guiShapeNameHud part, but its recommended you do for learning.
# guiShapeNameHud.cc
#-------------------------------------------------------------------------------
# in (class GuiShapeNameHud)
# add..
ColorF mEnemyTextColor;
# Add in color change to drawName.
# change..
void drawName( Point2I offset, const char *buf, F32 opacity);
# to..
void drawName( Point2I offset, const char *buf, F32 opacity, ColorF color);
# in (GuiShapeNameHud::initPersistFields)
# add this below "textColor" call...
addField( "enemyTextColor", TypeColorF, Offset( mEnemyTextColor, GuiShapeNameHud ) );
# in (GuiShapeNameHud::onRender)
# make the "drawName" call look like this..
drawName(Point2I((S32)projPnt.x, (S32)projPnt.y),shape->getShapeName(),opacity, renderColor);
# now add all this directly above the "drawName" call..
S32 myId = control->getTeamId();
S32 targetId = shape->getTeamId();
// Here we use the default
ColorF renderColor = mTextColor;
// If Our ID is different from our targets, use the enemy color.
if(myId != targetId)
renderColor = mEnemyTextColor;
# Done:Do a rebuild and goto game.cs
# game.cs
#-------------------------------------------------------------------------------
# Here is gets tricky, we need to have teams setup in script prior to this.
# So that the clients, when they join the game, will have a %client.team = ?; var.
# This is usually 0 for Observer, 1 for Team 1 and 2 for Team 2, and so on.
# If you do not have teams implemented in script take a look at this resource,
# writen by Xavier "eXoDuS" Amado..
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2312
# Lets continue.
# in (GameConnection::createPlayer)
# at the very bottom add..
%player.setTeamId(%this.team.teamId);
# Save and fire up the game. Add a bot to the opposite team to see him in red.
# ISSUES...
# Client Camera is not given a teamId thus it shows all players in enemyColor.
#10
I had to change the GuiShapeNameHud.cpp onrender function from
to
to get the int myId = control->getTeamId(); functionality to work
Also had to update the drawname function to pass in the color to the new GFX function.
To address Stefan's comment of an F32 variable passed over the network, I changed the mTeamId variable and all the get and set team id functions to int. The only one I left as a F32 function was the console command function that requires F32. It seems to work fairly well.
01/14/2009 (10:01 pm)
for tgea 1.8I had to change the GuiShapeNameHud.cpp onrender function from
GameBase* control = dynamic_cast<GameBase*>(conn->getControlObject());
to
ShapeBase* control = dynamic_cast<ShapeBase*>(conn->getControlObject());
to get the int myId = control->getTeamId(); functionality to work
Also had to update the drawname function to pass in the color to the new GFX function.
void GuiShapeNameHud::drawName(Point2I offset, const char *name, F32 opacity, ColorF color)
{
// Center the name
offset.x -= mProfile->mFont->getStrWidth((const UTF8 *)name) / 2;
offset.y -= mProfile->mFont->getHeight();
// Deal with opacity and draw.
mTextColor.alpha = opacity;
GFX->getDrawUtil()->setBitmapModulation(color);
GFX->getDrawUtil()->drawText(mProfile->mFont, offset, name);
GFX->getDrawUtil()->clearBitmapModulation();
}To address Stefan's comment of an F32 variable passed over the network, I changed the mTeamId variable and all the get and set team id functions to int. The only one I left as a F32 function was the console command function that requires F32. It seems to work fairly well.
#11
Any way you can post your TGEA 1.8 code changes? Im no coder and I tryed to understand what you sayed to change and I did that and all works well if you are on the same team but if your not then the name is invisable for some reasion. If you point your mouse at the character the only thing that shows up is the health bar and still no name and I can change back to the same team as the other client and the name shows up green.
Thanks
01/28/2009 (2:33 pm)
Britton LaRoche,Any way you can post your TGEA 1.8 code changes? Im no coder and I tryed to understand what you sayed to change and I did that and all works well if you are on the same team but if your not then the name is invisable for some reasion. If you point your mouse at the character the only thing that shows up is the health bar and still no name and I can change back to the same team as the other client and the name shows up green.
Thanks

Torque 3D Owner Tom Feni