play_sound path issues

Place to get help with not working mods / modding interface.
theelicht
Manual Inserter
Manual Inserter
Posts: 4
Joined: Tue Nov 06, 2018 9:51 am
Contact:

play_sound path issues

Post 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
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: play_sound path issues

Post 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.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
theelicht
Manual Inserter
Manual Inserter
Posts: 4
Joined: Tue Nov 06, 2018 9:51 am
Contact:

Re: play_sound path issues

Post by theelicht »

I see, I'll go ahead and give that a shot.
Thanks!
Post Reply

Return to “Modding help”