Hiding HUD parts
Availability
ZandroX behaviour.
fua_SetHudHiddenexists only on ZandroX; elsewhere it does nothing and returns 0, so the engine's HUD parts simply stay on screen.
| Number | Function | Returns |
|---|---|---|
| 24080 | fua_SetHudHidden(int parts) |
the parts that were hidden before the call |
| Part | Value | Hides |
|---|---|---|
FUA_HUD_COOPINFO |
1 | the teammates' names, health, armour and weapons down the top corners in co-op and team games |
FUA_HUD_TARGETNAME |
2 | the name, and the details, of the player or monster under the crosshair |
zt-bcc's zcommon.bcs declares them, and so does fua.acs for ACC
(Compiling ACS).
Usage
A menu built from HudMessages shares the screen with text the engine draws on its own, which no HudMessage
can move. fua_SetHudHidden hides those parts while the menu is open:
int was = fua_SetHudHidden( FUA_HUD_COOPINFO | FUA_HUD_TARGETNAME ); // the menu opens
...
fua_SetHudHidden( was ); // the menu closes
- The call sets the whole list. Each call hides the parts it names and shows every other one;
0shows them all again. - It returns what was hidden before, so a menu that opens over another hands that one's parts back when it closes. That holds only while menus close in the reverse order they opened; see Best practices for menus that overlap.
- Only the machine running the script changes. Nothing is sent over the network, and other players keep their HUD as it was.
- It never sticks. A map change, a new game, a loaded savegame or a connect to a server shows every part again, and savegames don't keep it. A menu script that dies with the menu open costs the player their co-op info until the next map at most.
- It only hides. A player's
cl_drawcoopinfo 0and a server'ssv_nocoopinfostill turn the co-op info off; a script can't turn it on. - To draw over the co-op info instead of hiding it, use the
HUDMSG_LAYER_FUA_TOPlayer; a menu can do both.
Online
- Call it from a
clientsidescript. A server's own scripts have no HUD, and there the call does nothing and returns 0. - A clientside script runs on every client the server starts it on. To hide one player's HUD from a script
the server runs with
ACS_ExecuteAlways, return early on every other client, as the second example does. - No setting or cheat is involved: what is hidden is the player's own screen.
Examples
Each example is a whole library: compile it with zt-bcc, add it to LOADACS and run its scripts with
pukename.
A shop menu: open, it hides the co-op info and the target's name and draws its title on the top layer; closed, it gives back whatever was hidden before it opened:
#library "fuashop"
#import "zcommon.bcs"
int partsBefore;
script "ShopOpen" ( void ) clientside {
partsBefore = fua_SetHudHidden( FUA_HUD_COOPINFO | FUA_HUD_TARGETNAME );
SetHudSize( 640, 480, 0 );
HudMessage( s: "SHOP"; HUDMSG_PLAIN | HUDMSG_LAYER_FUA_TOP, 900, CR_GOLD, 320.0, 60.0, 0 );
Log( s: "shop open, hidden before: ", d: partsBefore );
}
script "ShopClose" ( void ) clientside {
int hidden = fua_SetHudHidden( partsBefore );
HudMessage( s: ""; HUDMSG_PLAIN | HUDMSG_LAYER_FUA_TOP, 900, CR_UNTRANSLATED, 0.0, 0.0, 0.1 );
Log( s: "shop closed, it had hidden ", d: hidden );
}
A script the server starts for one player with ACS_ExecuteAlways runs on every client, so each client checks
that the activator is its own player before hiding anything:
#library "fuahudme"
#import "zcommon.bcs"
script "HideForMe" ( void ) clientside {
if ( PlayerNumber( ) != ConsolePlayerNumber( ) ) {
terminate;
}
fua_SetHudHidden( FUA_HUD_COOPINFO );
Log( s: "co-op info hidden for player ", d: PlayerNumber( ) );
}
ACC compiles both with fua.acs included in place of zcommon.acs. The shop, for ACC:
#library "accshop"
#include "fua.acs"
int partsBefore;
script "AccShopOpen" (void) clientside
{
partsBefore = fua_SetHudHidden(FUA_HUD_COOPINFO | FUA_HUD_TARGETNAME);
SetHudSize(640, 480, 0);
HudMessage(s: "SHOP"; HUDMSG_PLAIN | HUDMSG_LAYER_FUA_TOP, 900, CR_GOLD, 320.0, 60.0, 0);
Log(s: "shop open, hidden before: ", d: partsBefore);
}
script "AccShopClose" (void) clientside
{
int hidden = fua_SetHudHidden(partsBefore);
HudMessage(s: ""; HUDMSG_PLAIN | HUDMSG_LAYER_FUA_TOP, 900, CR_UNTRANSLATED, 0.0, 0.0, 0.1);
Log(s: "shop closed, it had hidden ", d: hidden);
}
Best practices
- Hide only while the menu is up, and give the parts back on every way out: the close key, the player dying, the menu's own timeout.
- Hand back the returned value rather than
0when one menu opens over another and always closes first, so the menu under it keeps its parts hidden. - Keep one owner when menus overlap. If a menu can close while one it opened is still up (a shop whose
loop ends after it opens the main menu), its hand-back shows the co-op info again under the other menu.
Give each menu a bit, keep the open ones in one variable, and call
fua_SetHudHiddenfrom that one place each time the set changes, so the parts stay hidden while any menu is open:
#library "fuahudow"
#import "zcommon.bcs"
#define MENU_MAIN 1
#define MENU_SHOP 2
int openMenus;
// The one place that calls fua_SetHudHidden: hidden while any menu is open.
void MenusChanged( void ) {
fua_SetHudHidden( openMenus ? FUA_HUD_COOPINFO | FUA_HUD_TARGETNAME : 0 );
}
void MenuOpened( int menu ) {
openMenus |= menu;
MenusChanged();
}
void MenuClosed( int menu ) {
openMenus &= ~menu;
MenusChanged();
}
script "ShopThenMenu" ( void ) clientside {
MenuOpened( MENU_SHOP );
MenuOpened( MENU_MAIN ); // the main menu opens from the shop
MenuClosed( MENU_SHOP ); // and the shop's loop ends first
// Asking for the same parts again changes nothing and returns what is hidden now.
Log( s: "main menu open, hidden: ", d: fua_SetHudHidden( FUA_HUD_COOPINFO | FUA_HUD_TARGETNAME ) );
MenuClosed( MENU_MAIN );
Log( s: "every menu closed, hidden: ", d: fua_SetHudHidden( 0 ) );
}
- Two mods share one list. Each machine has a single set of hidden parts, so two mods' menus open at once can show each other's parts on close; a mod and its add-ons should route their menus through one owner.
- Use it for screens that need the space, such as menus, shops and cutscenes; the co-op info is how teammates find each other, so a mod should not hide it for good.