• sound.PlayFile, stopping sound
    2 replies, posted
Is there any way to stop sound created by sound.PlayFile? [code] include("shared.lua") function ENT:Draw() if(self:GetNWBool("IsPlaying")) then cam.Start3D() render.SetMaterial(self.SpriteMat) render.DrawQuadEasy(self:GetPos(), (GetViewEntity():EyePos() - self:GetPos()):GetNormal(), 128, 128, Color(0,255,255,122)) cam.End3D() end self:DrawModel() local plyang = (GetViewEntity():GetPos() - self:GetPos()):Angle() local ang = self:GetAngles() //local ang = self:GetAngles() plyang:RotateAroundAxis(plyang:Up(), 90) plyang:RotateAroundAxis(plyang:Forward(), 90) //local rr,rg,rb = math.random(1,255),math.random(1,255),math.random(1,255) //local color = Color(rr,rg,rb) cam.Start3D2D(self:GetPos() + self:GetUp() * 60, plyang, 1) if(!self:GetNWBool("IsPlaying"))then draw.DrawText("Hardbass\nRadio", "Trebuchet18", 0, 0, Color(255,255,0,255), TEXT_ALIGN_CENTER) else draw.DrawText("Now playing:", "Trebuchet18", 0, 0, Color(255,255,0,255), TEXT_ALIGN_CENTER) draw.DrawText("\nDJ Bar@bass", "Trebuchet18", 0, 0, Color(255,255,255,255), TEXT_ALIGN_CENTER) end cam.End3D2D() end function ENT:Think() if(self:GetNWBool("IsPlaying")) && !self.IsAudioStarted then sound.PlayFile("sound/djbarabass-cityzen.wav", "stereo", function(station) if(IsValid(station)) then station:Play() audio = self.station end end) self.IsAudioStarted = true elseif(!self:GetNWBool("IsPlaying")) then if(IsValid(station)) then station:Stop() end self.IsAudioStarted = false end end [/code]
Not sure if I quite understand your question, are you not stopping the sound here; [code] elseif(!self:GetNWBool("IsPlaying")) then if(IsValid(station)) then station:Stop() end self.IsAudioStarted = false end [/code]
Uh. Your code is a little confusing. [CODE]audio = self.station[/CODE] Why'd you set audio if you're not going to use it again (and why are you using the self keyword)? In your code, station only exists as the callback's argument, so it's nil anywhere else.
Sorry, you need to Log In to post a reply to this thread.