8989-- @param table self 'self' from E2Functions.
9090-- @param Entity? ent Optional entity to check if they have permissions to modify.
9191local function checkPermissions (self , ent )
92- if not Enabled :GetBool () then error (" WebAudio is currently disabled on the server!" ) end
92+ if not Enabled :GetBool () then E2Lib . raiseException (" WebAudio is currently disabled on the server!" , nil , self . trace ) end
9393 local ply = self .player
9494
9595 local required_lv = AdminOnly :GetInt ()
9696 if required_lv == 1 then
97- if not ply :IsAdmin () then error (" WebAudio is currently restricted to admins!" ) end
97+ if not ply :IsAdmin () then E2Lib . raiseException (" WebAudio is currently restricted to admins!" , nil , self . trace ) end
9898 elseif required_lv == 2 then
99- if not ply :IsSuperAdmin () then error (" WebAudio is currently restricted to super-admins!" ) end
99+ if not ply :IsSuperAdmin () then E2Lib . raiseException (" WebAudio is currently restricted to super-admins!" , nil , self . trace ) end
100100 end
101101
102102 if ent then
103103 -- Checking if you have perms to modify this prop.
104- if not E2Lib .isOwner (self , ent ) then error (" You do not have permissions to modify this prop!" ) end
104+ if not E2Lib .isOwner (self , ent ) then E2Lib . raiseException (" You do not have permissions to modify this prop!" , nil , self . trace ) end
105105 end
106106end
107107
@@ -195,20 +195,20 @@ e2function webaudio webAudio(string url)
195195
196196 if not WebAudio .isWhitelistedURL (url ) then
197197 if WebAudio .Common .CustomWhitelist then
198- error (" This URL is not whitelisted! The server has a custom whitelist." )
198+ E2Lib . raiseException (" This URL is not whitelisted! The server has a custom whitelist." , nil , self . trace )
199199 else
200- error (" This URL is not whitelisted! See github.com/Vurv78/WebAudio/blob/main/WHITELIST.md" )
200+ E2Lib . raiseException (" This URL is not whitelisted! See github.com/Vurv78/WebAudio/blob/main/WHITELIST.md" , nil , self . trace )
201201 end
202202 end
203203
204204 -- Creation Time Quota
205205 if not CreationBurst :use (ply ) then
206- error (" You are creating WebAudios too fast. Check webAudioCanCreate before calling!" )
206+ E2Lib . raiseException (" You are creating WebAudios too fast. Check webAudioCanCreate before calling!" , nil , self . trace )
207207 end
208208
209209 -- Stream Count Quota
210210 if not checkCounter (ply , true ) then
211- error (" Reached maximum amount of WebAudio streams! Check webAudioCanCreate or webAudiosLeft before calling!" )
211+ E2Lib . raiseException (" Reached maximum amount of WebAudio streams! Check webAudioCanCreate or webAudiosLeft before calling!" , nil , self . trace )
212212 end
213213
214214 return registerStream (self , url , ply )
@@ -248,6 +248,10 @@ e2function number webAudiosLeft()
248248 return MaxStreams :GetInt () - (StreamCounter [self .player ] or 0 )
249249end
250250
251+ e2function number webAudioCanTransmit ()
252+ return NetBurst :check (self .player ) and 1 or 0
253+ end
254+
251255__e2setcost (4 )
252256e2function number webaudio :isValid ()
253257 return IsValid (this ) and 1 or 0
@@ -267,14 +271,14 @@ end
267271__e2setcost (15 )
268272e2function number webaudio :play ()
269273 checkPermissions (self )
270- if not NetBurst :use (self .player ) then return 0 end
274+ if not NetBurst :use (self .player ) then return self : throw ( " You are transmitting too fast, check webAudioCanTransmit! " , 0 ) end
271275
272276 return this :Play () and 1 or 0
273277end
274278
275279e2function number webaudio :pause ()
276280 checkPermissions (self )
277- if not NetBurst :use (self .player ) then return 0 end
281+ if not NetBurst :use (self .player ) then return self : throw ( " You are transmitting too fast, check webAudioCanTransmit! " , 0 ) end
278282
279283 return this :Pause () and 1 or 0
280284end
@@ -324,14 +328,16 @@ end
324328-- @return number Whether the WebAudio object successfully transmitted. Returns 0 if you are hitting quota.
325329e2function number webaudio :update ()
326330 checkPermissions (self )
327- if not NetBurst :use (self .player ) then return 0 end
331+ if not NetBurst :use (self .player ) then return self : throw ( " You are transmitting too fast, check webAudioCanTransmit! " , 0 ) end
328332
329333 return this :Transmit () and 1 or 0
330334end
331335
332336__e2setcost (5 )
333337e2function number webaudio :setParent (entity parent )
338+ if not IsValid (parent ) then return self :throw (" Parent is invalid!" , 0 ) end
334339 checkPermissions (self , parent )
340+
335341 this :SetParent (parent )
336342 return 1
337343end
0 commit comments