ForbodingAngel

Untitled

Feb 24th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. Spring.Echo ('This is my dick, there are many like it but this one is mine')
  2.  
  3. function gadget:GetInfo()
  4. return {
  5. name = "Randomised Death Sounds",
  6. desc = "Assign and play classes of unit death sounds",
  7. author = "FLOZi (C. Lawrence), rewrite of DeathSounds.lua by Argh",
  8. date = "19/05/2011",
  9. license = "Public Domain",
  10. layer = 1,
  11. enabled = true
  12. }
  13. end
  14.  
  15. -- Localisations
  16. local random = math.random
  17.  
  18. -- Synced Read
  19. local GetUnitDefID = Spring.GetUnitDefID
  20. local GetUnitNeutral = Spring.GetUnitNeutral
  21. local GetUnitPosition = Spring.GetUnitPosition
  22.  
  23. -- Unsynced Ctrl
  24. local PlaySoundFile = Spring.PlaySoundFile
  25.  
  26. -- constants
  27. local DEFAULT_VOLUME = 15
  28. local SOUNDS_PATH = "sounds/deathsounds/"
  29. local GAIA_TEAM_ID = Spring.GetGaiaTeamID()
  30.  
  31. -- variables
  32. local soundClasses = {}
  33. local soundClassSizes = {}
  34. local udSoundCache = {}
  35. local udVolumeCache = {}
  36.  
  37. -- included for RecursiveFileSearch
  38. local VFSUtils = VFS.Include('gamedata/VFSUtils.lua')
  39.  
  40. if (gadgetHandler:IsSyncedCode()) then
  41. -- SYNCED
  42.  
  43. function gadget:Initialize()
  44. local subDirs = VFS.SubDirs(SOUNDS_PATH)
  45. for i = 1, #subDirs do
  46. local subDir = subDirs[i]
  47. if not subDir:match("/%.svn") then
  48. local dirName = string.gsub(subDir,SOUNDS_PATH,'')
  49. dirName = string.gsub(dirName,"/",'')
  50. -- Spring.Echo (dirName)
  51. soundClasses[dirName] = RecursiveFileSearch(subDir)
  52. soundClassSizes[dirName] = #soundClasses[dirName]
  53. end
  54. end
  55. for unitDefID, unitDef in pairs(UnitDefs) do
  56. local cp = unitDef.customParams
  57. if cp and cp.death_sounds then
  58. udSoundCache[unitDefID] = cp.death_sounds
  59. udVolumeCache[unitDefID] = cp.death_volume or DEFAULT_VOLUME
  60. end
  61. end
  62. end
  63.  
  64.  
  65. function gadget:UnitDestroyed(unitID, unitDefID, teamId)
  66. local soundClass = udSoundCache[unitDefID]
  67. -- Spring.Echo (soundClass)
  68. -- Spring.Echo (soundClasses)
  69. -- Spring.Echo (soundClassSizes)
  70. if soundClass then
  71. local choice = random(soundClassSizes[soundClass])
  72. local x, y, z = GetUnitPosition(unitID)
  73. local volume = udVolumeCache[unitDefID]
  74. PlaySoundFile(soundClasses[soundClass][choice], volume, x, y, z)
  75. end
  76. end
  77.  
  78. end
Advertisement
Add Comment
Please, Sign In to add comment