Custom Hud

From ZDoom Wiki
Jump to navigation Jump to search

Assumed Knowledge

It is assumed that before you begin this tutorial, you are familiar with the following concepts:

Understanding these concepts is vital to understanding the following tutorial.

Scripting a Custom Hud

You can't disable or alter the built-in HUD, and it varies depending on how large the user has their screen set to. You have to have your script work around the existing HUD. What you can do, though, is have your script watch the value of the screenblocks CVAR (using GetCVar) and alter the HUD accordingly. The values correspond to the HUD as follows:

   3-9: There is a border around the player's view, and the status bar is displayed (why anyone would use this now, I don't know...) 
   10: Fullscreen with status bar 
   11: Fullscreen without status bar, ZDoom HUD enabled 
   12: Fullscreen with no HUD whatsoever 

** Thanks To Hotwax for this information

The Graphics

1) Create a graphic or graphics you want to use for the HUD.

Keep in mind the size of the average users' screen resolution, e.g. 640x480 or 800x600. This is important because a 1024x768 HUD graphic does not scale down well.


2) Load all the graphics you just made into your wad file using a lump management tool. Make note of each graphics name as you will need them in the ACS script.

ACS

1) If you use doombuilder open MAP01 of your wad and select "edit" from the "scripts" menu. To display the new HUD bar you use somthing like this:

   Script 1 ENTER 
   { 
       SetHudSize (800, 600, 1);
       SetFont("HUDLUMP");
       HudMessage (s: "a";HUDMSG_PLAIN,1000,CR_UNTRANSLATED,400.1,550.1,0.0);
   }

In this script, SetFont tells Doom that the font to use is actually the lump name of your custom statbar graphic ("HUDLUMP"), and printing "a" in the HudMessage, as above, will display that graphic. Notice that it is also an "ENTER" script, because it needs to be activated by the player so that you can easily access their inventory and health information.

** Thanks to Cyrez for the information.


2) Next comes displaying the player information. We'll start with health:

       SetHudSize (320, 200, 1);
       SetFont("BIGFONT");
       HudMessage (i: GetActorProperty(0,APROP_HEALTH);
                      HUDMSG_PLAIN,999,CR_UNTRANSLATED,90.1,175.1,0.0);

Notice I've changed the sethudsize to accomodate the font "BIGFONT", and the HudMessage coordinates will vary as a result. Finally, notice that the HudMessage ID is lower than that of the stat-bar HudMessage ID so that the health count will display infront of the stat-bar.

NB: I've deliberately left the HudMessage coordinates slightly unaligned in order to encourage people to find the correct offsets for themselves.

Using other HudMessages such as:

        HudMessage (i: CheckInventory("Armour");
                      HUDMSG_PLAIN,999,CR_UNTRANSLATED,175.1,175.1,0.0);
        HudMessage (i: CheckInventory("Clip");
                      HUDMSG_PLAIN,999,CR_UNTRANSLATED,175.1,175.1,0.0);

...you will also be able to figure out how to display the armor and ammo counts.


3) And finally, while this may sound tricky it's actually very straightforward - turning your custom stat-bar on and off according to how the player has their HUD displayed, as discussed earlier.

       if (getcvar ("screenblocks") <= 10) 
           {   /*Do your Custom Hud Stuff here*/}
       else
           {   /*Turn it off with HudMessages that print nothing*/}

These are obviously the very basic concepts you need to be familiar with in order to script your own custom hud. Use what you've learnt here, and have a look through the example scripts posted below to try and understand more about it.

Example Scripts