Page 1 of 1

play_sound path issues

Posted: Tue Nov 06, 2018 9:59 am
by theelicht
Hi there!

So I'm kinda new to modding this game and recently my friends and I stumbled upon this mod called TrainHorn by Benjamin Lee.
It plays a sound to the player who died by a train, but we want it to be played globally.

Code: Select all

script.on_event(defines.events.on_player_died, function(event)
    if event.cause ~= nil then
        if event.cause.type == 'locomotive' then
			for index,player in pairs(game.connected_players) do
				player.play_sound{path="ambient/horn.ogg", position = player.position}
			end
        end
    end
end)
Right now I've got this bit of code running and when there's a known ambient sound it doesn't seem to cause an issue.
However, when we change it to "ambient/horn.ogg" it gives an unknown sound error.

Does anyone know how to make the horn sound a known ambient sound?
I thank you all in advance!

- Theelicht

Re: play_sound path issues

Posted: Tue Nov 06, 2018 10:26 am
by eradicator
@Moderators: Move to modding help please.

Sounds are defined in the data stage. You can use either a single file, or "variations" which will play one of the files at random whenever the sound is played.

Code: Select all

data:extend{{
  type = "sound",
  name = 'my_sound_name',
  variations = {
    {filename = '__my-mod-name__/a-sound-file.ogg'},
    },
  -- filename=
  volume = 0.42
  }}
And can then be used with any of the play_sound functions on either LuaSurface, LuaForce or LuaPlayer. So you don't need to loop through all players.

Code: Select all

LuaSurface.play_sound{
  path = 'my_sound_name',
  position = {0,0},
  volume_modifier = 0.8,
  }
There's no need to make it an "ambient" type of sound.

Re: play_sound path issues

Posted: Tue Nov 06, 2018 11:14 am
by theelicht
I see, I'll go ahead and give that a shot.
Thanks!