Help with sound code.

I want to make a sound play when I enter my own server, and learn how to make it.
At the moment, I’ve gotten this.

[lua]function FirstSpawn ( ply )
if ply:steamid() == “STEAM_0:0:14328487” then
player.GetAll()
ply:ConCommand (“play itisgood.mp3”)

    end
    
    hook.Add ( "Playerinitialspawn", "playerInitialSpawn", FirstSpawn )[/lua]

Try something more like this, put it in a shared file:



if (SERVER) then
	local function PlaySoundOnJoin(ply)
		if (ply:SteamID() == "STEAM_0:0:14328487") then
			umsg.Start("PlaySound")
			umsg.End()
		end
	end
	hook.Add("PlayerInitialSpawn", "PlaySoundSpawn", PlaySoundOnJoin)
else
	usermessage.Hook("PlaySound", function()
		surface.PlaySound("itisgood.mp3")
	end)
end


Okay, so now, I want to make it play 2 sounds at random.
Randomly everytime I join.
So, would I just add math.Random(1,1) if I add surface.playsound(“allhail.mp3”)

Nope, table random.
[lua]local mySounds = {
“sound0.mp3”,
“sound1.mp3”
};
for _,snd in pairs(mySounds) do resource.AddFile(“sound/Ops/”…snd); end

function FirstSpawn( ply )
if (ply:SteamID() == “STEAM_0:0:14328487”) then
ply:ConCommand("play " … table.Random(mySounds))
end
hook.Add( “PlayerInitialSpawn”, “Velcom”, FirstSpawn )[/lua]

Thanks.
Now, about my Resource.addFile problem, check that out, the sounds for this aren’t being added.

I posted this in your thread, it applies here as well.

But wait, I want to use it for my steam ID.
How do I do that.

[editline]24th January 2011[/editline]

Okay, I’m confused now.
Completely confused.

So ? i didn’t say it was mine.And it’s still correct

I’m not saying that you copied that code, I just copied what I said from your thread into this thread because it applies.

I edited my post for clarity.

So, what do I do now?

-automerge-

Basically this sound is meant to play when only the owner (I) join the server.
No one else.

Using Tiagros’ method, I’m getting this spammed clientside.
It’s either this or my AddFile problem…


Couldn't include file 'shared.lua' (File not found)

I also changed it abit.
[lua]local mySounds = {
“allhail.mp3”,
“itisgood.mp3”
};
for _,snd in pairs(mySounds) do resource.AddFile(“sound/”…snd); end

function FirstSpawn( ply )
if ply:steamid() == “STEAM_0:0:14328487” then
ply:ConCommand("play " … table.Random(mySounds))
end
hook.Add( “PlayerInitialSpawn”, “Velcom”, FirstSpawn )[/lua]

I’m guessing your wanting other players to hear this sound when you enter the sound. Because this will just play the sound for you.

[LUA]
local mySounds = {
“allhail.mp3”,
“itisgood.mp3”
};
for _,snd in pairs(mySounds) do resource.AddFile(“sound/”…snd); end

function FirstSpawn( ply )
if ply:steamid() == “STEAM_0:0:14328487” then
for k,v in pairs(player.GetAll())do
v:ConCommand("play " … mySounds[math.Random(#mySounds)])
end
end
end
hook.Add( “PlayerInitialSpawn”, “Velcom”, FirstSpawn )
[/LUA]

You mean, when I enter the sound?
No, when I join the game.

[editline]24th January 2011[/editline]

Well what do ya’ know.


lua\autorun\allhail.lua:11] 'end' expected (to close to 'function' at line7) near '<eof>'

Fixed in the edit. No I mean when you enter the game you want everyone to hear this sound so they know you entered.

Yes.
Okay.

[editline]24th January 2011[/editline]

Okay, when I join, I get this…


Hook 'Velcom' Failed: [lua\autorun\allhail.lua:8] attempt to call method 'steamid' (a nil value)

[LUA]
local mySounds = {
“allhail.mp3”,
“itisgood.mp3”
};
for _,snd in pairs(mySounds) do resource.AddFile(“sound/”…snd); end

function FirstSpawn( ply )
if ply:SteamID() == “STEAM_0:0:14328487” then
for k,v in pairs(player.GetAll())do
v:ConCommand("play " … mySounds[math.Random(#mySounds)])
end
end
end
hook.Add( “PlayerInitialSpawn”, “Velcom”, FirstSpawn )
[/LUA]

Now I’m getting this…


[lua\autorun\allhail.lua:10] attempt to call field 'Random' (a nil value)

Change math.Random to math.random