1-
21--- Sound functions. Plays and manipulates sounds, optionally
32-- attaching them to an entity.
43
@@ -8,13 +7,21 @@ local sound_library, _ = SF.Libraries.Register("sounds")
87local sound_methods , sound_metamethods = SF .Typedef (" Sound" )
98local wrap , unwrap = SF .CreateWrapper (sound_metamethods ,true ,false )
109
10+ -- Register privileges
11+ do
12+ local P = SF .Permissions
13+ P .registerPrivilege ( " sound.create" , " Sound" , " Allows the user to create sounds" )
14+ P .registerPrivilege ( " sound.modify" , " Sound" , " Allows the user to modify sounds" )
15+ end
16+
1117--- Creates a sound and attaches it to an entity. You need to do sound:Play() before
1218-- the sound will play however.
1319-- @param path Filepath to the sound file
1420-- @param entity Entity playing the sound
1521-- @return The sound object. Keep this around to ensure it isn't GC'd (and thus stopped)
1622-- before it is done playing.
1723function sound_library .create (entity , path )
24+ if not SF .Permissions .check ( SF .instance .player , path , " sound.create" ) then SF .throw ( " Insufficient permissions" , 2 ) end
1825 SF .CheckType (path , " string" )
1926 SF .CheckType (entity , SF .Entities .Metatable )
2027 if path :match (' ["?]' ) then SF .throw ( " Invalid sound path: " .. path , 2 ) end
2835-- @param amplitude (Optinal) Loudness of the sound, from 0 to 255
2936-- @param pitch (Optional) Pitch percent, from 0 to 255
3037function sound_library .emitWorld (origin , path , amplitude , pitch )
38+ if not SF .Permissions .check ( SF .instance .player , path , " sound.create" ) then SF .throw ( " Insufficient permissions" , 2 ) end
3139 SF .CheckType (path , " string" )
3240 SF .CheckType (origin , " Vector" )
3341 if amplitude then
4856-- @param soundlevel (Optional) The sound level. See sound:setLevel() for more info
4957-- @param pitch (Optional) Pitch percent, from 0 to 255
5058function sound_library .emitEntity (entity , path , soundlevel , pitch )
59+ if not SF .Permissions .check ( SF .instance .player , path , " sound.create" ) then SF .throw ( " Insufficient permissions" , 2 ) end
5160 SF .CheckType (entity , SF .Entities .Metatable )
5261 SF .CheckType (path , " string" )
5362 if soundlevel then
7786
7887--- Plays the sound.
7988function sound_methods :play ()
89+ if not SF .Permissions .check ( SF .instance .player , this , " sound.modify" ) then SF .throw ( " Insufficient permissions" , 2 ) end
8090 SF .CheckType (self , sound_metamethods )
8191 unwrap (self ):Play ()
8292end
8595-- @param pitch The sound pitch as a percent from 0 to 255
8696-- @param delta (Optinal) The transition time between the current pitch and the new one
8797function sound_methods :setPitch (pitch , delta )
98+ if not SF .Permissions .check ( SF .instance .player , this , " sound.modify" ) then SF .throw ( " Insufficient permissions" , 2 ) end
8899 SF .CheckType (self , sound_metamethods )
89100 SF .CheckType (pitch , " number" )
90101 if delta then
97108--- Sets the sound volume
98109-- @param vol Volume as a percent between 0 and 1
99110function sound_methods :setVolume (vol )
111+ if not SF .Permissions .check ( SF .instance .player , this , " sound.modify" ) then SF .throw ( " Insufficient permissions" , 2 ) end
100112 SF .CheckType (self , sound_metamethods )
101113 SF .CheckType (vol , " number" )
102114 unwrap (self ):ChangeVolume (math .Clamp (vol ,0 ,1 ))
107119-- (use decibel value from the 'code' column, not the actual enum or 'value' column).
108120-- @param level New level
109121function sound_methods :setLevel (level )
122+ if not SF .Permissions .check ( SF .instance .player , this , " sound.modify" ) then SF .throw ( " Insufficient permissions" , 2 ) end
110123 SF .CheckType (self , sound_metamethods )
111124 SF .CheckType (level , " number" )
112125 unwrap (self ):SetSoundLevel (math .Clamp (level , 0 , 511 ))
115128--- Stops or fades out the sound.
116129-- @param fade (Optional) Time, in seconds, to fade out the sound. Not given = stop immediately
117130function sound_methods :stop (fade )
131+ if not SF .Permissions .check ( SF .instance .player , this , " sound.modify" ) then SF .throw ( " Insufficient permissions" , 2 ) end
118132 SF .CheckType (self , sound_metamethods )
119133 if fade then
120134 SF .CheckType (fade , " number" )
0 commit comments