Using EmitSound Clientside

Hello, I’m using the following to emit a heartbeat noise clientside:



function drawBlood()
	if LocalPlayer():Health() < 50 then 
		if bloodActive == false then
			bloodBorder = vgui.Create( "DImage" )
			bloodBorder:SetImage( "blood1.png" )
			bloodBorder:SetSize( ScrW(), ScrH() )
			bloodBorder:SetAlpha( 127 )
			bloodActive = true
		end 
		LocalPlayer():EmitSound( "heartbeatmp3.mp3", 500, 100 )
	end
end


And then server side I use:



resource.AddFile( "sounds/heartbeatmp3.mp3" )


However when it runs I get:


Stream Failed error 41
Failed to load sound "heartbeatmp3.mp3", file probably missing from disk/repository

I’ve used sounds before so I have no idea why this isn’t working, unless I’m doing something really stupid. My file structure is:


garrysmod/addons/sgn_lowhealthnotifier/sounds/heartbeatmp3.mp3

EDIT: I do download the file when connecting, and when I go clientside to garrysmod/download/sounds/heartbeatmp3.mp3 it is there.

[editline]30th May 2014[/editline]

Oh wait, is it meant to be sound?

Nope, if I change it all to sound/ it still gives me the same error:
Failed to load sound “heartbeatmp3.mp3”, file probably missing from disk/repository
Create Stream Failed error 41

It should be sound, not sounds, as the name of the directory that holds the sound files.

I edited my post a minute ago, but thanks. I’ve just tried sound and it still gives the same error.

Try this:
[lua]
resource.AddSingleFile( “sound/heartbeatmp3.mp3” )
util.PrecacheSound( “heartbeatmp3.mp3” )
[/lua]

Thanks, but same thing:

Try running [lua]
file.Exists(“sound/heartbeatmp3.mp3”, “GAME”)
[/lua]

To see if it really does exist.

I tried that, and it does: Here is my startup log:



=================================================== Addon has started...
 =============================================== file exists 
Player Login Message has started and is enabled
Included shared.lua
Gravity Changing Deathmatch configuration has been loaded.
Gravity Changing Deathmatch has been enabled.
TEST [maps/gpk_freecity.bsp][maps/rp_industrial17_v1.bsp]
TEST [maps/rp_industrial17_v1.bsp][maps/rp_industrial17_v1.bsp]
FOUND IN ADDON [171962560]
Making workshop map available for client download
ConVarRef room_type doesn't point to an existing ConVar
Executing dedicated server config file server.cfg
Using map cycle file 'cfg/mapcycle_default.txt'.  ('cfg/mapcycle.txt' was not found.)
prop_door_rotating has Door model (models/props_c17/door01_left.mdl) with no door_options! Verify that SKIN is valid, and has a corresponding options block in the model QC file
prop_door_rotating has Door model (models/props_c17/door01_left.mdl) with no door_options! Verify that SKIN is valid, and has a corresponding options block in the model QC file
prop_door_rotating has Door model (models/props_c17/door01_left.mdl) with no door_options! Verify that SKIN is valid, and has a corresponding options block in the model QC file
nexus_catwalkaccess has Door model (models/props_c17/door01_left.mdl) with no door_options! Verify that SKIN is valid, and has a corresponding options block in the model QC file
prop_door_rotating has Door model (models/props_c17/door01_left.mdl) with no door_options! Verify that SKIN is valid, and has a corresponding options block in the model QC file
prop_door_rotating has Door model (models/props_c17/door01_left.mdl) with no door_options! Verify that SKIN is valid, and has a corresponding options block in the model QC file
prop_door_rotating has Door model (models/props_c17/door01_left.mdl) with no door_options! Verify that SKIN is valid, and has a corresponding options block in the model QC file
prop_door_rotating has Door model (models/props_c17/door01_left.mdl) with no door_options! Verify that SKIN is valid, and has a corresponding options block in the model QC file
prop_door_rotating has Door model (models/props_c17/door01_left.mdl) with no door_options! Verify that SKIN is valid, and has a corresponding options block in the model QC file
prop_door_rotating has Door model (models/props_c17/door01_left.mdl) with no door_options! Verify that SKIN is valid, and has a corresponding options block in the model QC file
prop_door_rotating has Door model (models/props_c17/door01_left.mdl) with no door_options! Verify that SKIN is valid, and has a corresponding options block in the model QC file
prop_door_rotating has Door model (models/props_c17/door01_left.mdl) with no door_options! Verify that SKIN is valid, and has a corresponding options block in the model QC file
prop_door_rotating has Door model (models/props_c17/door01_left.mdl) with no door_options! Verify that SKIN is valid, and has a corresponding options block in the model QC file
prop_door_rotating has Door model (models/props_c17/door01_left.mdl) with no door_options! Verify that SKIN is valid, and has a corresponding options block in the model QC file
prop_door_rotating has Door model (models/props_c17/door01_left.mdl) with no door_options! Verify that SKIN is valid, and has a corresponding options block in the model QC file
prop_door_rotating has Door model (models/props_c17/door01_left.mdl) with no door_options! Verify that SKIN is valid, and has a corresponding options block in the model QC file
prop_door_rotating has Door model (models/props_c17/door01_left.mdl) with no door_options! Verify that SKIN is valid, and has a corresponding options block in the model QC file
prop_door_rotating has Door model (models/props_c17/door01_left.mdl) with no door_options! Verify that SKIN is valid, and has a corresponding options block in the model QC file
prop_door_rotating has Door model (models/props_c17/door01_left.mdl) with no door_options! Verify that SKIN is valid, and has a corresponding options block in the model QC file
prop_door_rotating has Door model (models/props_c17/door01_left.mdl) with no door_options! Verify that SKIN is valid, and has a corresponding options block in the model QC file
prop_door_rotating has Door model (models/props_c17/door01_left.mdl) with no door_options! Verify that SKIN is valid, and has a corresponding options block in the model QC file
office_door2 has Door model (models/props_c17/door01_left.mdl) with no door_options! Verify that SKIN is valid, and has a corresponding options block in the model QC file
office_door2 has Door model (models/props_c17/door01_left.mdl) with no door_options! Verify that SKIN is valid, and has a corresponding options block in the model QC file
Nav File is wrong or something (1)
Initializing Steam libraries for secure Internet server
Logging into anonymous gameserver account.
Unknown command "sbox_allownpcs"
Unknown command "sbox_plpldamage"
Unknown command "sbox_playergod"
Connection to Steam servers successful.
   Public IP is 88.150.197.34.
Assigned anonymous gameserver Steam ID [A-1:1448176648(4346)].
VAC secure mode is activated.


And sv_init.lua

AddCSLuaFile( ‘autorun/client/cl_init.lua’ )
include( ‘autorun/client/cl_init.lua’ )

resource.AddSingleFile( “sound/heartbeatmp3.mp3” )
util.PrecacheSound( “heartbeatmp3.mp3” )
print( “=================================================== Addon has started…”)

if file.Exists(“sound/heartbeatmp3.mp3”, “GAME”) then
print( " =============================================== file exists " )
else
print( " ================================================= file does not exist" )
end

Sorry, code tags not working.

Check it on the client.

Ah okay, will do.

[editline]30th May 2014[/editline]

Still prints that it’s found it clientside:

Did you copy the sound folder from the addon to the root /garrysmod directory. AFAIK, they can’t be in the addons folder to be downloaded, they have to be in the actual GMod folder with a FastDL.

Surely not? As the addons sound directory is like an extension to the root sound directory?
Looking in the root sound directory now I do see .ztmp version of my files which have been generated somehow.

Anyway my file does get downloaded, as I have checked my clientside download/sound directory and it is in there. But it’s just not finding it when needing to play it.

[editline]30th May 2014[/editline]

Even putting it in the root sound directory I still get the error :confused:

**[editline]30th May 2014[/editline]

Found the issue, LocalPlayer():EmitSound( “/heartbeatmp3.mp3”, 500, 100 )

Forgot the backslash at the start of the file-name.**