Unit Death Sounds

Unit Death Sounds

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Unit Death Sounds

Post 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.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Unit Death Sounds

Post by smoth »

as I scrolled your code, I thought, who wrote this abomination... then I read the author.. forb, why?!~?!
User avatar
Funkencool
Posts: 542
Joined: 02 Dec 2011, 22:31

Re: Unit Death Sounds

Post 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
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Unit Death Sounds

Post by FLOZi »

Beat you to it via lobby, funkencool :P
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Unit Death Sounds

Post by FLOZi »

Haha, I told forb i never got around to rewriting it... guess I was wrong!
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Unit Death Sounds

Post 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
Last edited by Forboding Angel on 25 Feb 2014, 23:09, edited 1 time in total.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Unit Death Sounds

Post 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
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Unit Death Sounds

Post 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.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Unit Death Sounds

Post 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.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Unit Death Sounds

Post by FLOZi »

Conversely, I would only do a ~= nil check if the variable was going to be a bool once initialised. 8)
User avatar
code_man
Posts: 260
Joined: 19 Jan 2014, 13:10

Re: Unit Death Sounds

Post 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.
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: Unit Death Sounds

Post 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.
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10454
Joined: 24 Jan 2006, 21:12

Re: Unit Death Sounds

Post 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.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Unit Death Sounds

Post 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
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Unit Death Sounds

Post 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.
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10454
Joined: 24 Jan 2006, 21:12

Re: Unit Death Sounds

Post 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..
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Unit Death Sounds

Post 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
User avatar
code_man
Posts: 260
Joined: 19 Jan 2014, 13:10

Re: Unit Death Sounds

Post 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?
Post Reply

Return to “Lua Scripts”