Team HUD Script Examples


The Team Hud expands on the Intermediate Hud by adding some more displayed information about team members, the team and the game.

Team and Team Members

When you are on a team you want to know information about individual team members and about the team as a whole. It works quite well to place all this information into one area since you can step through the list of team members and, at the end of the list, have the entire team displayed at once. There are two ownerdrawflag commands that are used when displaying this information. These commands keep track of your movement through the team member list (using the keys bound to the nextTeamMember and the prevTeamMember cvars) and know when you have reached the end of the list and want to display the team info.

Since this information is only relevant to a team game we will set up our menuDef so it will appear only if the game type is team based.

  menuDef
  {
name "SelectedPlayer"
visible MENU_TRUE
rect 2 363 180 64
ownerdrawflag CG_SHOW_ANYTEAMGAME
itemDef { } .... }

The ownerdrawflag CG_SHOW_ANYTEAMGAME command makes sure that this menuDef only is displayed during a team game.

The items in this menuDef are broken down into two groups, those displaying team information and those displaying information about individual team members. The team information group would look like the following :

  itemDef
  {
name "teaminfo"
rect 2 4 172 60
visible MENU_TRUE
textscale .17
textaligny 10
textalignx 0
forecolor 1 1 1 1
ownerdrawflag CG_SHOW_TEAMINFO
ownerdraw CG_TEAMINFO
}

The ownerdraw CG_TEAMINFO command displays information about the team using the text formatting commands in the item. The ownerdrawflag CG_SHOW_TEAMINFO command makes this item visible only when you are at the end of the team member list.

The team member group of items can display a great deal of information about the selected team member and you can choose which bits of info you want to see. We will show items for all the avalible information and you can decide which fit your Hud scheme. In each of these items the ownerdrawflag CG_SHOW_NOTEAMINFO command makes the item visible only when you are selecting a specific team member and not the team info.

The selected team member's head :

  itemDef
  {
name "selectedhead"
rect 4 3 32 32
visible MENU_TRUE
ownerdrawflag CG_SHOW_NOTEAMINFO
ownerdraw CG_SELECTEDPLAYER_HEAD
}

The ownerdraw CG_SELECTEDPLAYER_HEAD command shows the player's head in a 32x32 area. This will be a model unless the cg_draw3dIcons cvar is set to 0, in which it would be a graphic.

The selected team member's name :

  itemDef
  {
name "selectedname"
rect 35 3 35 15
visible MENU_TRUE
ownerdrawflag CG_SHOW_NOTEAMINFO textscale 0.25
textstyle ITEM_TEXTSTYLE_SHADOWED
forecolor 1 1 1 1
ownerdraw CG_SELECTEDPLAYER_NAME
}

This displays the name using the text formatting commands in the item in the color white.

The selected team member's location :

  itemDef
  {
name "selectedlocation"
rect 35 15 45 15
visible MENU_TRUE
ownerdrawflag CG_SHOW_NOTEAMINFO textscale 0.25
textstyle ITEM_TEXTSTYLE_SHADOWED
forecolor 1 1 1 1
ownerdraw CG_SELECTEDPLAYER_LOCATION
}

This displays the location using the text formatting commands in the item in the color white.

The selected team member's status :

  itemDef
  {
name "selectedstatus"
rect 7 40 16 16
visible MENU_TRUE
ownerdrawflag CG_SHOW_NOTEAMINFO
ownerdraw CG_SELECTEDPLAYER_STATUS
}

This displays a 16x16 graphic that shows the status of the team member.

The selected team member's weapon :

  itemDef
  {
name "selectedweapon"
rect 100 33 24 24
visible MENU_TRUE
ownerdrawflag CG_SHOW_NOTEAMINFO
ownerdraw CG_SELECTEDPLAYER_WEAPON
}

This displays a 24x24 graphic that shows the current weapon of the team member.

The selected team member's powerup :

  itemDef
  {
name "selectedpowerup"
rect 30 40 16 16
visible MENU_TRUE
ownerdrawflag CG_SHOW_NOTEAMINFO
ownerdraw CG_SELECTEDPLAYER_POWERUP
}

This displays a 16x16 graphic that shows the first powerup in the inventory of the team member.

The selected team member's armor :

  itemDef
  {
name "selectedarmor"
rect 75 48 22 11
visible MENU_TRUE
ownerdrawflag CG_SHOW_NOTEAMINFO textscale 0.25
textstyle ITEM_TEXTSTYLE_SHADOWED
forecolor 1 1 1 1
ownerdraw CG_SELECTEDPLAYER_ARMOR
}

This displays the armor amount using the text formatting commands in the item in the color white.

The selected team member's health :

  itemDef
  {
name "selectedhealth"
rect 75 35 22 11
visible MENU_TRUE
ownerdrawflag CG_SHOW_NOTEAMINFO textscale 0.25
textstyle ITEM_TEXTSTYLE_SHADOWED
forecolor 1 1 1 1
ownerdraw CG_SELECTEDPLAYER_HEALTH
}

This displays the health amount using the text formatting commands in the item in the color white.

Player Location

In maps designed for team based games you can often find out what area of the map you are located in. This can be useful information to display in the Hud and can be done like this :

  itemDef
  {
name "location"
rect 37 7 16 16
visible MENU_TRUE
ownerdrawflag CG_SHOW_ANYTEAMGAME textscale 0.25
textstyle ITEM_TEXTSTYLE_SHADOWED
forecolor 1 1 1 1
ownerdraw CG_PLAYER_LOCATION
}

This will be displayed when the game is a team game and it will use the item's text formatting commands and be white in color.

Player Status

In team games the status of the player is often useful. This status tell you what the player is doing at the current time, such as attacking, camping, etc. This can be displayed as a graphic by :

  itemDef
  {
name "status"
rect 16 10 16 16
visible MENU_TRUE
ownerdrawflag CG_SHOW_ANYTEAMGAME
ownerdraw CG_PLAYER_STATUS
}

This will display the status as a 16x16 graphic.

Team Scores

In team games you'd like to know the score for each team, as well as your individual score which we looked at earlier. There are two ownerdraw commands that display the score for the teams, one for each team. Again, these are only relevant in team games so we use the ownerdrawflag CG_SHOW_ANYTEAMGAME command to make them display only in a team game.

To show the Blue teams score :

  itemDef
  {
name "bluescore"
rect 35 21 30 15
visible MENU_TRUE
ownerdrawflag CG_SHOW_ANYTEAMGAME textscale 0.25
textstyle ITEM_TEXTSTYLE_SHADOWED
forecolor 1 1 1 1
ownerdraw CG_BLUE_SCORE
}

and to show the Red teams score :

  itemDef
  {
name "redscore"
rect 87 21 30 15
visible MENU_TRUE
ownerdrawflag CG_SHOW_ANYTEAMGAME textscale 0.25
textstyle ITEM_TEXTSTYLE_SHADOWED
forecolor 1 1 1 1
ownerdraw CG_RED_SCORE
}

These display the team scores using the text formatting commands in the item in the color white.

Flag Status

In games that use a flag, such as CTF and its variations, you should display information about the status of each team's flag. There are a number of ownerdraw commands that can display this information plus a number of flag related ownerdrawflag commands. These can be combined in different ways to provide information about the flag status.

An important bit of knowledge for the player is if he currently has the enemy's flag. There are several different ways of showing this on the Hud display. One of these is as follows :

  itemDef
  {
name "status"
rect 85 15 40 40
visible MENU_TRUE
ownerdraw CG_PLAYER_HASFLAG
}

This will draw a model of the flag currently in the possession of the player in a 40x40 area. Another method is to use a shader and make an area of the Hud pulse with color when you have the flag. If we use this graphic :

ui/assets/hud/green_box.tga
8x8

and this shader :

hudalert_green
{
nopicmip
nomipmaps

{ map ui/assets/hud/green_box.tga
blendFunc GL_ONE GL_ZERO
tcMod scroll 7.1 0.2
tcmod scale .8 1
rgbgen wave sin .25 .25 0 1
}
}

we could create an item like the following :

 itemDef
 {
   name "HasFlag"
   rect 12 13 116 48
   style WINDOW_STYLE_SHADER
   background hudalert_green
   visible MENU_TRUE
   ownerdrawflag CG_SHOW_IF_PLAYER_HAS_FLAG 
 }

that does just that. The two methods could even be used together to produce a very visible Hud element.

In CTF games it is also important to know if your team has the enemy flag or the enemy has your flag, as this affects the player's actions. Like other flag indicators, this action has both ownerdraw and ownerdrawflag commands associated with it.

To show the status of the flag (in base, captured or missing) as a graphic you can use the following, first for the Blue flag and then for the Red flag :

 
  itemDef
  {
name "blueflagstatus"
rect 30 22 16 16
visible MENU_TRUE ownerdrawflag CG_SHOW_CTF
ownerdraw CG_BLUE_FLAGSTATUS
}
  itemDef
  {
name "redflagstatus"
rect 77 22 16 16
visible MENU_TRUE ownerdrawflag CG_SHOW_CTF
ownerdraw CG_RED_FLAGSTATUS
}

Since these are only relevant in a CTF game we use the ownerdrawflag CG_SHOW_CTF command to make these appear only in that type of game. These display a 16x16 graphic showing the flag's status. To make it more visible that a flag has been captured you can make the area behind each flag pulse with the team's color whenever the flag has been captured. If we use these graphics :

ui/assets/hud/blue_box.tga
ui/assets/hud/red_box.tga
8x8
8x8

and these shaders :

hudalert_blue
{
nopicmip
nomipmaps

{ map ui/assets/hud/blue_box.tga
blendFunc GL_ONE GL_ZERO
tcMod scroll 7.1 0.2
tcmod scale .8 1
rgbgen wave sin .25 .25 0 1
}
} hudalert_red
{
nopicmip
nomipmaps

{ map ui/assets/hud/red_box.tga
blendFunc GL_ONE GL_ZERO
tcMod scroll 7.1 0.2
tcmod scale .8 1
rgbgen wave sin .25 .25 0 1
}
}

we could create items like the following :

 itemDef
 {
   name "BlueHasFlag"
   rect 0 13 63 48
   style WINDOW_STYLE_SHADER
   background hudalert_blue
   visible MENU_TRUE
   ownerdrawflag CG_SHOW_BLUE_TEAM_HAS_REDFLAG 
 }

 itemDef
 {
   name "RedHasFlag"
   rect 63 13 63 48
   style WINDOW_STYLE_SHADER
   background hudalert_red
   visible MENU_TRUE
   ownerdrawflag CG_SHOW_RED_TEAM_HAS_BLUEFLAG  
 }

that do just that. There are also ownerdraw commands that will display information about the player that has the flag. To show a model of the flag carrier's head you can use this :

  itemDef
  {
name "bluecarrierhead"
rect 30 22 32 32
visible MENU_TRUE ownerdrawflag CG_SHOW_CTF
ownerdraw CG_BLUE_FLAGHEAD
}

for the Red team member who is carrying the blue flag and this :

  itemDef
  {
name "redcarrierhead"
rect 64 22 32 32
visible MENU_TRUE ownerdrawflag CG_SHOW_CTF
ownerdraw CG_RED_FLAGHEAD
}

for the Blue team member who is carrying the red flag. You also can display the above player's name using the following :

  itemDef
  {
name "bluecarriername"
rect 30 58 32 15
visible MENU_TRUE
textscale 0.25
textstyle ITEM_TEXTSTYLE_SHADOWED
forecolor 1 1 1 1
ownerdraw CG_BLUE_FLAGNAME
} itemDef {
name "redcarriername"
rect 64 58 32 15
visible MENU_TRUE
textscale 0.25
textstyle ITEM_TEXTSTYLE_SHADOWED
forecolor 1 1 1 1
ownerdraw CG_RED_FLAGNAME
}

 

Return to Home Page