Scripts / Keypress = sound

Author
Message
Honkeyboy
3D Media Maker
9
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 17th Apr 2018 14:20 Edited at: 17th Apr 2018 15:30
Hi all anyone know if we can assign a sound to the player movement keys?
e.g if g_KeyPressW == 1 then playsound (e,0)
what I would like to do is have that for a,s,w,d,so basically when a movement key is pressed a sound will play, anyone?
Thanks
Edit ok i have the footsteps sounds looping correctly when w is pressed but the sound doesnt stop when its released anyone able to point out where im going wrong?



what I'm trying to do is play the mech footfall sound when the directional keys are pressed and when released the engine winddown sound is played but the footfall sounds dont stop just keep looping
Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
AMD Radeon 7570 1gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on
GraPhiX
Forum Support
19
Years of Service
User Offline
Joined: 15th Feb 2005
Playing:
Posted: 17th Apr 2018 17:41 Edited at: 17th Apr 2018 17:42
I'm not a LUA kind of guy but I think you need to reset the key when released I think lol
Welcome to the real world!
Main PC - Windows 10 Pro x64 - Core i7-7700K @4.2GHz - 32GB DDR4 RAM - GeForce GTX 1060-6G 6GB - 1TB NVe SSD
Test PC - Windows 10 Pro x64 - G4400 @3.3GHz - 16GB DDR3 RAM - GeForce GTX 950 2GB - 500GB SSD
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 17th Apr 2018 18:32 Edited at: 17th Apr 2018 18:34
Quote: "if g_KeyPressW == 1 then
LoopSound(e,2)
if g_KeyPressW == 0 then
StopSound(e,2)
PlaySound(e,3)"

you can't have both conditions true at the same time....
your code is saying "if i'm pressing W loop a sound and if i'm also not pressing W stop that sound and play a different sound"... it doesn't make sense, you would say "if i'm pressing W loop a sound otherwise stop that sound and play another sound"

note that you will also get an issue with the sound 3 always getting played like this, you need to also add some code to check for a time only play
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Honkeyboy
3D Media Maker
9
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 17th Apr 2018 19:24 Edited at: 17th Apr 2018 19:30
Right ok thanks G dont think i need both sounds to stop now as i have filled the slots with weapon change voices so just need the footfall to stop when the key is released, thanks m8 will test those out i did try using else but sound 3 just rattled your second part works perfectly thanks for showing me how m8
Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
AMD Radeon 7570 1gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on

Login to post a reply

Server time is: 2024-12-22 20:03:27
Your offset time is: 2024-12-22 20:03:27