With a little help from the wiki and wtg62's existing ACS code, I made a simple, fully working function with which to display HUD messages over actors.
Code: Select all
function void hudmessageonactor(int tid, int msgID, int hudX, int hudY, int xOffset, int yOffset, int range, str sprite, str text, int holdTime, str colour)
{
int dist, angle, vang, pitch, x, y;
if (hudX == 0) { hudX = 640; }
if (hudY == 0) { hudY = 480; }
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);
angle = (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 ((angle < 0.2 || angle > 0.8) && (dist >> 16) < range)
{
if (GetActorPitch(0) >= -0.25 && GetActorPitch(0) <= 0.25)
{
pitch = VectorAngle(dist, GetActorZ(tid) - (GetActorZ(0) + 41.0));
pitch = (pitch + GetActorPitch(0) + 1.0) % 1.0;
if ((hudX/2) * sin(angle) != 0 && cos(angle) != 0 && (hudX/2) * sin(pitch) != 0 && cos(pitch) != 0) // Fixes divide by zero
{
x = hudX/2 - ((hudX/2) * sin(angle) / cos(angle));
y = hudY/2 - ((HUDX/2) * sin(pitch) / cos(pitch));
x+=xOffset;
y+=yOffset;
HudMessage(s:text; HUDMSG_PLAIN, msgID, colour, (x << 16), (y << 16), holdTime);
}
}
}
}Code: Select all
script 1 ENTER
{
Thing_ChangeTID(0, 1+PlayerNumber());
}
script 2 RESPAWN
{
Thing_ChangeTID(0, 1+PlayerNumber());
}
script 3 ENTER CLIENTSIDE
{
while(TRUE)
{
for (int i = 1; i < PlayerCount(); i++)
{
if (PlayerInGame(1) && 1+PlayerNumber() != i && GetActorProperty(i, APROP_Health) > 0)
{
hudmessageonactor(i, i, 640, 480, 0, -120, 512, -1, StrParam(n:i), 0.1, CR_GREEN); // Displays nametags
hudmessageonactor(i, i+64, 640, 480, 0, -112, 512, -1, StrParam(s:"Health: ",d:GetActorProperty(i, APROP_Health),s:"%"), 0.1, CR_WHITE); // Displays health
}
}
Delay(1);
}
}Best called from a 1 tic delay perpetual loop specifying a holdtime of 0.1.
