Page 1 of 1

Modifying mod so sound is heard everywhere in multiplayer

Posted: Sat Apr 28, 2018 9:38 pm
by thatdude333
Hello all,

There's an existing mod, TrainHorn, that plays a train horn sound when a player is run over (AKA the train horn of shame).

I've added this mod to a small multiplayer game I'm running with friends and we found that the train horn sound is only local to the person getting squished, and I'm wondering if it can be modified so that the sound is global to all players?

I've been looking through the control.lua and data.lua of this mod, trying to figure this out. My best guess is that the following event position variable in control.lua "event.cause.surface.create_entity({name = "train-horn-sound", position = event.cause.position}) is what needs to be changed, but I could be 100% wrong and I do not know what to change it to, to be able to hear the train horn globally.

Here's the control.lua and data.lua of the mod:

control.lua

Code: Select all

script.on_event(defines.events.on_player_died, function(event)
    if event.cause ~= nil then
        if event.cause.type == 'locomotive' then
            event.cause.surface.create_entity(
                {name = "train-horn-sound", position = event.cause.position})
        end
    end
end)
data.lua

Code: Select all

data:extend({
    {
        type = "explosion",
        name = "train-horn-sound",
        flags = {"not-on-map"},
        animations = {
            {
                filename = "__core__/graphics/empty.png",
                priority = "low",
                width = 1,
                height = 1,
                frame_count = 1,
                line_length = 1,
                animation_speed = 1
            }
        },
        light = {intensity = 0, size = 0},
        sound = {
            {
                filename = "__TrainHorn__/sound/horn.ogg",
                volume = 1.0
            }
        }
    }
})
Thanks for any help!

Re: Modifying mod so sound is heard everywhere in multiplayer

Posted: Sat Apr 28, 2018 10:02 pm
by Klonan
thatdude333 wrote:Hello all,

There's an existing mod, TrainHorn, that plays a train horn sound when a player is run over (AKA the train horn of shame).

I've added this mod to a small multiplayer game I'm running with friends and we found that the train horn sound is only local to the person getting squished, and I'm wondering if it can be modified so that the sound is global to all players?

I've been looking through the control.lua and data.lua of this mod, trying to figure this out. My best guess is that the following event position variable in control.lua "event.cause.surface.create_entity({name = "train-horn-sound", position = event.cause.position}) is what needs to be changed, but I could be 100% wrong and I do not know what to change it to, to be able to hear the train horn globally.

Thanks for any help!
If you don't define a position, it will play globally:
http://lua-api.factorio.com/latest/LuaS ... play_sound

Re: Modifying mod so sound is heard everywhere in multiplayer

Posted: Sat Apr 28, 2018 10:15 pm
by Bilka
Klonan wrote: If you don't define a position, it will play globally:
http://lua-api.factorio.com/latest/LuaS ... play_sound
The mod is using an explosion to play the sound, not a sound(path).