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
7 const float SHOWNAMES_FADESPEED = 4;
10 if(!autocvar_hud_shownames)
13 if(self.sv_entnum == player_localentnum && !autocvar_chase_active)
16 if(self.sameteam || (!self.sameteam && autocvar_hud_shownames_enemies))
18 self.origin = getplayerorigin(self.sv_entnum-1);
19 self.origin_z += autocvar_hud_shownames_offset;
23 /* WIP, why does trace_ent != self not work as intended here?
24 if(autocvar_hud_shownames_enemies != 2) // player has to point at enemy if so
26 traceline(view_origin, view_origin + view_forward * MAX_SHOT_DISTANCE, MOVETYPE_FLY, world);
27 print("trace_endpos: ", vtos(trace_endpos), " view_origin: ", vtos(view_origin), "\n");
32 traceline(self.origin, view_origin, 1, self);
36 o = project_3d_to_2d(self.origin);
39 if(autocvar_hud_shownames_antioverlap)
41 // fade tag out if another tag that is closer to you overlaps
43 for(e = world; (e = find(e, classname, "shownames_tag")); )
47 eo = project_3d_to_2d(e.origin);
48 if not(eo_z < 0 || eo_x < 0 || eo_y < 0 || eo_x > vid_conwidth || eo_y > vid_conheight)
51 if(vlen((eX * o_x + eY * o_y) - eo) < autocvar_hud_shownames_antioverlap_distance && vlen(self.origin - view_origin) > vlen(e.origin - view_origin))
60 if(!self.sameteam && trace_endpos != view_origin) // out of view, fade out
61 self.alpha = max(0, self.alpha - SHOWNAMES_FADESPEED * frametime);
62 else if(!self.healthvalue) // dead player, fade out slowly
63 self.alpha = max(0, self.alpha - SHOWNAMES_FADESPEED * 0.25 * frametime);
64 else if(overlap) // tag overlap detected, fade out
65 self.alpha = max(0, self.alpha - SHOWNAMES_FADESPEED * frametime);
67 self.alpha = min(1, self.alpha + SHOWNAMES_FADESPEED * frametime);
73 dist = vlen(self.origin - view_origin);
76 a = autocvar_hud_shownames_alpha;
78 if(autocvar_hud_shownames_maxdistance)
80 if(dist >= autocvar_hud_shownames_maxdistance)
82 a *= ((autocvar_hud_shownames_maxdistance - autocvar_hud_shownames_mindistance) - max(0, dist - autocvar_hud_shownames_mindistance)) / (autocvar_hud_shownames_maxdistance - autocvar_hud_shownames_mindistance);
90 if(autocvar_hud_shownames_resize) // limit resize so its never smaller than 0.5... gets unreadable
91 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);
93 // draw the sprite image
94 if not(o_z < 0 || o_x < 0 || o_y < 0 || o_x > vid_conwidth || o_y > vid_conheight)
99 mySize = (eX * autocvar_hud_shownames_aspect + eY) * autocvar_hud_shownames_fontsize;
100 myPos = o - '0.5 0 0' * mySize_x - '0 1 0' * mySize_y;
106 myPos_x += 0.5 * (mySize_x / resize - mySize_x);
107 myPos_y += (mySize_y / resize - mySize_y);
109 vector namepos; // this is where the origin of the string
113 namewidth = mySize_x;
115 if(autocvar_hud_shownames_status && teamplay)
119 if(self.healthvalue > 0)
121 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", self.healthvalue/autocvar_hud_panel_healtharmor_maxhealth, 0, 1, '1 0 0', a, DRAWFLAG_NORMAL);
123 if(self.armorvalue > 0)
124 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", self.armorvalue/autocvar_hud_panel_healtharmor_maxarmor, 0, 0, '0 1 0', a, DRAWFLAG_NORMAL);
130 s = GetPlayerName(self.sv_entnum-1);
131 if((autocvar_hud_shownames_decolorize == 1 && teamplay) || autocvar_hud_shownames_decolorize == 2)
132 s = playername(s, GetPlayerColor(self.sv_entnum-1));
134 drawfontscale = '1 1 0' * resize;
135 s = textShortenToWidth(s, namewidth, '1 1 0' * autocvar_hud_shownames_fontsize, stringwidth_colors);
138 width = stringwidth(s, TRUE, '1 1 0' * autocvar_hud_shownames_fontsize);
140 if (width != namewidth)
141 namepos_x += (namewidth - width) / 2;
142 drawcolorcodedstring(namepos, s, '1 1 0' * autocvar_hud_shownames_fontsize, a, DRAWFLAG_NORMAL);
143 drawfontscale = '1 1 0';