I'm trying to figure out how to make a basic entity infinitely loop sound, but in a way suited for long term and multiplayer. CreateSound needs to be redone when a new player joins apparently. Could someone point me in the right direction?
Thanks(please save me),
51italian
[code]local ambSound = Sound("music/hl2_song26_trainstation1.mp3")
function ENT:Initialize()
self:SetModel( "models/hunter/blocks/cube025x025x025.mdl" )
self:PhysicsInit( SOLID_NONE ) -- Doesn't collide with anything, including the world. It's only a speaker.
self:SetMoveType( MOVETYPE_NONE ) -- Don't ever move since we'll try and set it through lua config.
self:SetSolid( SSOLID_NONE ) -- Don't collide
local phys = self:GetPhysicsObject()
if (phys:IsValid()) then
phys:Wake()
end
local soundLength = SoundDuration(ambSound)
if soundLength > 0 then
timer.Create( "soundEmit", soundLength, 0, playSound )
end
end
[/code] I can't figure this out.
What is playSound?
There are several ways to loop sounds... 1 would be to use GoldWave or Wavosaur to create cue-points so that the sound will start and play as normal, but when it reaches the end cue-point it returns to the start-cue point ( so you can have it set so there is a wind-up effect then loop at the wound-up sound ).
2 would be to use the current sound system to create the sound with the "loop" flag.
3 would be to use sound-duration to schedule sound:Stop( ) and sound:Play( ) to occur... Unfortunately, you must Stop the sound before Playing the sound in terms of looping.