GMod join-server sound

Hey,

I wanted to know if you can make a sound play when you join a server. I’m 99.9% you can’t. But I’ve seen it work on CS:S but thats a complete different game.

Any response would help.

(I don’t really need any code, I’m just wondering if its possible.)

Yes, it is possible, well at least as far as I remember. I’ve done this multiple times just for the fuck arounds. You need to set up a sv_loadingurl with an audio source to play automatically, but trust me, I’m pretty sure nobody likes to have a song shoved in their ears without having control over the volume / stopping it.

I have a code for that, it is very possible.

When you say, “…join a server”, doth thou mean when they SPAWN into the server, or when they are Loading the server or downloading files?

You can make a loading screen play sound, which can be extremely annoying.
You can play a sound on the first spawn, or when the player has fully connected to the server. It just depends where, when and how you want it to occur…

hook a sound to play in PlayerInitialSpawn

Does this play the spund for the whole server or only the player and could you possibly show how to make a hook since im really new to lua :stuck_out_tongue:

[lua]
local soundPath = “buttons/lever1.wav”

hook.Add( “PlayerInitialSpawn”, “playMyJoinSound”, function( ply )
if ( ply:IsAdmin() ) then
for k,v in pairs( player.GetAll() ) do
v:ConCommand( "play "…soundPath )
end
end
end )
[/lua]

Not the most optimal way, but it wouldn’t change anything in real performance.
Place this inside lua/autorun/server

Join music



timer.Simple( 5, function() 
sound.PlayURL ( "http://gmod.cocraft.ru/welc.mp3", "mono", function( station )
	if ( IsValid( station ) ) then

		station:Play()
		station:SetVolume( 1 )

	else

		LocalPlayer():ChatPrint( "" )

	end
end )
end )


Only autorun/client drop

Doesn’t ULX have this feature?

No, it just has a “playsound” feature, not one for when players join. (unless there is a plugin that someone made for it)

But if you really want to annoy people with sounds.



if SERVER then
	hook.Add("PlayerInitialSpawn", "SpawnSound", function( ply )
		if ply:IsAdmin() then // define ply somewhere else
			umsg.Start( "deploymusic" )
			umsg.End()	
		end
	end)
else
	usermessage.Hook( "deploymusic", function()
		local url = "www.someplace.com/annoyingsoundtomakeeveryoneleave.mp3"
		sound.PlayURL( url , "mono", function(a) end)
		chat.AddText( Color( 255, 0, 0 ) , "The minge admin has joined.") // Chat to announce your presence and annoying people
	end)
end


Not that I advocate using it to play some annoying music on people because they wont be able to stop it using stopsound in the console.

EDIT: Wow, I just realised how old the original post was, god damn it.

This shit won’t even work.



if SERVER then
   local soundFile = "HL1/fvox/beep.wav"
   local function playS() net.Start("playsound") net.WriteString(soundFile) net.Broadcast() end
   util.AddNetworkString("playsound")

   hook.Add("PlayerInitialSpawn", "playsoundOnJoin", function(ply)
       playS()
   end )
else
  net.Receive("playsound", function()
    local sound = net.ReadString()
    surface.PlaySound(sound)
    end )
end


place in autorun

It will now.

LocalPlayer() doesn’t return your player entity when it’s called serverside

Anybody know how to do this but have the volume lower?

Lower the volume in the Windows volume mixer.

Don’t use PlayerInitialSpawn as the other knobs in this thread suggested, it’ll attempt to play before the player enters the server fully. Use the InitPostEntity hook for something like this.

[lua]local volume = 25
local path = “whatever.mp3” – or a URL, change PlayFile to PlayURL if that’s the case

hook.Add(“InitPostEntity”, “Sound on join”, function()
sound.PlayFile(path, “”, function(ch)
if (not ch:IsValid()) then
return
end

    ch:SetVolume(volume)
end)

end)[/lua]