hudmessageonactor
From ZDoom Wiki
This function will place text or a sprite (depending on parameters passed) at the onscreen position of an actor with the specified tid, as long as it's in range (fixed mapunits).
function void hudmessageonactor(int tid, int range, str sprite, str text)
{
int dist, ang, vang, pitch, x, y;
int HUDX = 640;
int HUDY = 400;
int offset = 0;
if(sprite != -1)
{
setfont(sprite);
text = "A";
offset = 0.1;
}
sethudsize(HUDX, HUDY, 1);
x = getactorx(tid) - getactorx(0);
y = getactory(tid) - getactory(0);
vang = vectorangle(x,y);
ang = (vang - GetActorAngle(0) + 1.0) % 1.0;
if(((vang+0.125)%0.5) > 0.25) dist = fixeddiv(y, sin(vang));
else dist = fixeddiv(x, cos(vang));
if ((ang < 0.2 || ang > 0.8) && dist < range)
{
pitch = vectorangle(dist, getactorz(tid) - (getactorz(0) + 41.0));
pitch = (pitch + GetActorPitch(0) + 1.0) % 1.0;
x = HUDX/2 - ((HUDX/2) * sin(ang) / cos(ang));
y = HUDY/2 - ((HUDX/2) * sin(pitch) / cos(pitch));
hudmessage(s:text; HUDMSG_PLAIN, 1, CR_UNTRANSLATED, (x<<16)+offset, (y<<16)+offset, 0);
}
else
hudmessage(s:" "; HUDMSG_PLAIN, 1, CR_UNTRANSLATED, 0, 0, 0);
}