Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- chatcinematic = {}
- local lib = chatcinematic
- lib.random_seed = ""
- function lib.RandomSeed(min, max, seed)
- seed = seed or lib.random_seed
- max = max + 1
- seed = seed .. tostring(max) .. tostring(min)
- return min + (max - min) * (util.CRC(seed)/10000000000)
- end
- local function HOOK(name, ...)
- hook.Add(name, "chatcinematic_" .. name, lib[name])
- for key, value in pairs{...} do
- hook.Add(value, "chatcinematic_" .. value, lib[name])
- end
- end
- function lib.Initialize()
- lib.AddPlayer(LocalPlayer())
- end
- function lib.Stop()
- lib.players = {}
- lib.active_player = NULL
- end
- function lib.IsActive()
- return lib.GetActivePlayer():IsPlayer()
- end
- do -- players
- do -- manage
- lib.players = {}
- function lib.CheckPlayers()
- for ply in pairs(lib.players) do
- if not lib.CanChat(ply) then
- if lib.active_player == ply then
- lib.active_player = NULL
- end
- lib.players[ply] = nil
- end
- end
- end
- function lib.GetPlayers()
- lib.CheckPlayers()
- return lib.players
- end
- function lib.HasPlayer(ply)
- lib.CheckPlayers()
- return lib.players[ply] and true or false
- end
- function lib.AddPlayer(ply)
- if not lib.CanChat(ply) then
- lib.RemovePlayer(ply)
- return
- end
- lib.players[ply] = ply
- end
- function lib.RemovePlayer(ply)
- if lib.GetActivePlayer() == ply then
- lib.SetActivePlayer(NULL)
- end
- lib.players[ply] = nil
- end
- end
- function lib.SetActivePlayer(ply)
- if lib.HasPlayer(ply) then
- lib.active_player = ply
- end
- end
- function lib.GetActivePlayer()
- return lib.active_player or NULL
- end
- function lib.CanChat(a)
- local b = LocalPlayer()
- if b:GetVelocity():Length() > 300 then
- return false
- end
- if not a:IsPlayer() or a == b then
- return true
- end
- if a:GetVelocity():Length() > 300 then
- return false
- end
- local apos = a:EyePos()
- local bpos = b:EyePos()
- if apos:Distance(bpos) > lib.cam_distance then
- return false
- end
- if a:GetAimVector():Dot((apos - bpos):Normalize()) > 0.9 then
- return false
- end
- return true
- end
- function lib.OnPlayerChat(ply, str)
- if ply == LocalPlayer() then
- for key, ply in pairs(ents.FindInSphere(ply:EyePos(), lib.cam_distance)) do
- if ply:IsPlayer() then
- lib.AddPlayer(ply)
- end
- end
- end
- lib.random_seed = str
- if lib.CanChat(ply) then
- lib.AddPlayer(ply)
- if (ply.last_active_chatcinematic or 0) < CurTime() and (lib.last_active_chatcinematic or 0) < CurTime() then
- lib.ChooseRandomCameraPos(ply)
- lib.SetActivePlayer(ply)
- ply.last_active_chatcinematic = CurTime() + 3
- lib.last_active_chatcinematic = CurTime() + 1.5
- end
- else
- lib.RemovePlayer(ply)
- end
- end
- HOOK("OnPlayerChat")
- end
- do -- view
- lib.cam_distance = 200
- lib.smooth_speed = 2
- lib.pos_smooth = vector_origin
- lib.dir_smooth = vector_origin
- lib.fov_smooth = 0
- lib.pos_target = vector_origin
- lib.dir_target = vector_origin
- lib.fov_target = 75
- lib.local_camera_pos = vector_origin
- lib.angle_offset = Angle(0,0,0)
- function lib.GetEyePos(ply)
- ply = not ply:Alive() and ply:GetRagdollEntity() or ply
- local pos, ang = ply:GetBonePosition(ply:LookupBone("ValveBiped.Bip01_Head1"))
- return pos + ang:Forward() * 2
- end
- function lib.ChooseRandomCameraPos(ply)
- local prev = lib.GetActivePlayer()
- if prev ~= ply then
- ply = ply or prev
- if ply:IsPlayer() then
- lib.local_camera_pos = Vector(lib.RandomSeed(-1,1)*0.2, lib.RandomSeed(-1,1)*0.2, lib.RandomSeed(-1,1)*0.3)
- lib.angle_offset = Angle(lib.RandomSeed(-1,1)*2, lib.RandomSeed(-1,1)*8, lib.RandomSeed(-1,1))
- lib.fov_target = lib.RandomSeed(10, 40)
- lib.new_angle = true
- lib.panning_dir = Angle(0,0,0)
- lib.panning_vel = lib.RandomSeed(1,3) * lib.angle_offset.y > 0 and -1 or 1
- lib.pos_target = nil
- end
- end
- end
- function lib.GetLocalCameraPos()
- local ply = lib.GetActivePlayer()
- if ply:IsPlayer() then
- return (ply:GetAimVector() * Vector(1,1,0)) + lib.local_camera_pos
- end
- return vector_origin
- end
- function lib.GetWorldCameraPos()
- local middle = vector_origin
- local players = lib.GetPlayers()
- for ply in pairs(lib.GetPlayers()) do
- middle = middle + lib.GetEyePos(ply)
- end
- if middle ~= vector_origin then
- middle = middle / table.Count(players)
- end
- local ply = lib.GetActivePlayer()
- return LerpVector(0.2, lib.GetEyePos(ply) + (lib.GetLocalCameraPos() * (lib.cam_distance * 0.5)), middle)
- end
- function lib.CalcSmooth()
- local delta = FrameTime()
- lib.pos_smooth = lib.pos_smooth + ((lib.pos_target - lib.pos_smooth) * (delta * lib.smooth_speed))
- lib.dir_smooth = lib.dir_smooth + ((lib.dir_target - lib.dir_smooth) * (delta * lib.smooth_speed))
- lib.fov_smooth = lib.fov_smooth + ((lib.fov_target - lib.fov_smooth) * (delta * lib.smooth_speed))
- end
- lib.panning_dir = vector_origin
- lib.panning_vel = 0
- function lib.CalcPanning()
- if math.abs(lib.panning_dir.y) < 5 then
- lib.panning_dir = lib.panning_dir + (Angle(0, FrameTime()*lib.panning_vel, 0))
- end
- end
- local params = {}
- function lib.CalcView()
- lib.CheckPlayers()
- local ply = lib.GetActivePlayer()
- if ply:IsPlayer() then
- lib.pos_target = lib.pos_target or lib.GetWorldCameraPos()
- lib.dir_target = lib.GetEyePos(ply) - lib.pos_target + lib.panning_dir
- lib.CalcSmooth()
- lib.CalcPanning()
- if lib.new_angle then
- lib.pos_smooth = lib.pos_target
- lib.dir_smooth = lib.dir_target
- lib.fov_smooth = lib.fov_target
- lib.new_angle = false
- end
- params.origin = lib.pos_smooth
- params.angles = lib.dir_smooth:Angle() + lib.angle_offset + lib.panning_dir
- params.fov = lib.fov_smooth
- return params
- end
- end
- HOOK("CalcView")
- function lib.ShouldDrawLocalPlayer()
- local ply = lib.GetActivePlayer()
- if ply:IsPlayer() then
- return true
- end
- end
- HOOK("ShouldDrawLocalPlayer")
- surface.CreateFont("calibri", 48, 500, true, false, "subtitle")
- lib.letterbox_ratio = 2.39 / 1
- lib.letterbox_color = Color(0, 0, 0, 255)
- lib.letterbox_vignette = 2
- lib.letterbox_message = "hi2"
- lib.letterbox_fade = 255
- function lib.PreChatSound(data)
- lib.letterbox_message = data.key
- lib.letterbox_fade = 255
- end
- HOOK("PreChatSound")
- local grad_up = surface.GetTextureID("gui/gradient_up")
- local grad_down = surface.GetTextureID("gui/gradient_down")
- function lib.DrawLetterBox()
- local width, height = surface.ScreenWidth(), surface.ScreenHeight()
- local ratio = width / height
- surface.SetDrawColor(lib.letterbox_color)
- local vx, vy, vw, vh
- if ratio < lib.letterbox_ratio then
- vw = width
- vh = width / lib.letterbox_ratio
- vx = (width - vw) / 2
- vy = (height - vh) / 2
- surface.DrawRect(-1, -1, vw, vy)
- surface.DrawRect(-1, vy + vh, vw, height - (vy + vh))
- else
- vw = height * lib.letterbox_ratio
- vh = height
- vx = (width - vw) / 2
- vy = (height - vh) / 2
- surface.DrawRect(0, 0, vx, vh)
- surface.DrawRect(vx + vw, 0, width - (vx + vw), vh)
- end
- local c = lib.letterbox_color
- surface.SetDrawColor(c.r, c.g, c.b, c.a*0.8)
- surface.SetTexture(grad_up)
- surface.DrawTexturedRect(vx, vy + vh - vh / lib.letterbox_vignette, vw, vh / lib.letterbox_vignette)
- surface.SetTexture(grad_down)
- surface.DrawTexturedRect(vx, vy, vw, vh / lib.letterbox_vignette)
- end
- function lib.DrawSubtitles()
- surface.SetFont("subtitle")
- local w, h = surface.GetTextSize(lib.letterbox_message)
- surface.SetTextPos((ScrW() - w) / 2, (ScrH() - h) * 0.95)
- surface.SetTextColor(Color(255, 255, 255, lib.letterbox_fade))
- surface.DrawText(lib.letterbox_message)
- lib.letterbox_fade = math.Clamp(lib.letterbox_fade - 1, 0, 255)
- end
- local mat = Material("particle/Particle_Glow_04_Additive")
- local size = 400
- function lib.RenderScreenspaceEffects()
- if not chatcinematic.IsActive() then return end
- DrawSharpen(1.5, 0.3)
- DrawColorModify({
- ["$pp_colour_colour"] = 0.8,
- ["$pp_colour_brightness"] = -0.10,
- ["$pp_colour_contrast"] = 0.5,
- })
- DrawBloom( 0, 2, 0, 0, 0.15, 0.1, 1, 1, 1 )
- cam.Start2D()
- surface.SetMaterial(mat)
- surface.SetDrawColor(150,150,150,5)
- surface.DrawTexturedRect(-size, -size, ScrW()+size*2, ScrH()+size*2)
- cam.End2D()
- lib.DrawLetterBox()
- lib.DrawSubtitles()
- --cam.Start2D()
- -- surface.SetDrawColor(120,110,150,10)
- -- surface.DrawRect(0, 0, ScrW(), ScrH())
- --cam.End2D()
- end
- HOOK("RenderScreenspaceEffects")
- function chatcinematic.HUDShouldDraw(str)
- if not chatcinematic.IsActive() then return end
- if str ~= "CHudWeaponSelection" then
- return false
- end
- end
- HOOK("HUDShouldDraw")
- local emitter = ParticleEmitter(EyePos())
- emitter:SetNoDraw(true)
- function lib.PostDrawOpaqueRenderables()
- if not chatcinematic.IsActive() then return end
- for i=1, 5 do
- local particle = emitter:Add("particle/Particle_Glow_05", LocalPlayer():EyePos() + VectorRand() * 500)
- if particle then
- local col = HSVToColor(math.random()*30, 0.1, 1)
- particle:SetColor(col.r, col.g, col.b, 266)
- particle:SetVelocity(VectorRand() )
- particle:SetDieTime((math.random()+4)*3)
- particle:SetLifeTime(0)
- local size = 1
- particle:SetAngles(AngleRand())
- particle:SetStartSize((math.random()+1)*2)
- particle:SetEndSize(0)
- particle:SetStartAlpha(0)
- particle:SetEndAlpha(255)
- --particle:SetRollDelta(math.Rand(-1,1)*20)
- particle:SetAirResistance(500)
- particle:SetGravity(VectorRand() * 10)
- end
- end
- emitter:Draw()
- end
- HOOK("PostDrawOpaqueRenderables")
- timer.Create("chat_cinametic_check_players", 0.2, 0, lib.CheckPlayers)
- end
- lib.Initialize()
Advertisement
Add Comment
Please, Sign In to add comment