Scripts / Sound Controls

Author
Message
GoDevils
9
Years of Service
User Offline
Joined: 24th Sep 2014
Location: Arizona USA
Posted: 28th Dec 2020 02:08
I have a water fall and the sound of the waterfall . I want to make the sound louder as I get nearer, and softer when I'm further away. (in GG Classic)

Can this be done?
Can it be done while other sounds are playing at the same time?

Thanks
"THERE IS NO SPOON"

AMD 6300 6 core 3.5 ghz, Windows 10, 8GB ram, GTX 1060 2GB ram
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 28th Dec 2020 03:05
Yes, just make attach it to an entity, make sure it is WAV Mono format and it should do it automatically (assuming a script attached to the object has called PlaySound or LoopSound once for the slot it is in).
Been there, done that, got all the T-Shirts!
PM
GoDevils
9
Years of Service
User Offline
Joined: 24th Sep 2014
Location: Arizona USA
Posted: 28th Dec 2020 04:19
@ AmenMoses

Thanks.... Let me see if I understand..

All sound files for GG must be in mono?
Let's say I have two different sounds attached to different objects...
...Can they play at the same time? If Yes, how many can play at the same time?
... Does it matter which sound positions (0,1,2, etc) are used for each entity?

Finally, if the script (attached to the entity) plays or loops the sound,
then the near and far effect is automatic?

Going to try... let you know.

PS... what does SetSound(e,v) do?

"THERE IS NO SPOON"

AMD 6300 6 core 3.5 ghz, Windows 10, 8GB ram, GTX 1060 2GB ram
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 28th Dec 2020 11:35
Quote: "All sound files for GG must be in mono?"

no, it's just stereo is assuming it has depth in the audio already, mono is considered "flat" so GG uses that type as it's default for making fake depth of sound
Quote: "Can they play at the same time? If Yes, how many can play at the same time?"

yes multiple sounds can play at once - no idea what the limit is but i doubt you're going to reach it for any normal game
Quote: " Does it matter which sound positions (0,1,2, etc) are used for each entity?"

no, the slots are just so you can play different or multiple sounds from 1 entity - it only really matters in that you need to keep track of which sound is in which slot for the purposes of playing them later
Quote: "Finally, if the script (attached to the entity) plays or loops the sound,
then the near and far effect is automatic?"

it should if the sound is in the correct format, otherwise you can fake it via GetPlayerDistance(e) and SetSoundVolume()
Quote: "PS... what does SetSound(e,v) do?"

i've not actually seen this used, would be curious to know myself but i think maybe it was intended to swap the sound used in PlaySound() - like PlayAnimation() - however PlaySound takes the slot while PlayAnimation doesn't
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: 28th Dec 2020 13:21
You use SetSound( e, v ) to specify which sound slot to alter.
So to set the volume of sound slot 3 to 70, for example, you would do:

SetSound( e, 3 )
SetVolume( 70 )
Been there, done that, got all the T-Shirts!
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 28th Dec 2020 13:35 Edited at: 28th Dec 2020 13:35
Quote: "All sound files for GG must be in mono?"


Depends on what the sound is for, In order to give a sound 'position' the engine needs to separately feed the left and right channels at different levels to mimic the real life (loosely) situation, hence the sound *must* be mono.
For non-positional sounds, like the narrator or general background ambience (wind noise in a car for example) then you should use stereo sounds.

Designing the sound scape for a game is as important (and as difficult) as the lighting. If the player is walking along a road with a church on the left and a river on the right then it ruins the immersion if the church bells sound comes from all directions or if the water sound does, if otoh you use positional sounds and have them set up correctly then you can really draw the player in and make them feel as if they are a part of the world you have created.

Btw, GG has several separate sound systems, the entity sound slots are actually intended for positional sound, music should use the music_load/music_play system (32 tracks max per level), other non positional SFX/ambience should use the GlobalSound system.

There will be a limit to how many sounds can be loaded at once but it will be a very large number so not really worth worrying about, only the music system at 32 slots will probably be something you may reach the limit on but I don't think I've ever seen an entire game with that many music tracks let alone for one level!
Been there, done that, got all the T-Shirts!
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 28th Dec 2020 13:42
Quote: "Finally, if the script (attached to the entity) plays or loops the sound,
then the near and far effect is automatic?"


Yes, but if the entity is moving PlaySound will pay the entire sample from the position of the entity at the time it is executed whereas for LoopSound the sound position will track the entity.

Btw this all worked reasonably well until early this year when some 'fix' basically buggered up the positional sounds something awful.

I have a sound tutorial thread on this forum which no longer works as well as it should, go back to a 2019 build if you want to try that thread out!

They may have fixed it in the xmas 2020 build but I somehow doubt it.
Been there, done that, got all the T-Shirts!
PM
GoDevils
9
Years of Service
User Offline
Joined: 24th Sep 2014
Location: Arizona USA
Posted: 28th Dec 2020 17:25
@ Amen and smallg

Thank you so much. This is great info.

Soon as I'm done posting this, going to give this stuff a try

"THERE IS NO SPOON"

AMD 6300 6 core 3.5 ghz, Windows 10, 8GB ram, GTX 1060 2GB ram

Login to post a reply

Server time is: 2024-04-26 21:44:58
Your offset time is: 2024-04-26 21:44:58