Scripts / Switch activate sound relative to player distance

Author
Message
magicmolecules
4
Years of Service
User Offline
Joined: 4th Dec 2019
Location:
Posted: 6th Jan 2020 09:53
Hey, i want to make a switch for a generator, when you turn it on it plays a buzzing sound. I'm able to make it play the sound, but the sound is not fading away when i leave. i tried to play around with some scripts without luck, and my LUA skills are not that good. help is very much appreciated

i got a second question. I'm struggling to learn LUA, when i see a script i know ish what it does. With simple scripts im able to modify it, kind of. I really want to learn, and i tried to google my way around and found some basic tutorials that was quite educational, but i still feal im so far away to make my own scripts. Maybe coding is not for me How did you learn lua? where should i start? is there some kind of "games" that can teach me? i don't mind if i have to pay for it...cheers







PM
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 6th Jan 2020 16:52
Try this one.

Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
magicmolecules
4
Years of Service
User Offline
Joined: 4th Dec 2019
Location:
Posted: 6th Jan 2020 17:43
Thanks for your reply, but i already got some "3d sound" scripts. i'm trying to fuse it together with the default GG switchmain.lua. so when i turn the switch it plays sound and when i get further away the sound should fade out.
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 6th Jan 2020 19:25
Only mono WAV files will automatically fade with distance and I usually find they don't fade as much as I'd like them too.
Been there, done that, got all the T-Shirts!
PM
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 6th Jan 2020 19:53
With the script that I have posted above, you can get the effect you are looking for, as you can see in the video below.



@ magicmolecules
As for the script "switchmain.lua" has many implications, so you should be more concise.
For example:

Is your switch animated?
How many frames do you have?
What frames do you want in the animation?
Do you want the switch to remain working even if the player is far from it, or instead prefer to stop the sound completely?
Can the player revisit the scene that contains the generator?
And a long etc.
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
magicmolecules
4
Years of Service
User Offline
Joined: 4th Dec 2019
Location:
Posted: 6th Jan 2020 21:11 Edited at: 6th Jan 2020 21:13
@ 3com
I don't need the button to be animated, to make it less complex for my self. The result i want is to push the button to activate the sound, and the sound should then fade when i move away from the sound source. Players will not be able to revisit later and the generator will remain active.
Im making an asylum where the power is out, the player is supposed to start the generator in the generator room before entering the the main building. After entering the building, the player will not be able to get outside again (jumps to next level).

it's the logic when i code i find difficult. What to put, when to put, what order, what goes first, what goes next. when i read a script i know 80% what it say's and what it does. But when i start a blank LUA my self it's like my brain is exploding.

i tried to make it without script using trigger zones, spawn entity with sound, and entity with sound relative to player distance. But no luck.
so then i found 2 script's that i thought could work and played around with it, also with no luck. one script like yours and the switchmain, i tried to put them together The way i tink is: When E is pressed -- then activate entity with your script -- goes on continuously.
hope this makes some kind of sense
PM
magicmolecules
4
Years of Service
User Offline
Joined: 4th Dec 2019
Location:
Posted: 6th Jan 2020 21:32
@ AmenMoses
i'll make sure to check how it works with mono WAV, I mostly use OGG for my sounds. Is the WAV format a better option? because with OGG i have had some small glitches with the sound now and then, the sound is not pure, instead it makes a crackling sound.
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 6th Jan 2020 21:49 Edited at: 6th Jan 2020 23:11
if you have loop sound in your script just replace it with this part - be sure to keep the sound number if it's not in slot 0

lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 6th Jan 2020 22:15
Yep, mono WAV files are needed for positional sounds as DX11 is used to play them and it only works with mono WAV files.

Ogg and stereo WAV are fine for background atmospherics or narrator/music etc but for positional sound effects you can only use mono WAV.

You may find this thread of interest:
https://forum.game-guru.com/thread/220877#msg2617569
Been there, done that, got all the T-Shirts!
PM
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 6th Jan 2020 22:48 Edited at: 6th Jan 2020 22:50
Attach the "soundinau" script to the generator, and the "switch on" script to the switch, sorry I don't have time to make a real switch.







Edit: fixing tags.
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
magicmolecules
4
Years of Service
User Offline
Joined: 4th Dec 2019
Location:
Posted: 7th Jan 2020 08:39
@ 3com @ smallg
Thank you for taking your time to help me out, it's very much appreciated, the scripts works perfectly.

@ AmenMoses
thanks for the tip, i tried the OGG file first and it didn't work. so i converted it to mono WAV and it works like a dream.
PM

Login to post a reply

Server time is: 2024-04-23 15:21:33
Your offset time is: 2024-04-23 15:21:33