-
Notifications
You must be signed in to change notification settings - Fork 10
/
bettersoundlib.txt
112 lines (95 loc) · 3.61 KB
/
bettersoundlib.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
@name bettersoundlib
@persist Sounds:table Antispam:table
@model models/bull/gates/microcontroller1.mdl
#[ ]#
## E2 Library: bettersoundlib ##
## ##
## Helps in cases where your e2 sounds fail ##
## to play for seemingly no reason. ##
## ##
## Manages sound IDs for you and explicitly ##
## stops them after they're done playing. ##
## ##
## Behaves similarly to betterhololib. ##
#[ ]#
if( first() ){
###############
##
# Entity:betterSoundPlay( Sound:string, Duration )
# Plays the provided Sound on a given Entity
# Provide shorter durations for better performance
# Provide 0 duration to play forever (if the sound loops)
#
# Returns the Sound's ID for use in things like soundPitch(), soundVolume(), ect...
#
function number entity:betterSoundPlay(Sound:string, Duration){
for(T=Sounds:count(),1,-1){
if(!Sounds[T,table]["playing",number]){
if(Sounds[T,table]["path",string] == Sound){
This:soundPlay(T,Duration,Sound)
Sounds[T,table]["playing",number] = 1
if(Duration){
timer("sound_freeup_"+T,Duration*1000)
}
return T
}
}
}
local T = Sounds:count() + 1
NewSoundHandler = table()
NewSoundHandler["path",string] = Sound
NewSoundHandler["playing",number] = 1
Sounds:pushTable(NewSoundHandler)
This:soundPlay(T,Duration,Sound)
if(Duration){
timer("sound_freeup_"+T,Duration*1000)
}
return T
}
###############
##
# Entity:antispamSoundPlay( Identifier:string, Sound:string, Duration )
# Plays the provided Sound on a given Entity if said sound isn't already playing
# Returns the Sound's ID for use in things like soundPitch(), soundVolume(), ect...
#
function string entity:antispamSoundPlay(Identifier:string, Sound:string, Duration){
local SoundID = Identifier+This:id()
if( !Antispam[SoundID,number] ){
This:soundPlay(SoundID,Duration,Sound)
Antispam[SoundID,number] = 1
timer("sound_antispam_"+SoundID,Duration*1000)
}
return SoundID
}
###############
##
# <BetterSound>:betterSoundStop( ) OR betterSoundStop( BetterSound )
# Stops a sound but leaves it cached internally.
# Good for sounds played with zero duration
#
function number:betterSoundStop(){
soundStop(This)
Sounds[This,table]["playing",number] = 0
}
function betterSoundStop(This){
soundStop(This)
Sounds[This,table]["playing",number] = 0
}
if(entity():model() == "models/bull/gates/microcontroller1.mdl"){
selfDestruct()
error("This is a library; #include it in something.")
}
}
for( I=1, Sounds:count() ){
if(clk("sound_freeup_"+I)){
soundStop(I)
Sounds[I,table]["playing",number] = 0
}
}
foreach( N, SoundID:string = Antispam:keys() ){
local Bool = Antispam[SoundID,number]
if(clk("sound_antispam_"+SoundID)){
soundStop(SoundID)
Antispam[SoundID,number] = 0
}
}