Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "zcommon.acs"
- int TID = 5; // unique tag of thing which is center of sound
- int MAX = 800.00; // distance from thing when volume should be 0%
- int MIN = 400.00; // distance from thing when volume should be MAX_VOL
- int MAX_VOL = 1.0; // 0.0 -> 1.0
- int CHAN = 7;
- // this func copied off zdoom wiki
- function int fdistance (int tid1, int tid2)
- {
- int len;
- int y = getactory(tid1) - getactory(tid2);
- int x = getactorx(tid1) - getactorx(tid2);
- int z = getactorz(tid1) - getactorz(tid2);
- int ang = vectorangle(x,y);
- if(((ang+0.125)%0.5) > 0.25) len = fixeddiv(y, sin(ang));
- else len = fixeddiv(x, cos(ang));
- ang = vectorangle(len, z);
- if(((ang+0.125)%0.5) > 0.25) len = fixeddiv(z, sin(ang));
- else len = fixeddiv(len, cos(ang));
- return len;
- }
- script 123 ENTER
- {
- int range = MAX - MIN;
- int newVol;
- PlaySound (TID, "song", CHAN, 0.001, TRUE, ATTN_NONE); // 0.0 vol at start causes sound to never work
- while (TRUE)
- {
- int distance = fdistance(0, 5);
- if (distance >= MAX) {
- newVol = 0.0;
- } else {
- if (distance <= MIN) {
- newVol = MAX_VOL;
- } else {
- int distToMax = max - distance;
- HudMessage(s:"Dist to max radius: ", i:distToMax >> 16;
- HUDMSG_PLAIN, 1, CR_GRAY, 0.01, 0.4, 0.1);
- newVol = FixedMul(FixedDiv(distToMax, range), MAX_VOL);
- }
- }
- SoundVolume(TID, CHAN, newVol);
- HudMessage(s:"Dist to center: ", i:distance >> 16;
- HUDMSG_PLAIN, 2, CR_GRAY, 0.01, 0.45, 0.1);
- HudMessage(s:"Volume: ", f:newVol;
- HUDMSG_PLAIN, 3, CR_GRAY, 0.01, 0.5, 0.1);
- Delay (1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement