• How to make a weapon play a constant sound, which other players can also hear?
    4 replies, posted
Hi, I have the TTT cloaking device on my server: [url]http://steamcommunity.com/sharedfiles/filedetails/?id=278890424[/url] I find it a bit too OP so I thought it would be better if the weapon would play a constant sound. I'm not the best with lua but i guess it would require editing the SWEP.Think function, but that runs every tick as far as I know, so it would cause lag I guess. The weapon works by just equipping it i.e. no left/right clicking. So I need the weapon to emit a sound every time the weapon is equipped. The sound would also need to be heard by others so they know that a player is cloaked and is able to find them using the direction of the sound. This part is off-topic but if anyone has suggestions on how I can make this weapon less OP that would be cool. I did think of using a cooldown feature but that is was out of my coding capability. --edit-- fixed, here is my code: [LUA] function SWEP:Deploy() timer.Create("timer_name", 5, 0, function() local sound= Sound( your_sound.wav" ) self.Weapon:EmitSound( sound) end ) end [/LUA] replace timer_name with a suitable name and 5 with the length of the sound file. [Lua] function SWEP:Holster( wep ) timer.Destroy("timer_name") return true end [/Lua] replace timer_name with the name you used in SWEP:Deploy
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index527b.html[/url]
[QUOTE=code_gs;45787935][url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index527b.html[/url][/QUOTE] Yeah I was just messing with that and it only plays the sound once, I tried to create a infinite loop but that just crashes the server. Is there any otherway behinds creating a huge looping wav file?
Put the sound playing function in a timer that loops infinitely for however long the sound file lasts, then destroy the timer in this: [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexb2ae.html[/url]
--removed--
Sorry, you need to Log In to post a reply to this thread.