Advertisement
yamanohera155233

Untitled

Jun 27th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. -----------------------------------------------------------------------------------------------------------------------------
  2.  
  3. -- Services
  4. local Rep = game:GetService("ReplicatedStorage")
  5. local Provider = game:GetService("ContentProvider")
  6.  
  7. local RbxUtil = LoadLibrary("RbxUtility")
  8. local Create = RbxUtil.Create
  9.  
  10. -- Others
  11. local ScapeStorage = (Rep:FindFirstChild("ScapeStorage") or Create("Folder"){
  12. Name = "ScapeStorage";
  13. Parent = Rep;
  14. })
  15.  
  16. local functions = {}
  17.  
  18. -----------------------------------------------------------------------------------------------------------------------------
  19. -- Functions
  20. -----------------------------------------------------------------------------------------------------------------------------
  21.  
  22. function functions:Preload(id)
  23. if id then
  24. local success, funct = pcall(function()
  25. Provider:Preload("http://www.roblox.com/asset/?id="..id)
  26. end)
  27. if success then
  28. return print("[SoundScape] Successfully preloaded id.")
  29. else
  30. return warn("[SoundScape] The id could not be loaded.")
  31. end
  32. end
  33. end
  34.  
  35. local function GetSound(name)
  36. if name then
  37. local SoundDir = ScapeStorage:FindFirstChild(name)
  38. if SoundDir then
  39. print("[SoundScape] Sound is a valid object in ScapeStorage's directory")
  40. return SoundDir
  41. else
  42. warn("[SoundScape] The sound is not a valid member of ScapeStorage's directory.")
  43. return nil
  44. end
  45. end
  46. end
  47.  
  48. function functions:CreateSound(name, id, parent, volume, pitch)
  49. if name and id and parent then
  50. local Sound = GetSound(name)
  51. if not Sound then
  52. local NewSound = Create("Sound"){
  53. -------------------------------
  54. Name = name;
  55. Parent = ScapeStorage;
  56. SoundId = "rbxassetid://"..id;
  57. -------------------------------
  58. Pitch = pitch or 1;
  59. Volume = volume or .5;
  60. -------------------------------
  61. }
  62.  
  63. local cNewSound = NewSound:Clone()
  64. cNewSound.Parent = parent
  65. else
  66. Sound:Clone().Parent = parent
  67. end
  68.  
  69. print("[SoundScape] Created sound.")
  70. end
  71. end
  72.  
  73. function functions:Play(sound, loop)
  74. if sound then
  75. sound.Looped = loop or false
  76. sound:Play()
  77. print("[SoundScape] Playing sound.")
  78. end
  79. end
  80.  
  81. function functions:Stop(sound)
  82. if sound then
  83. sound:Stop()
  84. print("[SoundScape] Stopping sound.")
  85. end
  86. end
  87.  
  88. function functions:GetSoundFromDir(name)
  89. return GetSound(name)
  90. end
  91.  
  92. function functions:CloneSoundFromDir(name, parent)
  93. local Sound = GetSound(name)
  94. if Sound then
  95. Sound:Clone().Parent = parent
  96. print("[SoundScape] Cloned sound from ScapeStorage's directory.")
  97. end
  98. end
  99.  
  100. function functions:RemoveSoundFromDir(name)
  101. local Sound = GetSound(name)
  102. if Sound then
  103. Sound:Destroy()
  104. print("[SoundScape] Destroyed sound.")
  105. end
  106. end
  107.  
  108. return functions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement