Page 1 of 1

Managing multiple weaponsounds

Posted: Fri Mar 26, 2021 11:52 am
by goodname
Hello everyone

I'm trying to modify a already existing mod. I want to add differntly pitched weapon sounds to each weapon. This should make the weapons sound less monoton and in the case uf fully automatic ones, less ear piercing. So what i already pitched the weapons sounds up and down a few tones and saved them as independent files and integrated them into the sound folder of the mod.
So i tried to extend the item.lua script with the new file names but this is where i run into errors. My question is: Is there a specific command that tells the game to pick multiple weapon sound for the same weapon randomly or at least sequentualy?

I already looked into the lua file for the standard smg of factorio which has 3 different sounds to play. I tried to copy its structure of the "sound=" and also placed the files (additionally) into the weapon sound (its name escapes me right now) folder of the "base" folder of factorio, sadly with no luck...

Re: Managing multiple weaponsounds

Posted: Fri Mar 26, 2021 12:13 pm
by DaveMcW
If you are trying to overwrite an existing entity's sound, you should not use data:extend. Instead, edit the data table directly.

Code: Select all

data.raw["gun"]["submachine-gun"].attack_parameters.sound = {
  {
    filename = "__my-mod__/sound/submachine-gunshot-1.ogg",
    volume = 0.6,
  },
  {
    filename = "__my-mod__/sound/submachine-gunshot-2.ogg",
    volume = 0.6,
  },
  {
    filename = "__my-mod__/sound/submachine-gunshot-3.ogg",
    volume = 0.6,
  }
}
Or if you want to keep the existing sounds and add another one:

Code: Select all

local new_sound = {
  filename = "__my-mod__/sound/submachine-gunshot-4.ogg",
  volume = 0.6,
}
table.insert(data.raw["gun"]["submachine-gun"].attack_parameters.sound, new_sound)

Re: Managing multiple weaponsounds

Posted: Sun Mar 28, 2021 10:56 am
by goodname
DaveMcW wrote: Fri Mar 26, 2021 12:13 pm If you are trying to overwrite an existing entity's sound, you should not use data:extend. Instead, edit the data table directly.

Code: Select all

data.raw["gun"]["submachine-gun"].attack_parameters.sound = {
  {
    filename = "__my-mod__/sound/submachine-gunshot-1.ogg",
    volume = 0.6,
  },
  {
    filename = "__my-mod__/sound/submachine-gunshot-2.ogg",
    volume = 0.6,
  },
  {
    filename = "__my-mod__/sound/submachine-gunshot-3.ogg",
    volume = 0.6,
  }
}
Or if you want to keep the existing sounds and add another one:

Code: Select all

local new_sound = {
  filename = "__my-mod__/sound/submachine-gunshot-4.ogg",
  volume = 0.6,
}
table.insert(data.raw["gun"]["submachine-gun"].attack_parameters.sound, new_sound)
Hey thank so much!!! It works now :mrgreen:

So for everyone who tries the same i'll quickly summarize what i did.

Here is the original code found in the data.lua file of the mod:

Code: Select all

require("prototypes.ammo")
require("prototypes.weapon")
require("prototypes.recipe")
require("prototypes.technology")
require("prototypes.ammo-category")
require("prototypes.projectiles")
require("prototypes.entity")
which i extended to:

Code: Select all

require("prototypes.ammo")
require("prototypes.weapon")
require("prototypes.recipe")
require("prototypes.technology")
require("prototypes.ammo-category")
require("prototypes.projectiles")
require("prototypes.entity")
data.raw["gun"]["boltgun"].attack_parameters.sound = {
  {
    filename = "__Wh40k_Armoury_fork__/sound/bolt1.wav",
    volume = 0.6,
  },
  {
    filename = "__Wh40k_Armoury_fork__/sound/bolt2.wav",
    volume = 0.6,
  },
  {
    filename = "__Wh40k_Armoury_fork__/sound/bolt3.wav",
    volume = 0.6,
  },
  {
    filename = "__Wh40k_Armoury_fork__/sound/bolt4.wav",
    volume = 0.6,
  },
  {
    filename = "__Wh40k_Armoury_fork__/sound/bolt5.wav",
    volume = 0.6,
  }
}
data.raw["gun"]["stormbolter"].attack_parameters.sound = {
  {
    filename = "__Wh40k_Armoury_fork__/sound/bolt1.wav",
    volume = 0.6,
  },
  {
    filename = "__Wh40k_Armoury_fork__/sound/bolt2.wav",
    volume = 0.6,
  },
  {
    filename = "__Wh40k_Armoury_fork__/sound/bolt3.wav",
    volume = 0.6,
  },
  {
    filename = "__Wh40k_Armoury_fork__/sound/bolt4.wav",
    volume = 0.6,
  },
  {
    filename = "__Wh40k_Armoury_fork__/sound/bolt5.wav",
    volume = 0.6,
  }
}
data.raw["gun"]["bolt_rifle"].attack_parameters.sound = {
  {
    filename = "__Wh40k_Armoury_fork__/sound/bolt1.wav",
    volume = 0.6,
  },
  {
    filename = "__Wh40k_Armoury_fork__/sound/bolt2.wav",
    volume = 0.6,
  },
  {
    filename = "__Wh40k_Armoury_fork__/sound/bolt3.wav",
    volume = 0.6,
  },
  {
    filename = "__Wh40k_Armoury_fork__/sound/bolt4.wav",
    volume = 0.6,
  },
  {
    filename = "__Wh40k_Armoury_fork__/sound/bolt5.wav",
    volume = 0.6,
  }
}
data.raw["gun"]["heavy_bolter"].attack_parameters.sound = {
  {
    filename = "__Wh40k_Armoury_fork__/sound/HBolt1.wav",
    volume = 0.6,
  }
  
}
data.raw["gun"]["assault_bolter"].attack_parameters.sound = {
  {
    filename = "__Wh40k_Armoury_fork__/sound/bolt1.wav",
    volume = 0.6,
  },
  {
    filename = "__Wh40k_Armoury_fork__/sound/bolt2.wav",
    volume = 0.6,
  },
  {
    filename = "__Wh40k_Armoury_fork__/sound/bolt3.wav",
    volume = 0.6,
  },
  {
    filename = "__Wh40k_Armoury_fork__/sound/bolt4.wav",
    volume = 0.6,
  },
  {
    filename = "__Wh40k_Armoury_fork__/sound/bolt5.wav",
    volume = 0.6,
  }
}
I added the 5 new sounds to the sound folder of the mod but i left the weapon.lua file untouched. Now it plays 5 differntly pitched weapon sounds for each full auto gun, which is much more pleasent to the ears :mrgreen:

Would it be ok for you if i try to contact the original mod dev and provide him with the newly modified files? I would give credit to you for helping me of course :)