Page 1 of 2

Unit Death Sounds

Posted: 24 Feb 2014, 23:39
by Forboding Angel
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.

Re: Unit Death Sounds

Posted: 24 Feb 2014, 23:42
by smoth
as I scrolled your code, I thought, who wrote this abomination... then I read the author.. forb, why?!~?!

Re: Unit Death Sounds

Posted: 25 Feb 2014, 00:34
by knorke

Re: Unit Death Sounds

Posted: 25 Feb 2014, 00:37
by Funkencool

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

Posted: 25 Feb 2014, 01:33
by FLOZi
Beat you to it via lobby, funkencool :P

Re: Unit Death Sounds

Posted: 25 Feb 2014, 01:34
by FLOZi
Haha, I told forb i never got around to rewriting it... guess I was wrong!

Re: Unit Death Sounds

Posted: 25 Feb 2014, 03:38
by Forboding Angel
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

Re: Unit Death Sounds

Posted: 25 Feb 2014, 20:43
by FLOZi
I still say you should use

Code: Select all

if attackerID then
rather than

Code: Select all

if attackerID ~= nil then
Personal preference I guess

Re: Unit Death Sounds

Posted: 25 Feb 2014, 23:16
by Forboding Angel
FLOZi wrote:

Code: Select all

if attackerID ~= nil then
Personal preference I guess
Tbh, the way you prefer strikes me as not making sense.

Re: Unit Death Sounds

Posted: 25 Feb 2014, 23:53
by SinbadEV

Re: Unit Death Sounds

Posted: 26 Feb 2014, 12:37
by gajop
FLOZi wrote:I still say you should use

Code: Select all

if attackerID then
rather than

Code: Select all

if attackerID ~= nil then
Personal preference I guess
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.
I would only put booleans without an equality check.

Re: Unit Death Sounds

Posted: 26 Feb 2014, 18:47
by FLOZi
Conversely, I would only do a ~= nil check if the variable was going to be a bool once initialised. 8)

Re: Unit Death Sounds

Posted: 27 Feb 2014, 23:21
by code_man
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

Posted: 27 Feb 2014, 23:42
by Jools
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

Posted: 28 Feb 2014, 14:14
by PicassoCT
Forboding Angel wrote:
FLOZi wrote:

Code: Select all

if attackerID ~= nil then
Personal preference I guess
Tbh, the way you prefer strikes me as not making sense.
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?

Its one of the sweetest syntactics of lua.

Re: Unit Death Sounds

Posted: 28 Feb 2014, 14:55
by smoth
code_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.
Forb likes how the combination of the two sounds makes unit death sounds more interesting

Re: Unit Death Sounds

Posted: 28 Feb 2014, 22:12
by knorke
code_man wrote:Im kinda new to spring and all, but why arent death sounds part of the unit defs?
They are, but in bit indirect way.
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

Posted: 28 Feb 2014, 22:34
by PicassoCT
knorke wrote:
code_man wrote:Im kinda new to spring and all, but why arent death sounds part of the unit defs?
They are, but in bit indirect way.
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.
Even i didnt know that, and i dev for this engine..

I mean i knew the one, and the other one, but never figured out the way those two, could do what they do..

Re: Unit Death Sounds

Posted: 02 Mar 2014, 01:22
by Forboding Angel
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

Re: Unit Death Sounds

Posted: 13 Mar 2014, 00:17
by code_man
Ok so now i have this problem, i have a unit with an actual death explosion and i want a deathsound too.
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
But this doesnt work in 0.96, only the Soundhit gets triggered.

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?