Modifying mod so sound is heard everywhere in multiplayer

Place to get help with not working mods / modding interface.
thatdude333
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sat Apr 28, 2018 9:17 pm
Contact:

Modifying mod so sound is heard everywhere in multiplayer

Post 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!
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5404
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Modifying mod so sound is heard everywhere in multiplayer

Post 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
Bilka
Factorio Staff
Factorio Staff
Posts: 3415
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Modifying mod so sound is heard everywhere in multiplayer

Post 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).
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Post Reply

Return to “Modding help”