No announcement yet.

Modifying the HUD

  • Filter
  • Time
  • Show
Clear All
new posts

    Modifying the HUD

    Hi guys,

    Another newbie question, hopefully this one's a bit more straightforward and will get some suggestions

    I've made a class called GiftigBombcopter extending ONSAttackCraft (i.e. a raptor) which has a modified alt fire, which now drops nuclear warheads (redeemer projectiles modified to just drop, with the smoke removed, etc.). The class has warheads and max_warheads variables to keep track of number of warheads onboard, and will play the MenuSounds.Denied1 sound instead of dropping a bomb when warheads reaches 0.

    This works great. What I would like to do now, however, is to modify the HUD for this vehicle to indicate how many warheads are currently onboard. I've never played around with the HUD before and I'm new to UT editing in general, so any tips are appreciated.

    Thanks in advance.

    As I’m sure you know, the HUD differs slightly from gametype to gametype. The different HUDs each have their own class, and which class is used for a given gametype is determined by the "HUDType" variable in that gametype’s class. xDeathMatch, for example, uses XInterface.HudCDeathMatch. Since you don’t want to go modifying preexisting code, you’ll want to begin by extending one of the gametype classes (the natural choice here is ONS) and switch that variable to your custom HUD class.

    I myself am trying to dissect the code that displays the weapon bar in DeathMatch, and I’ll be taking a look at other elements of the HUD as well. From what I learn I may be able to give you a lot more information, but I’m eager to see what others may post all the same. I too could always a few pointers from the pros, being a bit of a newbie myself.

    EDIT: Hmm, ya know, I'm not sure if a mutator could change the HUDType. I'm not familiar with the full capabilities of mutators, being that I don't use many myself and I haven't gone digging through the code thoroughly, but it would be much cleaner than subclassing gametypes. It's a question for someone better informed than me.


      You do not want to change the hud type unless its a new gametype altogether. You can use mutators (or even other actors that exist clientside) though to add HUDOverlays to a player's HUD (which can do much of the same thing as a HUD Canvas).

      Actually, vehicles already support the spawning and use of HUDOverlays (take a look through Vehicle.uc). The ONSVehicle class also has a DrawHUD function. You could either modify the drawHUD function, or make a customized HUOverlay to draw the remaining bomb count information.


        Never heard of customizing the Hud but It would be nice if someone could port the UT3 Hud to UT2004.


          Thanks guys, I'm looking at ONSVehicle and I can see how the HUD overlay is being drawn to the screen. What I really need to do then, is create a HUD overlay... which is where there's another problem as so far I've just been scripting and using existing graphics from the game.

          I tried creating a static mesh in UnrealEd, by putting together an object using brushes and then converting to a static mesh, but it wanted to save it as part of my package, and then simply created a separate file in a different directory, rather than putting it with the classes for my package. I don't yet know how to even begin editing textures, HUD overlays, etc. This is probably best asked in one of the other forums, but could anyone give me some ideas of how to do this?

          Thanks for the information so far.


            Making a new HUD Overlay is easy. Here is a code stub, but you should read the canvas class and the material at this link to understand all of the canvas functions.
            class HudOverlay_YourBomberClass extends HudOverlay;
            // bomb variables
            var int MaxBombs, CurrentBombs;
            function Render( Canvas C ){
                // draw things using the Canvas functions e.g: C.DrawText
                // grab the values from your bomber class, which since it is being driven, *should* be the pawn of the playercontroller owner (hence casting PlayerOwner.Pawn to your bomber)
                CurrentBombs = yourbomberclass(PlayerOwner.Pawn).NumberOfBombs;
                MAxBombs = yourbomberclass(PlayerOwner.Pawn).MaxBombs;
                C.Font = C.MedFont; // set the correct font size for the text, check the canvas class to see your other choices
                // Now draw the text on the HudOverlay
                C.DrawTextJustified(CurrentBombs@"/"@MaxBombs, 1, Blah, Blah , Blah, blah);// fill in the blahs to set the correct screen position of the text


              Thanks for the example meowcat; I'll give that a try in a little while. I was also hoping to put an icon representing the bomb next to it to make it clearer for quick reference, and change this text while loading warheads. I assume the latter could be simply achieved by adding something like this to the render function:

              local GiftigBombcopter gbc;
                // loading text here
              Thanks for the link as well by the way, going to be having a look through that


                Yup! For all of the drawing functions review that link about the Canvas class, and do some digging through the normal UT2k4 GUI classes (they have all kinds of examples of how to draw icons and text on the Canvas). The assaultRifle.uc file also has some good example code if I recall correctly for those little grenade icons.


                  Thanks, I was planning on looking at stuff like that for the drawn-on icons, yeah. At the moment I'm more concerned about how to create the icons etc to be drawn onto the screen; as I said, I've only used pre-existing graphics so far, and I don't know how to properly create my own static meshes and textures. UnrealEd said it added it to my package but I assume that means it added it to the compiled package file, which seems a bit inconvenient as it sounds like it'll be overwritten the next time I recompile my scripts.


                  Error when trying to use PlayerOwner, and on further inspection there is no variable with that name. Did you mean to imply this?

                  local PlayerController PlayerOwner;
                  That's what I'm trying now, anyway.


                    Hmm it's not even attempting to load the HUD overlay, and I'm not sure why...

                    // HUD OVERLAY CLASS
                    class HudOverlay_GiftigBombcopter extends HudOverlay;
                    function render(Canvas c)
                     local PlayerController p;
                     local GiftigBombcopter vehicle;
                     local GiftigBombcopterWeapon weapon;
                     log("render function reached");
                     log("vehicle != None"); //remove
                     log("weapon != None"); //remove
                     c.drawTextJustified(weapon.warheads@" / "@weapon.max_warheads@" warheads",1,10,10,100,100); //pure guess with the dimensions, need to read that page a bit more
                     VehicleNameString="Giftig Bomber";
                     VehiclePositionString="in a Giftig Bomber";
                    Any ideas what's wrong? I'm not getting any log messages.

                    Looking at the Vehicle class, the overlay is spawned if the HUDOverlayClass variable is not None, upon calling of ActivateOverlay(true). This is called from the ClientKDriverEnter function, as long as the bBehindView variable of the PlayerController is false... can someone tell me what this variable means? Maybe it's set to true...

                    FURTHER EDIT:

                    To test this, I tried triggering the vehicle's activateOverlay(true); at the start of the altFire function for the weapon, but I still didn't get any log messages.


                      Did you read through the code in the vehicle (or maybe it was SVehicle, or ONS vehicle) that explains when the HUDOverlay is spawned? You can't be in third person view when in the vehicle, otherwise the overlay wont spawn. To test this, get into your vehicle, scorll the mousewheel so the view is in FP, then hop out and hop back in and see if the HUD shows up.


                        Okay two issues:

                        1 - I always use third-person mode in vehicles, and so does everyone else I know. Is there a way I can make the overlay appear while in third-person mode?

                        2 - The overlay isn't appearing when I do as you suggested, and I'm not getting any log messages either.


                          Modify the ClientKDriverEnter function to always spawn the overlay. Or alternatively (and this is probably the way to go) modify the DrawHUD function itself to draw the ammo stuff to the screen.


                            Originally posted by meowcat View Post
                            Or alternatively (and this is probably the way to go) modify the DrawHUD function itself to draw the ammo stuff to the screen.
                            Did that, worked immediately. I don't know why I was messing about with overlays to begin with

                            Thanks for the help. Now I just need to sort out the icon, and look through that link to figure out how to draw it correctly.


                              Can I have the sripts when ur done, im kinda stuck at hud's. Would appreciate it!