Page 1 of 1

[1.1.34] play_sound{...} not playing sound globally

Posted: Sun May 30, 2021 8:27 pm
by Stringweasel
I'm trying to play a sound that's heard globally, ideally only for specific players. According to the docs if I don't supply a position argument then it's played "everywhere". However, when I play the sound and walk away the sound volume lowers, and disappear if I'm far enough away. I expect the volume to stay constant because I don't supply a position.

I tried this using surface and player and observed no difference. Also, I'm playing the siren sound which is quite long.

Reproduce

Load the little mod that simply creates a SoundPath for the siren sound. Then type the following console command:

Code: Select all

/c game.player.surface.play_sound{path="siren"}
or

Code: Select all

/c game.player.play_sound{path="siren"}
You will hear the sound. Walk away, and the sound volume will lower and eventually dissapear if you're far enough away.

Re: [1.1.34] play_sound{...} not playing sound globally

Posted: Mon May 31, 2021 1:24 pm
by Rseding91
Thanks for the report. Currently this is how sounds work: when a sound is played it gets played at a position (in this case the player position) and since it's not tied to a specific entity the position stays where it was created. Maybe the name could be updated or the docs updated to mention that it plays at the player(s) position so if they move and the sound is long it doesn't move with them.

Re: [1.1.34] play_sound{...} not playing sound globally

Posted: Mon May 31, 2021 1:39 pm
by Stringweasel
I understand, that is unfortunate. I will make a note later in Bilka's thread that the docs should be updated.

So, there is no way in Lua to mimic a programable speaker that plays the siren sound consistently and heard everywhere, except for building a physical programmable speaker entity and setting it to play the siren? This will cause all players to hear it, but I can live with that. I'd rather have the sound consistent.

Thanks for having a look at it Rseding!

Re: [1.1.34] play_sound{...} not playing sound globally

Posted: Sun Apr 10, 2022 11:25 am
by boernsen2
Did you find any way to play a custom sound globally for all players and position-independently?

Re: [1.1.34] play_sound{...} not playing sound globally

Posted: Sun Apr 10, 2022 1:10 pm
by Stringweasel
boernsen2 wrote:
Sun Apr 10, 2022 11:25 am
Did you find any way to play a custom sound globally for all players and position-independently?
I decided it was out-of-scope for me, but someone did make a good suggestion to me. Spawn a speaker and let the speaker play the sound somehow. A speaker can be set to play global, and will stay global even if you move around. And if you're doing data-stage as well you could create an invisible speaker to use. Spawn it somewhere and after the sound is done delete it again. Or create a single one that's the dedicated sound maker, depends on your implementation. Never tried it though.

Re: [1.1.34] play_sound{...} not playing sound globally

Posted: Sun Apr 10, 2022 7:14 pm
by boernsen2
Just for reference, I just found a solution accidentally!!! :)

I stumbled over this:
https://wiki.factorio.com/Prototype/Sou ... e_modifier

Just configure your sound with an exorbitantly high audible_distance_modifier in data.lua, e.g.

Code: Select all

data:extend({
  {
    type = "sound",
    name = "my_sound",
    filename = "__ModName__/my_sound.ogg",
    category = "gui-effect",
    volume = 1.0,
    audible_distance_modifier = 1e20
  }
})
Then use it as usual with any of these:
https://lua-api.factorio.com/latest/Lua ... play_sound
https://lua-api.factorio.com/latest/Lua ... play_sound
https://lua-api.factorio.com/latest/Lua ... play_sound
https://lua-api.factorio.com/latest/Lua ... play_sound

Thanks for all your inspriation!! :)