• Playing custom sounds [Gamemode]
    5 replies, posted
So I've tried adding a sound whenever the client presses the USE button (Which is E). But It doesn't play the sound, all it gives me in console is this, [CODE] Failed to load sound "sound\allahu.wav", file probably missing from disk/repository [/CODE] There is no other lua errors, just this part. I've tried fixing it by myself for a while now but I failed, so I came here for some help, what was I doing wrong? The Path for the sound file, \Steam\SteamApps\common\GarrysMod\garrysmod\gamemodes\creative\content\sound\allahu.wav . And the Path for the lua file, \Steam\SteamApps\common\GarrysMod\garrysmod\gamemodes\creative\gamemode\init.lua . Here is the code that I'm talking about. Its located in init.lua . [CODE] AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") resource.AddFile("sound/allahu.wav") AddCSLuaFile("cl_powers.lua") include("sv_powers.lua") include("shared.lua") local ply=FindMetaTable("Player") function GM:KeyPress(ply,key) if key==IN_USE and ply:Alive() then if expt==0 then expt=1 local exp=ents.Create("env_explosion") exp:Spawn() exp:SetKeyValue("iMagnitude",200) exp:EmitSound( "sound/allahu.wav" ) timer.Simple(.5,function() exp:SetPos(ply:GetPos()) exp:Fire("Explode",0,0) expt=0 end) else sound.Play("weapons/slam/buttonclick.wav",Vector(ply:GetPos())) end end [/CODE] Thanks.
When you are playing a sound it looks in the sound folder instantly so you don't need any folder paths unless it is not in the sound folder. If you where to have the sound in sound/explosive/allahu.wav then you would use the path explosive/allahu.wav. Try [CODE] exp:EmitSound("allahu.wav") [/CODE]
[QUOTE=Cheese_3;49962696]When you are playing a sound it looks in the sound folder instantly so you don't need any folder paths unless it is not in the sound folder. If you where to have the sound in sound/explosive/allahu.wav then you would use the path explosive/allahu.wav. Try [CODE] exp:EmitSound("allahu.wav") [/CODE][/QUOTE] Thank you for the quick reply and explanation, it worked! [editline]19th March 2016[/editline] Another question, How do I force the client side to download the sound file?
[QUOTE=MrNeon;49962766]Thank you for the quick reply and explanation, it worked! [editline]19th March 2016[/editline] Another question, How do I force the client side to download the sound file?[/QUOTE] No Problem, resource.AddFile() Is what you use to force the user to download the file. [CODE] if ( SERVER ) then resource.AddFile( "sound/allahu.wav" ) end [/CODE]
[QUOTE=Cheese_3;49963130]No Problem, resource.AddFile() Is what you use to force the user to download the file. [CODE] if ( SERVER ) then resource.AddFile( "sound/allahu.wav" ) end [/CODE][/QUOTE] Thank you again.
Look here for more info on EmitSound: [url]https://wiki.garrysmod.com/page/Global/EmitSound[/url]
Sorry, you need to Log In to post a reply to this thread.