Health Point Bar

From ZDoom Wiki
Jump to navigation Jump to search

Tutorial written and coded by Apothem

Description

This is an example of healthbar script for bosses and minibosses.

To use this script replace mtid with the TID of the monster you want the bar to monitor and replace the value of mmaxhp with the max health of the monster you're monitoring.

Make sure to replace ENTER with (void) if you do not want the script to activate with the player entering the level.

The lumps fillcrit, filldang, fillnorm, and fillcaut are all the filler pics for the bar. Please put these inside the wad outside of any tags. The bar itself, HPMONBAR, is the actual bar pic. also place that inside the wad, but outside of any tags.

Code

#include "zcommon.acs"

int mtid = 666; //Replace the number here with your monster TID

Script 4 ENTER //Replace ENTER with (void) if you want to activate the script
{              //with a line instead of on level entry.
    int hdisp;
    int monhp = GetActorProperty (mtid, APROP_HEALTH);
    int mmaxhp = GetActorProperty (mtid, APROP_SPAWNHEALTH);
    SetFont ("NORMAL");
    hdisp = (monhp * 100 / mmaxhp);
    if (hdisp <= 0)
        hdisp = 0;

    SetHudSize (800,600, FALSE);
    HudMessage (i:hdisp; HUDMSG_FADEOUT, 101, CR_WHITE, 120.1, 10.1, 0.1, 1.0);

    int acounter;
    int bcounter;
    SetFont ("MONHPBAR");
    HudMessage (s:"a"; HUDMSG_FADEOUT, 102, CR_GREEN, 0.1, 1.1, 0.1, 1.0);

    for (acounter = 0; acounter <= hdisp; acounter++)
    {
        if (hdisp <= 0)
            break;

        bcounter = bcounter + 2.0;
        SetFont ("FILLNORM"); //By default, the bar shows as a blue bar.

        if (hdisp < 75) //If the hp is at a caution level (75%) Display a yellow bar.
            SetFont ("FILLCAUT");

        if (hdisp < 50) //If the hp is at a danger level (50%) Display an orange bar.
            SetFont ("FILLDANG");

        if (hdisp < 25) // If the hp is at a critical level (25%) Display a red bar.
            SetFont ("FILLCRIT");

        HudMessage (s:"a"; HUDMSG_FADEOUT, acounter, CR_GREEN, 23.1 + bcounter, 7.1, 0.1, 1.0);
    }
    bcounter = 0;
    acounter = 0;
    Delay (1);
    Restart;
}

Extras

See Also

Tutorials
Enjay's modification of Apothem's HP bar