Play a sound position-independently for all passengers of a train

Place to get help with not working mods / modding interface.
Post Reply
boernsen2
Inserter
Inserter
Posts: 21
Joined: Thu Dec 02, 2021 5:36 pm
Contact:

Play a sound position-independently for all passengers of a train

Post by boernsen2 »

Hi everyone,

would it be possible at all to play a sound for all players sitting in a certain train, but in a position-independent way, so that the sound doesn't become silent when the train moves away from the original play_sound position?

The intention is to have a sound being played for all passengers when the train is passing a certain trigger position.

Thank you very much in advance!

boernsen2
Inserter
Inserter
Posts: 21
Joined: Thu Dec 02, 2021 5:36 pm
Contact:

Re: Play a sound position-independently for all passengers of a train

Post by boernsen2 »

Btw I already searched for other threads beforehand and also found this one: Modifying mod so sound is heard everywhere in multiplayer

But it only mentions https://lua-api.factorio.com/latest/Lua ... play_sound, which according to the documentation:
position:: MapPosition? Where the sound should be played. If not given, it's played at the current position of each player.
As far as I understand, this would mute the sound as well when the train (and its passengers) move away quickly.

Would there be any chance to get this working using a speaker?
([1.1.34] play_sound{...} not playing sound globally)

Qon
Smart Inserter
Smart Inserter
Posts: 2119
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: Play a sound position-independently for all passengers of a train

Post by Qon »

boernsen2 wrote:
Sun Apr 10, 2022 11:24 am
Btw I already searched for other threads beforehand and also found this one: Modifying mod so sound is heard everywhere in multiplayer

But it only mentions https://lua-api.factorio.com/latest/Lua ... play_sound, which according to the documentation:
position:: MapPosition? Where the sound should be played. If not given, it's played at the current position of each player.
As far as I understand, this would mute the sound as well when the train (and its passengers) move away quickly.

Would there be any chance to get this working using a speaker?
([1.1.34] play_sound{...} not playing sound globally)
Use https://lua-api.factorio.com/latest/Lua ... play_sound if you want to play it for some players but not others (like players close by the train but outside it)
It also has
position:: MapPosition? Where the sound should be played. If not given, it's played at the current position of the player.
I don't think moving should mute/decrease the volume of the sound, that would be odd.

Edit: it is odd.

boernsen2
Inserter
Inserter
Posts: 21
Joined: Thu Dec 02, 2021 5:36 pm
Contact:

Re: Play a sound position-independently for all passengers of a train

Post by boernsen2 »

Got it!!!

I accidentally 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!! :)


Post Reply

Return to “Modding help”