View difference between Paste ID: J2u7TNUP and btMkGuR8
SHOW: | | - or go back to the newest paste.
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
str audio = "something";
9
10
int CHAN = 7;
11
12
// this func copied off zdoom wiki
13
function int fdistance (int tid1, int tid2)
14
{
15
	int len;
16
	int y = getactory(tid1) - getactory(tid2);
17
	int x = getactorx(tid1) - getactorx(tid2);
18
	int z = getactorz(tid1) - getactorz(tid2);
19
20
	int ang = vectorangle(x,y);
21
	if(((ang+0.125)%0.5) > 0.25) len = fixeddiv(y, sin(ang));
22
	else len = fixeddiv(x, cos(ang));
23
24
	ang = vectorangle(len, z);
25
	if(((ang+0.125)%0.5) > 0.25) len = fixeddiv(z, sin(ang));
26
	else len = fixeddiv(len, cos(ang));
27
28
	return len;
29
}
30
31
32
script 123 ENTER
33
{
34
35
	int range = MAX - MIN;
36
37
	int newVol;
38-
	PlaySound (TID, "song", CHAN, 0.001, TRUE, ATTN_NONE); // 0.0 vol at start causes sound to never work
38+
39
	PlaySound (TID, audio, CHAN, 0.001, TRUE, ATTN_NONE); // 0.0 vol at start causes sound to never work
40
41
    while (TRUE)
42
    {
43
44
        int distance = fdistance(0, TID);
45
46
		if (distance >= MAX) {
47
			newVol = 0.0;
48
		} else {
49
			if (distance <= MIN) {
50
				newVol = MAX_VOL;
51
			} else {
52
53
				int distToMax = max - distance;
54
55
				HudMessage(s:"Dist to max radius: ", i:distToMax >> 16;
56
					       HUDMSG_PLAIN, 1, CR_GRAY, 0.01, 0.4, 0.1);
57
58
59
				newVol = FixedMul(FixedDiv(distToMax, range), MAX_VOL);
60
61
			}
62
63
		}
64
65
		SoundVolume(TID, CHAN, newVol);
66
67
		HudMessage(s:"Dist to center: ", i:distance >> 16;
68
					   HUDMSG_PLAIN, 2, CR_GRAY, 0.01, 0.45, 0.1);
69
70
		HudMessage(s:"Volume: ", f:newVol;
71
					   HUDMSG_PLAIN, 3, CR_GRAY, 0.01, 0.5, 0.1);
72
73
        Delay (1);
74
75
76
77
    }
78
}