Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- polyphony = {}
- polyphony.Instruments = {
- "wowozela/samples/bass.wav",
- "wowozela/samples/bass.wav",
- "wowozela/samples/bass3.wav",
- "wowozela/samples/bassguitar2.wav",
- "wowozela/samples/bell.wav",
- "wowozela/samples/coolchiff.wav",
- "wowozela/samples/crackpiano.wav",
- "wowozela/samples/dingdong.wav",
- "wowozela/samples/dooooooooh.wav",
- "wowozela/samples/dusktodawn.wav",
- "wowozela/samples/flute.wav",
- "wowozela/samples/fmbass.wav",
- "wowozela/samples/fuzz.wav",
- "wowozela/samples/guitar.wav",
- "wowozela/samples/hit.wav",
- "wowozela/samples/honkytonk.wav",
- "wowozela/samples/horn.wav",
- "wowozela/samples/justice.wav",
- "wowozela/samples/littleflower.wav",
- "wowozela/samples/meow.wav",
- "wowozela/samples/miku.wav",
- "wowozela/samples/mmm.wav",
- "wowozela/samples/oohh.wav",
- "wowozela/samples/overdrive.wav",
- "wowozela/samples/pianostab.wav",
- "wowozela/samples/prima.wav",
- "wowozela/samples/quack.wav",
- "wowozela/samples/saw_880.wav",
- "wowozela/samples/sine_880.wav",
- "wowozela/samples/skull.wav",
- "wowozela/samples/slap.wav",
- "wowozela/samples/square_880.wav",
- "wowozela/samples/string.wav",
- "wowozela/samples/toypiano.wav",
- "wowozela/samples/triangle_880.wav",
- "wowozela/samples/trumpet.wav",
- "wowozela/samples/woof.wav",
- }
- if CLIENT then
- function polyphony.Start(instrument, key, pitch, volume)
- polyphony.ModifyVoice(LocalPlayer(), instrument, key, pitch, volume)
- polyphony.NetSend(instrument, key, pitch, volume)
- end
- function polyphony.Stop(instrument, key)
- polyphony.ModifyVoice(LocalPlayer(), instrument, key, 0, 0)
- polyphony.NetSend(instrument, key, 0, 0)
- end
- for key, ply in pairs(player.GetAll()) do
- if ply.poly_voices then
- for key, instrument in pairs(ply.poly_voices) do
- for key, ent in pairs(instrument) do
- if ent:IsValid() then
- if ent.poly_sound then
- ent.poly_sound:Stop()
- end
- ent:Remove()
- end
- end
- end
- end
- ply.poly_voices = nil
- end
- function polyphony.ModifyVoice(ply, instrument, key, pitch, volume)
- ply.poly_voices = ply.poly_voices or {}
- ply.poly_voices[instrument] = ply.poly_voices[instrument] or {}
- local ent = ply.poly_voices[instrument][key] or NULL
- if ent.poly_sound then
- ent.poly_sound:Stop()
- end
- SafeRemoveEntity(ent)
- if not ent:IsValid() then
- ent = ents.CreateClientProp()
- ent:SetPos(ply:EyePos())
- ent:SetModel("models/props_junk/PopCan01a.mdl")
- end
- local snd = CreateSound(ent, polyphony.Instruments[instrument])
- local mult = -(ply:EyePos():Distance(LocalPlayer():EyePos()) / 1000) + 2
- if pitch > 0 and volume > 0 then
- snd:Stop()
- snd:Play()
- snd:ChangeVolume((volume / 255) * mult, 0)
- snd:ChangePitch(pitch, 0)
- else
- snd:Stop()
- ent:Remove()
- end
- ent.poly_sound = snd
- ply.poly_voices[instrument][key] = ent
- end
- function polyphony.NetSend(instrument, key, pitch, volume)
- net.Start("polyphony")
- net.WriteInt(instrument - 128, 8)
- net.WriteInt(key - 128, 8)
- net.WriteInt(pitch - 128, 8)
- net.WriteInt(volume - 128, 8)
- net.SendToServer()
- end
- net.Receive("polyphony", function()
- local ply = net.ReadEntity()
- if ply:IsValid() then
- local instrument = net.ReadInt(8) + 128
- local key = net.ReadInt(8) + 128
- local pitch = net.ReadInt(8) + 128
- local volume = net.ReadInt(8) + 128
- --prints(ply, instrument, key, pitch, volume)
- polyphony.ModifyVoice(ply, instrument, key, pitch, volume)
- end
- end)
- end
- if SERVER then
- util.AddNetworkString("polyphony")
- net.Receive("polyphony", function(len, ply)
- if ply:IsValid() then
- local instrument = net.ReadInt(8)
- local key = net.ReadInt(8)
- local pitch = net.ReadInt(8)
- local volume = net.ReadInt(8)
- print(ply, instrument + 128, key + 128, pitch + 128, volume + 128)
- local filter = {}
- for _, v in pairs(player.GetAll()) do
- local mult = -(ply:EyePos():Distance(v:EyePos()) / 1000) + 2
- if v ~= ply and mult > 0 then
- table.insert(filter, v)
- end
- end
- net.Start("polyphony")
- net.WriteEntity(ply)
- net.WriteInt(instrument, 8)
- net.WriteInt(key, 8)
- net.WriteInt(pitch, 8)
- net.WriteInt(volume, 8)
- net.Send(filter)
- end
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement