Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.63 KB | None | 0 0
  1. #include "zcommon.acs"
  2.  
  3. int TID = 5; // unique tag of thing which is center of sound
  4. int MAX = 800.00; // distance from thing when volume should be 0%
  5. int MIN = 400.00; // distance from thing when volume should be MAX_VOL
  6. int MAX_VOL = 1.0; // 0.0 -> 1.0
  7.  
  8.  
  9. int CHAN = 7;
  10.  
  11. // this func copied off zdoom wiki
  12. function int fdistance (int tid1, int tid2)
  13. {
  14.     int len;
  15.     int y = getactory(tid1) - getactory(tid2);
  16.     int x = getactorx(tid1) - getactorx(tid2);
  17.     int z = getactorz(tid1) - getactorz(tid2);
  18.  
  19.     int ang = vectorangle(x,y);
  20.     if(((ang+0.125)%0.5) > 0.25) len = fixeddiv(y, sin(ang));
  21.     else len = fixeddiv(x, cos(ang));
  22.  
  23.     ang = vectorangle(len, z);
  24.     if(((ang+0.125)%0.5) > 0.25) len = fixeddiv(z, sin(ang));
  25.     else len = fixeddiv(len, cos(ang));
  26.  
  27.     return len;
  28. }
  29.  
  30.  
  31. script 123 ENTER
  32. {
  33.  
  34.     int range = MAX - MIN;
  35.  
  36.     int newVol;
  37.  
  38.     PlaySound (TID, "song", CHAN, 0.001, TRUE, ATTN_NONE); // 0.0 vol at start causes sound to never work
  39.  
  40.     while (TRUE)
  41.     {
  42.  
  43.         int distance = fdistance(0, 5);
  44.  
  45.         if (distance >= MAX) {
  46.             newVol = 0.0;
  47.         } else {
  48.             if (distance <= MIN) {
  49.                 newVol = MAX_VOL;
  50.             } else {
  51.  
  52.                 int distToMax = max - distance;
  53.  
  54.                 HudMessage(s:"Dist to max radius: ", i:distToMax >> 16;
  55.                            HUDMSG_PLAIN, 1, CR_GRAY, 0.01, 0.4, 0.1);
  56.  
  57.  
  58.                 newVol = FixedMul(FixedDiv(distToMax, range), MAX_VOL);
  59.  
  60.             }
  61.  
  62.         }
  63.  
  64.         SoundVolume(TID, CHAN, newVol);
  65.  
  66.         HudMessage(s:"Dist to center: ", i:distance >> 16;
  67.                        HUDMSG_PLAIN, 2, CR_GRAY, 0.01, 0.45, 0.1);
  68.  
  69.         HudMessage(s:"Volume: ", f:newVol;
  70.                        HUDMSG_PLAIN, 3, CR_GRAY, 0.01, 0.5, 0.1);
  71.  
  72.         Delay (1);
  73.  
  74.  
  75.  
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement