Announcement

Collapse
No announcement yet.

Health Won't Update on the HUD?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Health Won't Update on the HUD?

    Ok, so I've been reading around on Scaleform for a while now and haven't found much explaining in detail on the Unreal Script side of things. I get that I have to make (and name) the parts of the HUD in Flash, and then import it in udk and call on the components (MC or Dynamic Txt) and have them update. How I actually do this syntax wise I have a limited understanding of at this point in time. If anyone would explain some of this to me and tell me what I am doing wrong I would be great full. Here is my code that I followed from ryanjon2040's post with the example code from here http://forums.epicgames.com/threads/...-A-from-a-noob

    I tailored it to suit my class and read through it quite a few times. This is what I have.

    HSGFxHUD
    Code:
    class HSGFxHUD extends GFxMoviePlayer;
    
    var float LastHealthpc;
    var GFxObject SFBar_MC;
    var GFxObject SFHealth_txt;
    var HSPlayerController PlayerOwner;
    var HSPawn HSP;
    var PlayerController myPC;
    
    function int roundNum(float NumIn)
    {
        local int iNum;
        local float fNum;
        
        fNum=NumIn;
        iNum=int(fNum);
        fNum-=iNum;
        if (fNum >= 0.5f)
        {
            return (iNum + 1);
        }
        else
        {
            return iNum;
        }
    }
    
    function int HealthFunc(int val, int max)
    {
        return roundNum((float(val) / float(max)) * 100.0f);
    }
    
    function Init2(PlayerController PC)
    {
        Start();
        Advance(0.f);
        LastHealthpc = -1337;
        SFBar_MC = GetVariableObject("_root.SFBar_MC"); //Your Healthbar meter. eg: GetVariableObject("_root.health_mc");
    }
    
    function TickHUD()
    {
        myPC = GetPC();
        HSP = HSPawn(myPC.Pawn);
        
        if (HSP == None)
        {
            return;
        }
        else
        {
            if (LastHealthpc != HealthFunc(HSP.Health, HSP.HealthMax))
            {
                LastHealthpc = HealthFunc(HSP.Health, HSP.HealthMax);
                SFBar_MC.SetFloat("_xscale", (LastHealthpc > 100) ? 100.0f : LastHealthpc);
                SFHealth_txt.SetString("text", round(LastHealthpc)$"%");
            }
        }
    }
    defaultproperties
    {
        bDisplayWithHudOff = false
        MovieInfo=SwfMovie'UDKHUD.HSHealthHUD' //Your SWFMovie
        //bEnableGammaCorrection = false;
        bAllowInput = false;
        bAllowFocus = false;
    }

    HSHUD
    Code:
    class HSHUD extends UDKHUD;
    
    var HSGFxHUD HudMovie;
    var HSPlayerController PO;
    
    //DISABLES THE GIANT RED BOOGIE HIT EFFECT FROM UTHUD.
    function DisplayHit(vector HitDir, int Damage, class<DamageType> damageType)
    {
        
    }
    
    singular event Destroyed()
    {
        if (HudMovie != none)
        {
            HudMovie.Close(true);
            HudMovie = none;
        }
    }
    
    simulated function PostBeginPlay()
    {
        super.PostBeginPlay();
        
        HudMovie = new class'HSGFxHUD';
        HudMovie.PlayerOwner = PO;
        HudMovie.SetTimingMode(TM_Real);
        HudMovie.Init2(HudMovie.PlayerOwner);
        HudMovie.SetViewScaleMode(SM_ExactFit);
        HudMovie.SetAlignment(Align_TopLeft);
    }
    
    event PostRender()
    {
        HudMovie.TickHUD();
        DisplayConsoleMessages();
        DisplayLocalMessages();
        DisplayKismetMessages();
    }
    
    defaultproperties
    {
    
    }
    And here is a picture explaining the HUD for a visual
    [IMG][/IMG]

    #2
    Here's one thing I noticed...

    You have two GFxObjects but I only see one being assigned to an object in your menu.

    To do that you can add the following to your Init2 function:
    SFHealth_txt = GetVariableObject("_root.SFHealth_txt"); // the quoted text should match what's in your action script file.

    Comment


      #3
      Oh I see. Thanks. K got it updated but still to no avail on the updating, the bar doesn't move and the text doesn't change from 100%.

      Code:
      function Init2(PlayerController PC)
      {
          Start();
          Advance(0.f);
          LastHealthpc = -1337;
          SFBar_MC = GetVariableObject("_root.SFHealthBar_MC.SFBar_MC"); //Your Healthbar meter. eg: GetVariableObject("_root.healthbar.health_mc");
          SFHealth_txt = GetVariableObject("_root.SFHealthBar_MC.SFHealth_txt"); // the quoted text should match what's in your action script file.
      }
      I'm gonna play with it some more and keep tryin to figure it out. Let me know if you think of anything it could be.
      Also, I know that actionscript is used to do effect like bobbing ect. But do I actually need to code anything for the health bar to move itself, or does all that get taken care of (like i think) in UScript?

      Comment


        #4
        It could still be a lot of things, more information would help. Here's some suggestions and things I'd do if facing a similar problem.

        1. Check to see if the menu the getting updated at all. One test could be to set the default text in your actionscript to something other then what you expect and see if it ever gets updated.
        2. Check to see if the UScript code is getting called with the proper values. For example you could add `Log("Debug: HealthVal:"@HSP.Health@"Rounded To"@round(LastHealthpc)$"%"); to your TickHud function.
        3. If the problem you're facing is still difficult try to reduce it by taking away functions that are not fully needed. Such as looking up the health value and trying to round it. Until you get your code to communicate with ActionScript doing additional processes adds difficulty to solving your issue.
        4. Always make sure you're checking your logs, noticing something like Accessed none on something you're trying to use can save a lot of debugging.

        Comment


          #5
          Did you ever solve this problem? I'm stuck on it too.

          Comment

          Working...
          X