Playing Sound

So, I am trying to play sound on when a round starts.

The sound is located in garrysmod/sound/Welcome.wma
Here is the code


ROUND_WAITING = 0
ROUND_PREPARING = 1
ROUND_ACTIVE = 2
ROUND_ENDING = 3

	
	AddCSLuaFile() -- Send the file to the client. 

	hook.Add( "OnRoundSet", "Round Set Example", function( round, winner )

		if round == ROUND_WAITING then
			print( "We're waiting for the game to start!" ) 
		elseif round == ROUND_PREPARING then
			print( "The round is preparing!" )
			**surface.PlaySound( "/sound/Welcome.wma" )**
			elseif round == ROUND_ACTIVE then
			print( "Let's play!" )
		elseif round == ROUND_ENDING then 
			print( "The winner is "..winner.."!" ) -- If the winner is the timelimit, it will be the number 123.
			if winner != 123 then
				print( team.GetName(winner).." is awesome!" )
			end
		end
	end )

But I get ‘gmod surface a nil value’ why do I get it? The file is sv_round.lua part of the Deathrun gamemode.
I am starting to think /sound/Welcome.wma but were does PlaySound point to by default?

Try without the first / in surface.PlaySound
If that doesn’t work, try wihout sound/

Nope don’t work.

I am not sure if wma file types are supported, would you try converting it to a wav or mp3?

I’ve tried unconverted mp3’s and wav’s no luck…

Create a singleplayer server with that file in your garrysmod/garrysmod/sound folder, then in game type “sound <file>”. See if that creates a suggestion. If not, try other names such as sound/<file> or /<file>

Can someone who knows what they are talking about help me?

Oh sorry, I thought sound was still in existance.
The directory surface.PlaySound points at garrysmod/garrysmod/sound/.

You want to use surface.PlaySound(“Welcome.wma”)
If that doesn’t work, it is probably one of three things:

  1. Doesn’t support wma / You don’t have it downloaded
  2. Didn’t put it in the right folder
  3. File is corrupt

It makes a diference but

[ERROR] gamemodes/deathrun/gamemode/sv_round.lua:15: attempt to index global ‘surface’ (a nil value)

You are trying to run a surface library function (client) on the server.

I’m a noob at Lua
surface.PlaySound( “radioactive.mp3” )

fix?

“Can someone who knows what their talking about help me?”

Idiot

easiest way:
[lua]
for i, ply in ipairs(player.GetAll()) do
ply:SendLua(‘surface.PlaySound(“radioactive.mp3”)’);
end
[/lua]

Console Error:
Create Stream Failed error 41
Failed to load sound “radioactive.mp3”, file probably missing from disk/repository
R

I tried putting it in ‘gmod/garrysmod/sound’, ‘gmod/garrysmod’, ‘gmod’
using


			for i, ply in ipairs(player.GetAll()) do
			ply:SendLua('surface.PlaySound("radioactive.mp3")');
			end

full code


ROUND_WAITING = 0
ROUND_PREPARING = 1
ROUND_ACTIVE = 2
ROUND_ENDING = 3

	
	AddCSLuaFile() -- Send the file to the client. 

	hook.Add( "OnRoundSet", "Round Set Example", function( round, winner )

		if round == ROUND_WAITING then
			print( "We're waiting for the game to start!" ) 
		elseif round == ROUND_PREPARING then
			print( "The round is preparing!" )
			for i, ply in ipairs(player.GetAll()) do
			ply:SendLua('surface.PlaySound("radioactive.mp3")');
			end
			elseif round == ROUND_ACTIVE then
			print( "Let's play!" )
		elseif round == ROUND_ENDING then 
			print( "The winner is "..winner.."!" ) -- If the winner is the timelimit, it will be the number 123.
			if winner != 123 then
				print( team.GetName(winner).." is awesome!" )
			end
		end
	end )

did you add the file to fastdl (ignore if you don’t use fastdl), and resource.AddFile the file?

Fon’t have FastDL and how do I use resouce.Addfile? I know, I am very stupid.

resource.AddFile - maurits.tv