Guest User

Untitled

a guest
Jun 21st, 2019
54
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // TriggeredAmbSound.
  3. // A sound source which can be triggered on or off.
  4. //=============================================================================
  5. class TriggeredAmbSound expands AmbientSound;
  6.  
  7. var() float TurnOnTime;        // Time sound takes to change from off to on
  8. var() float TurnOffTime;       // Time sound takes to change from on to off
  9. var() bool  bInitiallyOn;      // Whether it's initially on
  10. var() float RemainOnTime;      // How long the TriggerPound effect lasts
  11.  
  12. var float InitialSoundVolume;  // Initial volume
  13. var Sound InitialAmbientSound; // Initial sound
  14. var float Alpha;
  15. var bool bNextOn;
  16. var Actor SavedTrigger;
  17. var float PoundTime;
  18.  
  19. event BeginPlay()
  20. {
  21.     InitialSoundVolume = SoundVolume;
  22.     InitialAmbientSound = AmbientSound;
  23.     bNextOn = bInitiallyOn;
  24.     if (bInitiallyOn)
  25.         Alpha = 1;
  26.     else
  27.         Alpha = 0;
  28. }
  29.  
  30. event Tick(float DeltaTime)
  31. {
  32.     if (bNextOn)
  33.     {
  34.         Alpha += DeltaTime / FMax(TurnOnTime, DeltaTime);
  35.         if (Alpha >= 1)
  36.         {
  37.             Alpha = 1;
  38.             Disable('Tick');
  39.             if (SavedTrigger != none)
  40.                 SavedTrigger.EndEvent();
  41.         }
  42.     }
  43.     else
  44.     {
  45.         Alpha -= DeltaTime / FMax(TurnOffTime, DeltaTime);
  46.         if (Alpha <= 0)
  47.         {
  48.             Alpha = 0;
  49.             Disable('Tick');
  50.             if (SavedTrigger != none)
  51.                 SavedTrigger.EndEvent();
  52.         }
  53.     }
  54.  
  55.     UpdateAmbientSound();
  56. }
  57.  
  58. // Trigger turns the sound on
  59. state() TriggerTurnsOn
  60. {
  61.     event Trigger(Actor A, Pawn EventInstigator)
  62.     {
  63.         if (SavedTrigger != none)
  64.             SavedTrigger.EndEvent();
  65.         SavedTrigger = A;
  66.         if (SavedTrigger != none)
  67.             SavedTrigger.BeginEvent();
  68.         bNextOn = true;
  69.         Enable('Tick');
  70.     }
  71. }
  72.  
  73. // Trigger turns the sound off
  74. state() TriggerTurnsOff
  75. {
  76.     event Trigger(Actor A, Pawn EventInstigator)
  77.     {
  78.         if (SavedTrigger != none)
  79.             SavedTrigger.EndEvent();
  80.         SavedTrigger = A;
  81.         if (SavedTrigger != none)
  82.             SavedTrigger.BeginEvent();
  83.         bNextOn = false;
  84.         Enable('Tick');
  85.     }
  86. }
  87.  
  88. // Trigger toggles the sound
  89. state() TriggerToggle
  90. {
  91.     event Trigger(Actor A, Pawn EventInstigator)
  92.     {
  93.         if (SavedTrigger != none)
  94.             SavedTrigger.EndEvent();
  95.         SavedTrigger = A;
  96.         if (SavedTrigger != none)
  97.             SavedTrigger.BeginEvent();
  98.         bNextOn = !bNextOn;
  99.         Enable('Tick');
  100.     }
  101. }
  102.  
  103. // Trigger controls the sound
  104. state() TriggerControl
  105. {
  106.     event Trigger(Actor A, Pawn EventInstigator)
  107.     {
  108.         if (SavedTrigger != none)
  109.             SavedTrigger.EndEvent();
  110.         SavedTrigger = A;
  111.         if (SavedTrigger != none)
  112.             SavedTrigger.BeginEvent();
  113.         bNextOn = !bInitiallyOn;
  114.         Enable('Tick');
  115.     }
  116.  
  117.     event UnTrigger(Actor A, Pawn EventInstigator)
  118.     {
  119.         if (SavedTrigger != none)
  120.             SavedTrigger.EndEvent();
  121.         SavedTrigger = A;
  122.         if (SavedTrigger != none)
  123.             SavedTrigger.BeginEvent();
  124.         bNextOn = bInitiallyOn;
  125.         Enable('Tick');
  126.     }
  127. }
  128.  
  129. state() TriggerPound
  130. {
  131.     event Timer()
  132.     {
  133.         if (RemainOnTime > 0 && PoundTime >= RemainOnTime)
  134.             return;
  135.         bNextOn = !bNextOn;
  136.         if (bNextOn)
  137.         {
  138.             PoundTime += TurnOnTime;
  139.             SetTimer(TurnOnTime, false);
  140.         }
  141.         else
  142.         {
  143.             PoundTime += TurnOffTime;
  144.             SetTimer(TurnOffTime, false);
  145.         }
  146.     }
  147.  
  148.     event Trigger(Actor A, Pawn EventInstigator)
  149.     {
  150.         if (SavedTrigger != none)
  151.             SavedTrigger.EndEvent();
  152.         SavedTrigger = A;
  153.         if (SavedTrigger != none)
  154.             SavedTrigger.BeginEvent();
  155.         bNextOn = !bInitiallyOn;
  156.  
  157.         // how much time will pass till reversal
  158.         if (bNextOn)
  159.             PoundTime = TurnOnTime;
  160.         else
  161.             PoundTime = TurnOffTime;
  162.         SetTimer(PoundTime, false); // wake up when it's time to reverse
  163.         Enable('Tick');
  164.     }
  165.  
  166.     function Reset()
  167.     {
  168.         SetTimer(0, false);
  169.         global.Reset();
  170.     }
  171. }
  172.  
  173. // Reset the sound
  174. function Reset()
  175. {
  176.     if (bInitiallyOn)
  177.     {
  178.         Alpha   = 1;
  179.         bNextOn = true;
  180.     }
  181.     else
  182.     {
  183.         Alpha   = 0;
  184.         bNextOn = false;
  185.     }
  186.  
  187.     UpdateAmbientSound();
  188. }
  189.  
  190. function UpdateAmbientSound()
  191. {
  192.     SoundVolume = Alpha * InitialSoundVolume;
  193.     if (SoundVolume > 0)
  194.         AmbientSound = InitialAmbientSound;
  195.     else
  196.         AmbientSound = none;
  197. }
  198.  
  199. defaultproperties
  200. {
  201.     bNoDelete=True
  202.     bStatic=False
  203. }
RAW Paste Data