Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -----------------------------------------------------------------------------------------------------------------------------
- -- Services
- local Rep = game:GetService("ReplicatedStorage")
- local Provider = game:GetService("ContentProvider")
- local RbxUtil = LoadLibrary("RbxUtility")
- local Create = RbxUtil.Create
- -- Others
- local ScapeStorage = (Rep:FindFirstChild("ScapeStorage") or Create("Folder"){
- Name = "ScapeStorage";
- Parent = Rep;
- })
- local functions = {}
- -----------------------------------------------------------------------------------------------------------------------------
- -- Functions
- -----------------------------------------------------------------------------------------------------------------------------
- function functions:Preload(id)
- if id then
- local success, funct = pcall(function()
- Provider:Preload("http://www.roblox.com/asset/?id="..id)
- end)
- if success then
- return print("[SoundScape] Successfully preloaded id.")
- else
- return warn("[SoundScape] The id could not be loaded.")
- end
- end
- end
- local function GetSound(name)
- if name then
- local SoundDir = ScapeStorage:FindFirstChild(name)
- if SoundDir then
- print("[SoundScape] Sound is a valid object in ScapeStorage's directory")
- return SoundDir
- else
- warn("[SoundScape] The sound is not a valid member of ScapeStorage's directory.")
- return nil
- end
- end
- end
- function functions:CreateSound(name, id, parent, volume, pitch)
- if name and id and parent then
- local Sound = GetSound(name)
- if not Sound then
- local NewSound = Create("Sound"){
- -------------------------------
- Name = name;
- Parent = ScapeStorage;
- SoundId = "rbxassetid://"..id;
- -------------------------------
- Pitch = pitch or 1;
- Volume = volume or .5;
- -------------------------------
- }
- local cNewSound = NewSound:Clone()
- cNewSound.Parent = parent
- else
- Sound:Clone().Parent = parent
- end
- print("[SoundScape] Created sound.")
- end
- end
- function functions:Play(sound, loop)
- if sound then
- sound.Looped = loop or false
- sound:Play()
- print("[SoundScape] Playing sound.")
- end
- end
- function functions:Stop(sound)
- if sound then
- sound:Stop()
- print("[SoundScape] Stopping sound.")
- end
- end
- function functions:GetSoundFromDir(name)
- return GetSound(name)
- end
- function functions:CloneSoundFromDir(name, parent)
- local Sound = GetSound(name)
- if Sound then
- Sound:Clone().Parent = parent
- print("[SoundScape] Cloned sound from ScapeStorage's directory.")
- end
- end
- function functions:RemoveSoundFromDir(name)
- local Sound = GetSound(name)
- if Sound then
- Sound:Destroy()
- print("[SoundScape] Destroyed sound.")
- end
- end
- return functions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement