Sauerworld Forum

health and armour (teammates)

alebrije

  • *
  • 21
  • +4/-0
    • JuGadores Latinos eXtremos
health and armour (teammates)
« on: August 28, 2014, 09:28:30 PM »
For long time i was looking the way to show the health and armour (in my client) above the playermodels (like in warsow) and, thx to your client i can do it. Thx guys for help me (indirectly). all credit is for you guys. 8)

you can see here:


and here the code (file src/fpsgame/render.cpp):
Code: [Select]
void rendergame(bool mainpass)
    {
        if(mainpass) ai::render();

        if(intermission)
        {
            bestteams.shrink(0);
            bestplayers.shrink(0);
            if(m_teammode) getbestteams(bestteams);
            else getbestplayers(bestplayers);
        }

        startmodelbatches();

        fpsent *exclude = isthirdperson() ? NULL : followingplayer();
        loopv(players)
        {
            fpsent *d = players[i];
            if(d == player1 || d->state==CS_SPECTATOR || d->state==CS_SPAWNING || d->lifesequence < 0 || d == exclude || (d->state==CS_DEAD && hidedead)) continue;
            int team = 0;
            if(teamskins || m_teammode) team = isteam(player1->team, d->team) ? 1 : 2;
            renderplayer(d, getplayermodelinfo(d), team, 1, mainpass);
            copystring(d->info, colorname(d));
            if(d->maxhealth>100) { defformatstring(sn)(" +%d", d->maxhealth-100); concatstring(d->info, sn); }

            bool specorsameteam = (player1->state==CS_SPECTATOR) ? true : isteam(player1->team, d->team);
            if(m_teammode && !m_insta && specorsameteam && d->state!=CS_DEAD) {
                // -------------- here is the code ----------------------
                particle_meter(d->abovehead(), d->armour/100.0f, PART_METER, 1, 0xFF4500, 0, 1.0f);
                particle_meter(d->abovehead().add(vec(0, 0, 1)), d->health/100.0f , PART_METER, 1, 0x00FF00, 0, 1.0f);
                particle_text(d->abovehead().add(vec(0, 0, 3)), d->info, PART_TEXT, 1, 0x6496FF, 2.0f);
            }
            else if(d->state!=CS_DEAD) particle_text(d->abovehead(), d->info, PART_TEXT, 1, team ? (team==1 ? 0x6496FF : 0xFF4B19) : 0x1EC850, 2.0f);

        }
        loopv(ragdolls)
        {
            fpsent *d = ragdolls[i];
            int team = 0;
            if(teamskins || m_teammode) team = isteam(player1->team, d->team) ? 1 : 2;
            float fade = 1.0f;
            if(ragdollmillis && ragdollfade)
                fade -= clamp(float(lastmillis - (d->lastupdate + max(ragdollmillis - ragdollfade, 0)))/min(ragdollmillis, ragdollfade), 0.0f, 1.0f);
            renderplayer(d, getplayermodelinfo(d), team, fade, mainpass);
        }
        if(isthirdperson() && !followingplayer() && (player1->state!=CS_DEAD || !hidedead)) renderplayer(player1, getplayermodelinfo(player1), teamskins || m_teammode ? 1 : 0, 1, mainpass);
        rendermonsters();
        rendermovables();
        entities::renderentities();
        renderbouncers();
        renderprojectiles();
        if(cmode) cmode->rendergame();

        endmodelbatches();
    }

Of course needed some adjust, for example in ctf mode we can get more than 100 (of shield) wiht yellow armour and we can get more than 100 (health) wiht the healt bonus.

I prefer this way to show the health and armour than only show some text, if you wanna added to your client will be great.  ;D
Verba volant, scripta manent

alebrije

  • *
  • 21
  • +4/-0
    • JuGadores Latinos eXtremos
Re: health and armour (teammates)
« Reply #1 on: August 31, 2014, 07:45:10 PM »
Update for the health bonus and yellow armour on ctf mode.

You can watch the images here: health bonus and yellow armour bars (updated)

And here the code:
file ../src/fpsgame/render.cpp
Code: [Select]
VARP(showteamhealth, 0, 0, 1); // added: to eneable the health and armour bars.

void rendergame(bool mainpass)
{
/*
* some code here (before our code)
*/
loopv(players)
{
fpsent *d = players[i];
if(d == player1 || d->state==CS_SPECTATOR || d->state==CS_SPAWNING || d->lifesequence < 0 || d == exclude || (d->state==CS_DEAD && hidedead)) continue;
int team = 0;
if(teamskins || m_teammode) team = isteam(player1->team, d->team) ? 1 : 2;
renderplayer(d, getplayermodelinfo(d), team, 1, mainpass);
copystring(d->info, colorname(d));
if(d->maxhealth>100) { defformatstring(sn)(" +%d", d->maxhealth-100); concatstring(d->info, sn); }

// added: here is our code for the health and armour bars
if(d->state!=CS_DEAD) {
bool specorsameteam = (player1->state==CS_SPECTATOR) ? true : isteam(player1->team, d->team);
if(showteamhealth && m_teammode && !m_insta && specorsameteam) {
int hmtype = PART_METER, hvalue = d->health, hcolor = 0x00FF00, hcolor2 = 0;
int amtype = PART_METER, avalue = d->armour, acolor = 0xFF4500, acolor2 = 0;
if(d->health > 100) {
hcolor = 0x006400; hcolor2 = 0x00FF00; hvalue = d->health - 100; hmtype = PART_METER_VS;
}
if((d->armourtype==A_YELLOW) && (d->armour > 100)) { // maybe just d->armour>100     >.<'
acolor = 0xFFD700; acolor2 = 0xFF4500; avalue = d->armour - 100; amtype = PART_METER_VS;
}
particle_health(d->abovehead(), avalue/100.0f, amtype, 1, acolor, acolor2, 1.0f);
particle_health(d->abovehead().add(vec(0, 0, 1)), hvalue/100.0f, hmtype, 1, hcolor, hcolor2, 1.0f);
particle_text(d->abovehead().add(vec(0, 0, 3)), d->info, PART_TEXT, 1, team==1 ? 0x6496FF : 0xFF4B19, 2.0f);
}
else particle_text(d->abovehead(), d->info, PART_TEXT, 1, team ? (team==1 ? 0x6496FF : 0xFF4B19) : 0x1EC850, 2.0f);
}
}
/*
* some more code here (after our code))
*/
}

file ../src/engine/renderparticles.cpp
Code: [Select]
// added: like maxparticletextdistance (for name plates) but for health and armour bars
//        but, would be used maxparticletextdistance to do the same, idk. i liked both:
//        one for the name and one for the bars.
VARP(maxparticlehealthdistance, 0, 128, 10000);

// added: new function for display healt and armour bars.
//        some mix between particle_textcopy and particle_meter.
void particle_health(const vec &s, float val, int type, int fade, int color, int color2, float size)
{
    if(!canaddparticles()) return;
    if(!particletext || camera1->o.dist(s) > maxparticlehealthdistance) return; // or maxparticletextdistance if you
    particle *p = newparticle(s, vec(0, 0, 1), fade, type, color, size);        // dont wanna use maxparticlehealthdistance
    p->color2[0] = color2>>16;
    p->color2[1] = (color2>>8)&0xFF;
    p->color2[2] = color2&0xFF;
    p->progress = clamp(int(val*100), 0, 100);
}

and dont forgget added the prororype for the function particle_health in ../src/shared/iengine.h
Verba volant, scripta manent

Doko

  • **
  • 71
  • +4/-0
Re: health and armour (teammates)
« Reply #2 on: September 01, 2014, 06:37:14 PM »
This can be very useful, thanks for posting it :)

Re: health and armour (teammates)
« Reply #3 on: December 03, 2017, 10:06:14 AM »
Is this code free to use? In other words, what license is it under?

alebrije

  • *
  • 21
  • +4/-0
    • JuGadores Latinos eXtremos
Re: health and armour (teammates)
« Reply #4 on: March 25, 2018, 02:35:33 AM »
Verba volant, scripta manent