Unit Death Sounds
Moderator: Moderators
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Unit Death Sounds
I have used this gadget for a really long time, but it has the most annoying drawback, and that is that each sound must be added manually to the gadget.
Can someone edit it so that it will just read sounds for a separate directory for each type of unit (soldier, generic, nuke, etc) and randomize form all the sounds in that dir automagically instead of using the silly method here?
https://code.google.com/p/evolutionrts/ ... sounds.lua
I can't imagine that I'm the only one who finds this gadget useful.
Can someone edit it so that it will just read sounds for a separate directory for each type of unit (soldier, generic, nuke, etc) and randomize form all the sounds in that dir automagically instead of using the silly method here?
https://code.google.com/p/evolutionrts/ ... sounds.lua
I can't imagine that I'm the only one who finds this gadget useful.
Re: Unit Death Sounds
as I scrolled your code, I thought, who wrote this abomination... then I read the author.. forb, why?!~?!
- Funkencool
- Posts: 542
- Joined: 02 Dec 2011, 22:31
Re: Unit Death Sounds
Code: Select all
function gadget:UnitDestroyed(u, ud, team, attackerID)
if attackerID ~= nil then --Add this so that units who are destroyed via lua (like salvaging) or self destructed, will not play an overlapping sound effect
if SoldierDeath[ud] and GetUnitNeutral(u) == false then
randomPick = math_rand(1,32)
x,y,z = GetUnitPosition(u)
PlaySoundFile("sounds/unitdeath/e"..randomPick..".wav",15, x, y, z )
end
Re: Unit Death Sounds
Beat you to it via lobby, funkencool 

Re: Unit Death Sounds
Haha, I told forb i never got around to rewriting it... guess I was wrong!
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Unit Death Sounds
http://pastebin.com/zseXFhHj
Here is the fixed and working code. Yes, we know, gsub twice, bad, blah blah. Anyone who cares enough can feel free to pitch in code to fix it
Thank you flozi and smothikins for all the help :-D
Here is the gadget in Evo. You can also have a look in the Evo sounds folder to see exactly show the structure is set up.
https://code.google.com/p/evolutionrts/ ... sounds.lua
Here is the fixed and working code. Yes, we know, gsub twice, bad, blah blah. Anyone who cares enough can feel free to pitch in code to fix it

Thank you flozi and smothikins for all the help :-D
Here is the gadget in Evo. You can also have a look in the Evo sounds folder to see exactly show the structure is set up.
https://code.google.com/p/evolutionrts/ ... sounds.lua
Last edited by Forboding Angel on 25 Feb 2014, 23:09, edited 1 time in total.
Re: Unit Death Sounds
I still say you should use
rather than
Personal preference I guess
Code: Select all
if attackerID then
Code: Select all
if attackerID ~= nil then
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Unit Death Sounds
Tbh, the way you prefer strikes me as not making sense.FLOZi wrote:Personal preference I guessCode: Select all
if attackerID ~= nil then
Re: Unit Death Sounds
Personal preference indeed, I prefer the second way - I find it more clearly represents what you're trying to check, which in this case is whether attackerID is set.FLOZi wrote:I still say you should use
rather thanCode: Select all
if attackerID then
Personal preference I guessCode: Select all
if attackerID ~= nil then
I would only put booleans without an equality check.
Re: Unit Death Sounds
Conversely, I would only do a ~= nil check if the variable was going to be a bool once initialised. 

Re: Unit Death Sounds
Im kinda new to spring and all, but why arent death sounds part of the unit defs?
I mean it seems so generic that it might aswel be there instead of having to use a seperate gadget for it.
I mean it seems so generic that it might aswel be there instead of having to use a seperate gadget for it.
Re: Unit Death Sounds
That's a good question. It used to be part of unitdef, but more and more stuff has been moved out to lua.
Re: Unit Death Sounds
it makes perfect sense. What is more natural, then having a object in a enviroment which expects a boolean, then too ask for the existance of said object?Forboding Angel wrote:Tbh, the way you prefer strikes me as not making sense.FLOZi wrote:Personal preference I guessCode: Select all
if attackerID ~= nil then
Its one of the sweetest syntactics of lua.
Re: Unit Death Sounds
Forb likes how the combination of the two sounds makes unit death sounds more interestingcode_man wrote:Im kinda new to spring and all, but why arent death sounds part of the unit defs?
I mean it seems so generic that it might aswel be there instead of having to use a seperate gadget for it.
Re: Unit Death Sounds
They are, but in bit indirect way.code_man wrote:Im kinda new to spring and all, but why arent death sounds part of the unit defs?
unitDefs have explodeAs : "The name of the weapon this unit should explode as when it is killed"
This triggered weapon can then have sound via soundStart.
Re: Unit Death Sounds
Even i didnt know that, and i dev for this engine..knorke wrote:They are, but in bit indirect way.code_man wrote:Im kinda new to spring and all, but why arent death sounds part of the unit defs?
unitDefs have explodeAs : "The name of the weapon this unit should explode as when it is killed"
This triggered weapon can then have sound via soundStart.
I mean i knew the one, and the other one, but never figured out the way those two, could do what they do..
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Unit Death Sounds
Soundhit = when a projectile hits a target
Soundstart = the sound that is given when a projectile is fired
So for explodeas defs, you use soundstart
Soundstart = the sound that is given when a projectile is fired
So for explodeas defs, you use soundstart
Re: Unit Death Sounds
Ok so now i have this problem, i have a unit with an actual death explosion and i want a deathsound too.
Also, isnt it a bit overkill to have to have a weapon instead of a simple sound table entry for deathsounds?
Furthermore is it possible to have a set of sounds for death?
But this doesnt work in 0.96, only the Soundhit gets triggered.Forboding Angel wrote:Soundhit = when a projectile hits a target
Soundstart = the sound that is given when a projectile is fired
So for explodeas defs, you use soundstart
Also, isnt it a bit overkill to have to have a weapon instead of a simple sound table entry for deathsounds?
Furthermore is it possible to have a set of sounds for death?