Results 1 to 9 of 9
  1. #1
    MSgt. Shooter Person
    Join Date
    Feb 2012
    Posts
    72

    Default accessing custom variables on the hud

    Does anybody know how to correctly show a custom variable on the HUD? I have been having a lot of trouble on this. When I use this code on the HUD, it doesn't seem to work (it always shows as 0):

    Code:
    local WCPawn p;
    p=WCPlayerPawn(PawnOwner)
    DigitsMoney.Value = p.Money;
    The WCPlayerPawn is my referenced object, Money is my custom variable and DigitsMoney is the variable that shows my custom variable on the HUD. This does show up on the HUD as a 0. When i replace DigitsMoney.Value with something like PawnOwner.health it works fine and shows the health but that's not what I want. The Money variable is set to a totally different number! Is my code wrong or something! Please help!

  2. #2
    Redeemer
    Join Date
    Jan 2004
    Location
    The great Pacific Northwest
    Posts
    1,426

    Default

    hmm, a couple of questions:
    1. Does your UT2004 log file say anything specifically error related?
    2. Are you positive that your custom HUD and custom pawn are being used by your game/mutator (sounds like the HUD is, but are you sure about the pawn?)
    3. How often does the "DigitsMoney.Value=p.Money;" statement get called, only once, or every draw call to the HUD?
    4. Is WCPlayerPawn a subclass of WCPawn?
    "What do you mean it doesn't exist clientside?"
    YARM: where player's Lean, Prone, Mantle, Dash, Crouch Jump, 'Parkour' and slide around all with generic realistic weapons!
    My Generic Mods for UT2K4:
    Yet Another Real-life Mod: Realistic weapons, unoriginal gameplay, w/ cheap CODMW knockoff mutator
    TD Vehicles: HUMV, MI4Hound, Motorcycle, IFAV Jeep, UH-60, MH-53 & AH-6 Helicopters, Abrams Tank

  3. #3
    MSgt. Shooter Person
    Join Date
    Feb 2012
    Posts
    72

    Default

    Thank you for answering. I looked at my UT2004 Log file for errors and came up THIS same thing HUNDREDS of times. It makes the log file really big:

    Code:
    Warning: WCHudCDeathmatch DM-MyMap.WCHudCDeathmatch0 (Function WCGame.WCHudCDeathmatch.DrawWarriorImages:0031) Accessed None 'P'.
    That is definitely the error. The piece of code I wrote above was definitely wrong. I also tried at the beginning " local WCPlayerPawn P; " but that didn't work either.
    WCPlayerPawn is certainly a subclass WCPawn.

    The "DigitsMoney.Value=p.Money;" gets called when the HUD is drawn. It lies under DrawHudPassA:

    Code:
    Simulated function DrawHudPassA (Canvas C)
    {
    local pawn RealPawnOwner;
    local class<ammunition> ammoclass;
    
    ZoomFadeOut(C);
    DrawWarriorImages(C);
    ...
    It lies right under where the Local Variables are being defined near the top. This part is just taken out of the top of the function. Is this in the correct position?

    And yes the Custom Pawn is using that value because I tried in the console "Get WCGame.WCPlayerPawn Money" it gives me my default value 500. That is the value I want shown on the HUD but it seems to be 0. I'm also not using any mutators.

    I hope this issue gets figured out soon.
    Last edited by gruntkiller4000; 04-20-2012 at 03:45 AM.

  4. #4
    Redeemer
    Join Date
    Jan 2004
    Location
    The great Pacific Northwest
    Posts
    1,426

    Default

    The error message means that the PawnOwner cannot be cast to a WCPlayerPawn, which means pawnOwner is none, or is not a WCplayerPawn. The use of the "get" console command would normally retrieve your pawn's information, but may also grab another pawn's value (that IS a WCPlayerPawn). If "get" fails to find an actor of the class currently loaded I *think* it may simply grab the class's default value.

    Use the "Showdebug" console command to verify that your pawn is in fact a WCPlayerPawn.
    "What do you mean it doesn't exist clientside?"
    YARM: where player's Lean, Prone, Mantle, Dash, Crouch Jump, 'Parkour' and slide around all with generic realistic weapons!
    My Generic Mods for UT2K4:
    Yet Another Real-life Mod: Realistic weapons, unoriginal gameplay, w/ cheap CODMW knockoff mutator
    TD Vehicles: HUMV, MI4Hound, Motorcycle, IFAV Jeep, UH-60, MH-53 & AH-6 Helicopters, Abrams Tank

  5. #5
    MSgt. Shooter Person
    Join Date
    Feb 2012
    Posts
    72

    Default

    I used 'Showdebug' and did read my Tag as 'WCPawn', State 'WCPawn'. It wasn't WCPlayerPawn!!!
    It took me 10 minutes or so to figure this out. I had to change the DefaultPlayerClassName="WCPawn" to "WCPlayerPawn" for both my custom deathmatch and team deathmatch games. But THANKS. But there is still one more thing. If the player dies the value resets. :\
    I moved the Money variables to WCPlayer. I changed a bit of things on the WCHudCDeathmatch using "P=WCPlayer(PlayerOwner)". THAT worked still (The value still shows on the HUD). But, if I pick up a money item (that changes the variable money) it won't change! The "set" command certainly changes the value so it's not the HUD. Here's my code for my Money pickup under the touch function:

    Code:
    A = WCPlayer(Other)
    LastMoney = P.Money;
    P.Money = LastMoney + MoneyAmount;
    The LastMoney/Money variable had been assigned. How can I get a variable directly from WCPlayer? If I try "A=WCPlayer(PlayerOwner)" it won't compile because the expression doesn't exist. Can I replace the function Other with something else to let me grab the variable from WCPlayer? And I did check the log and it's similar to the error before. (Accessed None 'A'). Thanks.
    Last edited by gruntkiller4000; 04-21-2012 at 12:23 AM.

  6. #6
    Banned
    Join Date
    Feb 2011
    Location
    BXL/Paris
    Posts
    2,169

    Default

    To preserve Money amount after pawn dead, save it in YourController ( or YourPlayerReplicationInfo if YourGame is net mode...) not in YourPawn.
    Code:
    local YourPawn P;
    local YourController PC;
    
    P = YourPawn(Other);
    
    if( P != None &&  P.Controller != None)
    {
        PC = YourController(P.Controller);
    
        if( PC != None )
            PC.Money += MoneyAmount;
    }

  7. #7
    MSgt. Shooter Person
    Join Date
    Feb 2012
    Posts
    72

    Default

    Thanks VendorX and Meowcat. Switching from my pawn (WCPlayerPawn) to the Controller (WCPlayer) worked. It didn't reset when I died. Thanks!!!

  8. #8

    Default

    Quote Originally Posted by gruntkiller4000 View Post
    Thanks VendorX and Meowcat. Switching from my pawn (WCPlayerPawn) to the Controller (WCPlayer) worked. It didn't reset when I died. Thanks!!!
    I really recommend that you move your data to a PlayerReplicationInfo class rather than the PlayerController class(as VendorX said), even if your mod is offline, it will be much easier in the end.

  9. #9
    MSgt. Shooter Person
    Join Date
    Feb 2012
    Posts
    72

    Default

    It's working now properly using player replication info. thanks


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.