Announcement

Collapse
No announcement yet.

Pawn Sound if Health <=10 [Solved]

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

    Pawn Sound if Health <=10 [Solved]

    ================================================== ========================
    Author:
    .TKBS
    Information: .Play a Soundcue (heartbeat) when the pawn has 10 Health or less...// & other events
    Release Date: .later
    Game: UT3, UDK compatible (may need updates)
    Description:I will Provide 2 methods for playing audio (Will post later) [1] Using level events & [2] Using a custom pawn class
    Download Link:
    Single Player : Yes
    Cooperative : No
    New Sounds : Yes
    New Graphics : No
    Author Notes: The free files in the link are 11025 sample rates, you might want to find (or make) some better files. Ensure they are the correct format. Also try to consider other sound effects that may be in use whilst using this.
    ================================================== ========================
    Method [1] Pawn Code:
    • Play audio when health is a certain amount


    Method [2] level Events:
    • Useful for LD's, bit faster than other methods
    • Play audio on trigger/ volume/ actor touch etc


    ================================================== ========================
    ↓↓↓ Below is the old useless stuff ↓↓↓ - you can ignore this
    ================================================== ========================
    Old stuff:
     
    Spoiler

    #2
    You can check the UTBeserk item for instance. You don't need to get access to your PC, as the Pawn should already have a PlaySound function. An AudioComponent is not realldy neeed (but it would work, yes).

    There is also NotifyTakeHit which can be used to start the sound timer in the PC instead of the Pawn.

    Comment


      #3
      • UTBerserk has nothing to do with a pawns health
      • Ignoring PC and removing audio component as you said is fine, but if it can be left, it makes no difference
      • That code i posted forces my pawn to always has 12 health, so thanks for not telling me that


      The problem is not with playing the sound, it is not be able access a pawns health or play the sound/ stop the sound based on the pawns health.

      Ambient Pawn sound on level load:
       
      Spoiler

      This is what i need working
      Code:
           if (Health <= 10)
      // when the players ehalth <10 or = 10.
      // when above 10 must stop sound
      Old stuff:
       
      Spoiler

      Comment


        #4
        UTBerserk
        Code:
        function GivenTo(Pawn NewOwner, bool bDoNotActivate)
        {
            //...
        
            // set timer for ending sounds
            SetTimer(TimeRemaining - 3.0, false, 'PlayBerserkFadingSound');
        }
        
        /** called on a timer to play Berserk ending sound */
        function PlayBerserkFadingSound()
        {
            // reset timer if time got added
            if (TimeRemaining > 3.0)
            {
                SetTimer(TimeRemaining - 3.0, false, 'PlayBerserkFadingSound');
            }
            else
            {
                Instigator.PlaySound(BerserkFadingSound);
                SetTimer(0.75, false, 'PlayBerserkFadingSound');
            }
        }
        I wouldn't say UTBeserk, when UTBeserk woudln't help. If you don't understand your own code which you had posted in the 1st post, that i'm not able to help you (or you should ask exactly).

        With the combination of your code and the beesrk example, you can create a working example.
        Code:
        class MYPawn extends UTPawn;
        
        //Sound cue
        var SoundCue HeartBeat;
        var AudioComponent HeartBeatSound;
        
        event TakeDamage(int Damage, Controller InstigatedBy, vector HitLocation, vector Momentum, class<DamageType> DamageType, optional TraceHitInfo HitInfo, optional Actor DamageCauser)
        {
        
           // not sure what to do here or how to access my pawn controller
          // only needs to be client side
            local PlayerController LocalControl;
            LocalControl = PlayerController(Controller);
        
         // need to change this line was taken from somewhere else [TH]
            if (InstigatedBy.GetTeamNum() != GetTeamNum() && (LocalControl == none || !LocalControl.IsInState('InSpawnProtection') ))
            {
                Health -= Damage;
                SetTimer(0.5, true, 'PlayHeartBeatSound');
                if (Health <= 10){
                    Health = HealthMax;
                    WorldInfo.Game.ScoreKill(InstigatedBy, self.Controller);
                }
            }
        }
        
        reliable client function PlayHeartBeatSound() 
        {
            if ( Health <=10 ) 
        {
                if (!HeartBeatSound.IsPlaying())
              {
                    //HeartBeatSound.FadeIn(1,1);
                HeartBeatSound= MYPlayerController(Controller).GetPooledAudioComponent(HeartBeat, self, true);
                    HeartBeatSound.Play();
                    //`log("---> STARTING HEARTBEAT "@Health);
                    return;
               } 
        else 
        {
                    //`log("---> PLAYING HEARTBEAT "@Health);
                    return;
                }
        } 
        else
            {
                HeartBeatSound.FadeOut(3,0.25);
                //`log("---> STOP HEARTBEAT "@Health);
                ClearTimer('PlayHeartBeatSound');
            } 
        
        
        }
        Code:
        class MYPawn extends UTPawn;
        
        //Sound cue
        var SoundCue HeartBeat;
        
        event TakeDamage(int Damage, Controller  InstigatedBy, vector HitLocation, vector Momentum,  class<DamageType> DamageType, optional TraceHitInfo HitInfo,  optional Actor DamageCauser)
        {
            super.TakeDamage(int Damage, InstigatedBy, HitLoction, Momentum, DamageType, HitInfo, DamageCauser);
            if (Health <= 10)
            {
                // not sure if you intend multiplayer support, but this will trigger a call on the client side
                PlayHeartBeatSound();
             }
        }
        
        reliable client function PlayHeartBeatSound() 
        {
            // if this gets called, the function got replicated
            // in general, the Health should be replicated, so we check for the new health value
                
            // reset timer if health got added
            if ( Health <= 10 && !IsTimerActive('PlayHeartBeatSound') ) 
            {
        
                // the timer is not active anymore and the health is still low
                // we play the sound here on the client part, and re-call this function with a Timer
        
                // as we replicated this call, and a listen server might also call this method, we need to be sure the sound will not get replicated 
                PlaySound(HeartBeat, true);
                SetTimer(0.75, false, 'PlayHeartBeatSound');
            }
        } 

        Comment


          #5
          • event TakeDamage (the stuff in brackets) is different from super.takedamage, even before compiling i know that will give me an error. -- ive made enough errors to know that


          compile that code, if it works show it as a .u file - you will find that code will not compile. But thank you for trying

          Old Stuff:
           
          Spoiler

          Comment


            #6
            -.-
            Maybe try to understand compile errors. I was just using copy paste and might have added typos. If you don't learn from your mistakes and don't even try to do something, you won't get any experience at all.

            Trail & error ... i won't try it out for you:
            Code:
            class MYPawn extends UTPawn;
            
            //Sound cue
            var SoundCue HeartBeat;
            
            event PostBeginPlay()
            {
                super.PostBeginPlay();
            
                // called for possible savegame support
                SetTimer(3.0, false, 'CheckHeartBeat');
            }
            
            event TakeDamage(int Damage, Controller InstigatedBy, vector HitLocation, vector Momentum,  class<DamageType> DamageType, optional TraceHitInfo HitInfo,  optional Actor DamageCauser)
            {
                super.TakeDamage(Damage, InstigatedBy, HitLoction, Momentum, DamageType, HitInfo, DamageCauser);
                CheckHeartBeat();
            }
            
            function CheckHeartBeat()
            {
                if (Health <= 10)
                {
                    // not sure if you intend multiplayer support, but this will trigger a call on the client side
                    PlayHeartBeatSound();
                }
            }
            
            reliable client function PlayHeartBeatSound() 
            {
                // if this gets called, the function got replicated
                // in general, the Health should be replicated, so we check for the new health value
                    
                // reset timer if health got added
                if ( Health <= 10 && !IsTimerActive('PlayHeartBeatSound') ) 
                {
            
                    // the timer is not active anymore and the health is still low
                    // we play the sound here on the client part, and re-call this function with a Timer
            
                    // as we replicated this call, and a listen server might also call this method, we need to be sure the sound will not get replicated 
                    PlaySound(HeartBeat, true);
                    SetTimer(0.75, false, 'PlayHeartBeatSound');
                }
            }

            Comment

            Working...
            X