1 // self.isactive = player is in range and coordinates/status (health and armor) are up to date
2 // self.origin = player origin TODO: should maybe move this so it's the origin of the shownames tag already in SSQC for culling?
5 // self.sameteam = player is on same team as local client
6 // self.fadedelay = time to wait before name tag starts fading in for enemies
7 // self.pointtime = last time you pointed at this player
8 // self.csqcmodel_isdead = value of csqcmodel_isdead to know when the player is dead or not
10 const float SHOWNAMES_FADESPEED = 4;
11 const float SHOWNAMES_FADEDELAY = 0.4;
12 void Draw_ShowNames(entity ent)
14 if(!autocvar_hud_shownames)
17 #ifdef COMPAT_XON050_ENGINE
18 if((ent.sv_entnum == player_localentnum) || (ent.sv_entnum == spectatee_status)) // ent is me or person i'm spectating
20 if(ent.sv_entnum == player_localentnum) // ent is me or person i'm spectating
22 if not (autocvar_hud_shownames_self && autocvar_chase_active)
25 makevectors(view_angles);
27 if(ent.sameteam || (!ent.sameteam && autocvar_hud_shownames_enemies))
29 ent.origin_z += autocvar_hud_shownames_offset;
32 if(ent.sameteam && !autocvar_hud_shownames_crosshairdistance)
38 traceline(view_origin, ent.origin, MOVE_NORMAL, ent);
39 if(trace_fraction < 1 && (trace_networkentity != ent.sv_entnum && trace_ent.entnum != ent.sv_entnum))
46 float overlap = FALSE, onscreen, crosshairdistance;
49 o = project_3d_to_2d(ent.origin);
51 if(autocvar_hud_shownames_antioverlap)
53 // fade tag out if another tag that is closer to you overlaps
55 for(e = world; (e = find(e, classname, "shownames_tag")); )
59 eo = project_3d_to_2d(e.origin);
60 if not(eo_z < 0 || eo_x < 0 || eo_y < 0 || eo_x > vid_conwidth || eo_y > vid_conheight)
63 if(vlen((eX * o_x + eY * o_y) - eo) < autocvar_hud_shownames_antioverlap_distance && vlen(ent.origin - view_origin) > vlen(e.origin - view_origin))
72 onscreen = (o_z >= 0 && o_x >= 0 && o_y >= 0 && o_x <= vid_conwidth && o_y <= vid_conheight);
73 crosshairdistance = sqrt( pow(o_x - vid_conwidth/2, 2) + pow(o_y - vid_conheight/2, 2) );
75 if(autocvar_hud_shownames_crosshairdistance)
77 if(autocvar_hud_shownames_crosshairdistance > crosshairdistance)
80 if not(ent.pointtime + autocvar_hud_shownames_crosshairdistance_time > time)
83 overlap = (autocvar_hud_shownames_crosshairdistance_antioverlap ? overlap : FALSE); // override what antioverlap says unless allowed by cvar.
87 ent.fadedelay = time + SHOWNAMES_FADEDELAY;
89 if(!ent.sameteam && (!onscreen || !hit)) // out of view, fade out
91 ent.alpha = max(0, ent.alpha - SHOWNAMES_FADESPEED * frametime);
92 ent.fadedelay = 0; // reset fade in delay, enemy has left the view
94 else if(ent.csqcmodel_isdead) // dead player, fade out slowly
95 ent.alpha = max(0, ent.alpha - SHOWNAMES_FADESPEED * 0.25 * frametime);
96 else if(overlap) // tag overlap detected, fade out
97 ent.alpha = max(0, ent.alpha - SHOWNAMES_FADESPEED * frametime);
98 else if(ent.sameteam) // fade in for team mates
99 ent.alpha = min(1, ent.alpha + SHOWNAMES_FADESPEED * frametime);
100 else if(time > ent.fadedelay) // fade in for enemies
101 ent.alpha = min(1, ent.alpha + SHOWNAMES_FADESPEED * frametime);
107 dist = vlen(ent.origin - view_origin);
110 a = autocvar_hud_shownames_alpha;
112 if(autocvar_hud_shownames_maxdistance)
114 if(dist >= autocvar_hud_shownames_maxdistance)
116 a *= ((autocvar_hud_shownames_maxdistance - autocvar_hud_shownames_mindistance) - max(0, dist - autocvar_hud_shownames_mindistance)) / (autocvar_hud_shownames_maxdistance - autocvar_hud_shownames_mindistance);
124 if(autocvar_hud_shownames_resize) // limit resize so its never smaller than 0.5... gets unreadable
125 resize = 0.5 + 0.5 * ((autocvar_hud_shownames_maxdistance - autocvar_hud_shownames_mindistance) - max(0, dist - autocvar_hud_shownames_mindistance)) / (autocvar_hud_shownames_maxdistance - autocvar_hud_shownames_mindistance);
127 // draw the sprite image
132 vector myPos, mySize;
133 mySize = (eX * autocvar_hud_shownames_aspect + eY) * autocvar_hud_shownames_fontsize;
134 myPos = o - '0.5 0 0' * mySize_x - '0 1 0' * mySize_y;
140 myPos_x += 0.5 * (mySize_x / resize - mySize_x);
141 myPos_y += (mySize_y / resize - mySize_y);
143 vector namepos; // this is where the origin of the string
147 namewidth = mySize_x;
149 if(autocvar_hud_shownames_status && teamplay)
153 if(ent.healthvalue > 0)
155 HUD_Panel_DrawProgressBar(namepos + '0 1 0' * autocvar_hud_shownames_fontsize * resize, eX * 0.5 * mySize_x + eY * resize * autocvar_hud_shownames_statusbar_height, "nametag_statusbar", ent.healthvalue/autocvar_hud_panel_healtharmor_maxhealth, 0, 1, '1 0 0', a, DRAWFLAG_NORMAL);
157 if(ent.armorvalue > 0)
158 HUD_Panel_DrawProgressBar(namepos + '0 1 0' * autocvar_hud_shownames_fontsize * resize + eX * 0.5 * mySize_x, eX * 0.5 * mySize_x + eY * resize * autocvar_hud_shownames_statusbar_height, "nametag_statusbar", ent.armorvalue/autocvar_hud_panel_healtharmor_maxarmor, 0, 0, '0 1 0', a, DRAWFLAG_NORMAL);
164 s = GetPlayerName(ent.sv_entnum-1);
165 if((autocvar_hud_shownames_decolorize == 1 && teamplay) || autocvar_hud_shownames_decolorize == 2)
166 s = playername(s, GetPlayerColor(ent.sv_entnum-1));
168 drawfontscale = '1 1 0' * resize;
169 s = textShortenToWidth(s, namewidth, '1 1 0' * autocvar_hud_shownames_fontsize, stringwidth_colors);
172 width = stringwidth(s, TRUE, '1 1 0' * autocvar_hud_shownames_fontsize);
174 if (width != namewidth)
175 namepos_x += (namewidth - width) / 2;
176 drawcolorcodedstring(namepos, s, '1 1 0' * autocvar_hud_shownames_fontsize, a, DRAWFLAG_NORMAL);
177 drawfontscale = '1 1 0';
182 entity shownames_ent[255];
183 void Draw_ShowNames_All()
186 for(i = 0; i < maxclients; ++i)
189 t = GetPlayerColor(i);
190 if(t == COLOR_SPECTATOR)
194 e = shownames_ent[i];
198 e.classname = "shownames_tag";
200 shownames_ent[i] = e;
204 entcs = entcs_receiver[i];
207 e.healthvalue = entcs.healthvalue;
208 e.armorvalue = entcs.armorvalue;
209 e.sameteam = 1; /* (teamplay && (t == myteam)); */
213 e.healthvalue = 2342;
218 setorigin(e, getplayerorigin(i));
219 if(e.origin == GETPLAYERORIGIN_ERROR)
222 e.csqcmodel_isdead = getplayerisdead(i);