Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local print = epoe.Print
- local me = me
- -- config / gmod specific
- local SOUNDS = {
- hi = "ambient/levels/prison/radio_random11.wav",
- oh = "ambient/energy/spark3.wav",
- boop = "buttons/button16.wav",
- kick = "weapons/crossbow/hitbod1.wav",
- beep = "npc/attack_helicopter/aheli_crash_alert2.wav",
- snare = "physics/flesh/flesh_strider_impact_bullet3.wav",
- wood = "physics/wood/wood_box_impact_bullet4.wav"
- }
- local MODIFIERS = {
- ["&"] = {
- args = {
- function(dsp) return math.Clamp(tonumber(dsp) or 0, 0, 128) end
- },
- start = function(self, dsp)
- LocalPlayer():SetDSP(dsp)
- end,
- stop = function(self, dsp)
- LocalPlayer():SetDSP(0)
- end,
- },
- ["=="] = {
- args = {
- function(time) return tonumber(time) or 1 end
- },
- init = function(self, time)
- self.duration = time
- end,
- },
- ["--"] = {
- args = {
- function(stop_percent) return tonumber(stop_percent) or 100 end
- },
- init = function(self, stop_percent)
- self.duration = self.duration * (stop_percent / 100)
- end,
- },
- ["="] = {
- args = {
- function(time) return tonumber(time) or 0 end
- },
- init = function(self, time)
- self.duration = time
- end,
- },
- ["%"] = {
- args = {
- function(pitch) return math.Clamp(tonumber(pitch) or 100, 0, 255) end,
- function(time) return tonumber(time) or 0 end,
- },
- init = function(self, pitch, time)
- self.duration = self.duration / (pitch / 100)
- self.duration = self.duration + time
- end,
- think = function(self, pitch, time)
- if self.csp then
- self.csp:ChangePitch(pitch, time)
- end
- end,
- },
- ["^"] = {
- args = {
- function(volume) return math.Clamp(tonumber(volume) or 100, 0, 100) end,
- function(time) return tonumber(time) or 0 end,
- },
- think = function(self, volume, time)
- if self.csp then
- if self.source_entity == LocalPlayer() then
- volume = volume / 2
- end
- self.csp:ChangeVolume(volume / 100, time)
- end
- end,
- }
- }
- local function PLAY_SOUND(self)
- local csp = CreateSound(me, self.path)
- csp:PlayEx(1, 0)
- self.source_entity = me
- self.csp = csp
- end
- local function STOP_SOUND(self)
- if self.csp then
- self.csp:Stop()
- end
- end
- local function GET_DURATION(self)
- return SoundDuration(self.path) or 0
- end
- --
- local cache = {}
- local function parse(str)
- if cache[str] then return cache[str] end
- local out = {}
- -- lowercase it so we don't have to deal with case sensitivity
- str = str:lower()
- -- add a last space so it matches the end as well
- str = str .. " "
- -- split the input by either space or ;
- for line in str:gmatch("(.-)%s") do
- local key, mods = line:match("([a-z_]+)([%p%d]+)")
- -- if it doesn't have a modifier, use the whole line
- if not key then
- key = line
- end
- local modifiers = {}
- if mods then
- for mod, args in mods:gmatch("(%p+)([%d%.,]+)") do
- if args then
- -- add a last . so it matches the end as well
- args = args .. ","
- local temp = {}
- -- split the args by .
- for arg in args:gmatch("(.-),") do
- -- if it's a number make it a number, otherwise leave it as string
- arg = tonumber(arg) or arg
- table.insert(temp, arg)
- end
- table.insert(modifiers, {mod = mod, args = temp})
- end
- end
- end
- table.insert(out, {key = key, modifiers = modifiers})
- end
- cache[str] = out
- return out
- end
- local function play(sounds)
- local id = "LOL_" ..tostring(sounds)
- local active_sounds = {}
- hook.Add("RenderScene", id, function()
- for key, data in pairs(active_sounds) do
- if data.stop_time < SysTime() then
- if data.last_sound then
- print(data.active_sounds[key])
- data.active_sounds[key]:stop()
- hook.Remove("RenderScene", id)
- end
- active_sounds[key] = nil
- else
- data:think()
- end
- end
- end)
- -- copy the table since we're going to modify it
- sounds = table.Copy(sounds)
- for i, sound in ipairs(sounds) do
- local path = SOUNDS[sound.key]
- if path then
- sound.path = path
- sound.duration = GET_DURATION(sound)
- sound.play = function(self)
- for i, data in pairs(self.modifiers) do
- local mod = MODIFIERS[data.mod]
- if mod and mod.start then
- mod.start(self, unpack(data.args))
- end
- end
- PLAY_SOUND(self)
- end
- sound.remove = function(self)
- for i, data in pairs(self.modifiers) do
- local mod = MODIFIERS[data.mod]
- if mod and mod.stop then
- mod.stop(self, unpack(data.args))
- end
- end
- STOP_SOUND(self)
- end
- -- only add a think function if the modifier exists
- if sound.modifiers then
- -- if args is defined use it to default and clamp the arguments
- for i, data in pairs(sound.modifiers) do
- local mod = MODIFIERS[data.mod]
- if mod and mod.args then
- for i, func in pairs(mod.args) do
- data.args[i] = func(data.args[i])
- end
- end
- end
- sound.think = function(self)
- for i, data in pairs(self.modifiers) do
- local mod = MODIFIERS[data.mod]
- if mod and mod.think then
- mod.think(self, unpack(data.args))
- end
- end
- end
- end
- end
- end
- -- play it
- local duration = 0
- local last
- for i, sound in ipairs(sounds) do
- if sound.play then
- -- let it be able to think once first so we can modify duration and such when changing pitch
- if sound.think then
- sound:think()
- end
- for mod, data in pairs(sound.modifiers) do
- local mod = MODIFIERS[data.mod]
- if mod and mod.init then
- mod.init(sound, unpack(data.args))
- end
- end
- timer.Simple(duration, function()
- if last then
- last:remove()
- end
- sound.stop_time = SysTime() + sound.duration
- sound:play()
- if sound.think then
- table.insert(active_sounds, sound)
- end
- if i == #sounds then
- sound.last_sound = true
- end
- last = sound
- end)
- duration = duration + sound.duration
- end
- end
- end
- local data = parse(
- [[
- boop%100=0.125
- boop%100=0.125
- boop%50=0.5
- boop%50=0.5
- boop%50=0.35
- boop%50=0.40
- boop%100=0.125
- boop%100=0.125
- boop%50=0.5
- boop%50=0.5
- boop%25=0.35
- boop%50=0.4
- boop%25=0.25
- boop%25==0.25
- boop%25==0.125
- boop%25==0.25
- boop%25==0.125
- boop%50=0.35
- boop%50=0.40
- boop%50=0.40
- boop%25==0.25
- boop%25==0.125
- boop%25==0.25
- boop%25==0.125
- boop%50=0.35
- boop%50=0.40
- boop%50=0.40
- boop%100=0.125
- boop%100=0.125
- boop%50=0.5
- boop%50=0.5
- boop%50=0.35
- boop%50=0.40
- ]])
- play(data)
- local data = parse(
- [[
- kick%150=0.25^0
- kick%150=0.5
- kick%150=0.5
- kick%150=0.5
- kick%150=0.5
- kick%150=0.5
- kick%150=0.5
- kick%150=0.5
- kick%150=0.5
- kick%150=0.5
- kick%150=0.5
- kick%150=0.5
- kick%150=0.5
- kick%150=0.5
- kick%150=0.5
- kick%150=0.5
- kick%150=0.5
- kick%150=1
- kick%150=1
- ]]
- )
- play(data)
- local data = parse(
- [[
- oh%255=0.125^100
- oh%255=0.125^75
- oh%255=0.125^50
- oh%255=0.125^25
- oh%255=0.125^100
- oh%255=0.125^75
- oh%255=0.125^50
- oh%255=0.125^25
- oh%255=0.125^100
- oh%255=0.125^75
- oh%255=0.125^50
- oh%255=0.125^25
- oh%255=0.125^100
- oh%255=0.125^75
- oh%255=0.125^50
- oh%255=0.125^25
- oh%255=0.125^100
- oh%255=0.125^75
- oh%255=0.125^50
- oh%255=0.125^25
- oh%255=0.125^100
- oh%255=0.125^75
- oh%255=0.125^50
- oh%255=0.125^25
- oh%255=0.125^100
- oh%255=0.125^75
- oh%255=0.125^50
- oh%255=0.125^25
- oh%255=0.125^100
- oh%255=0.125^75
- oh%255=0.125^50
- oh%255=0.125^25
- oh%255=0.125^100
- oh%255=0.125^75
- oh%255=0.125^50
- oh%255=0.125^25
- oh%255=0.125^100
- oh%255=0.125^75
- oh%255=0.125^50
- oh%255=0.125^25
- oh%255=0.125^100
- oh%255=0.125^75
- oh%255=0.125^50
- oh%255=0.125^25
- oh%255=0.125^100
- oh%255=0.125^75
- oh%255=0.125^50
- oh%255=0.125^25
- oh%255=0.125^100
- oh%255=0.125^75
- oh%255=0.125^50
- oh%255=0.125^25
- oh%255=0.125^100
- oh%255=0.125^75
- oh%255=0.125^50
- oh%255=0.125^25
- oh%255=0.125^100
- oh%255=0.125^75
- oh%255=0.125^50
- oh%255=0.125^25
- oh%255=0.125^100
- oh%255=0.125^75
- oh%255=0.125^50
- oh%255=0.125^25
- ]])
- play(data)
- local data = parse(
- [[
- hi%100=0.5
- hi%100=0.5
- hi%100=0.5
- hi%100=0.5
- hi%100=0.5
- hi%100=0.5
- hi%100=0.5
- hi%100=0.5
- ]])
- play(data)
- local data = parse(
- [[
- snare%255=0.75^0
- snare%150=1^0
- snare%150=1^0
- snare%150=1^0
- snare%150=1^0
- snare%150=1
- snare%150=1
- snare%150=1
- snare%150=0.125
- snare%150=0.5
- ]]
- )
- play(data)
Add Comment
Please, Sign In to add comment