VERC: TriAPI based team overlays Last edited 3 months ago2019-04-21 13:04:50 UTC by Penguinboy Penguinboy

This tutorial will show you how to make use of the Triangle API to make team overlays so you blind players that can't tell the difference between skins can finally tell the difference by a green circle above your team mates' heads. All you need to do is open your CLIENT project, open up the tri.cpp file, then go into the HUD_DrawTransparentTriangles() function and add this code anywhere before the closing brace:
// render team overlays
cl_entity_t* thisplayer = gEngfuncs.GetLocalPlayer();
float size = 25;
vec3_t angles, forward, right, up;
gEngfuncs.GetViewAngles((float*)angles);
AngleVectors(angles, forward, right, up);

// only for teamplay
if (gHUD.m_Teamplay) {
    for (int i = 0; i < MAX_PLAYERS + 1; i++) {
        cl_entity_t* player = gEngfuncs.GetEntityByIndex(i);
        int team = g_PlayerExtraInfo[player->index].teamnumber;
        // they aren't a player, continue the looping
        if (g_PlayerInfoList[i].name == NULL)
            continue;
        // if they are this player, then continue
        if (player == thisplayer)
            continue;
        if (g_PlayerExtraInfo[thisplayer->index].teamnumber == team) {
            // render the sprite above their heads
            if (player) {
                vec3_t org;
                vec3_t point;
                org = player->origin;

                // starting position
                org.z += 52;
                org = org + right * -size / 2;

                /*
                org + right * size;
                org + up * size;
                */
                if (gHUD.m_hsprCursor == 0) {
                    char sz[256];
                    sprintf(sz, "sprites/flare3.spr");
                    gHUD.m_hsprCursor = SPR_Load(sz);
                }

                if (!gEngfuncs.pTriAPI->SpriteTexture((struct model_s*)gEngfuncs.GetSpritePointer(gHUD.m_hsprCursor), 0))
                    return;

                // Create a triangle, sigh
                gEngfuncs.pTriAPI->RenderMode(kRenderTransAdd);
                gEngfuncs.pTriAPI->CullFace(TRI_NONE);
                gEngfuncs.pTriAPI->Begin(TRI_QUADS);

                // now draw that tiny quad
                // the triapi calls are pretty similar to opengl
                gEngfuncs.pTriAPI->Color4f(0.0, 1.0, 0.0, 1.0);

                gEngfuncs.pTriAPI->Brightness(1.0);
                gEngfuncs.pTriAPI->TexCoord2f(1, 1);
                point = org;
                gEngfuncs.pTriAPI->Vertex3fv(point);

                gEngfuncs.pTriAPI->TexCoord2f(1, 0);
                point = org + up * size;
                gEngfuncs.pTriAPI->Vertex3fv(point);

                gEngfuncs.pTriAPI->TexCoord2f(0, 0);
                point = org + right * size + up * size;
                gEngfuncs.pTriAPI->Vertex3fv(point);

                gEngfuncs.pTriAPI->TexCoord2f(0, 1);
                point = org + right * size;
                gEngfuncs.pTriAPI->Vertex3fv(point);

                gEngfuncs.pTriAPI->End();
                gEngfuncs.pTriAPI->RenderMode(kRenderTransAdd);
            }
        }
    }
}
You can change the flare3.spr to any sprite you want. You just need to make sure its there, or it won't work at all. Have fun!
-Mazor
This article was originally published on the Valve Editing Resource Collective (VERC).
TWHL only archives articles from defunct websites. For more information on TWHL's archiving efforts, please visit the TWHL Archiving Project page.

Comments

You must log in to post a comment. You can login or register a new account.