Files
garrysmod-coop/lua/entities/feedc0de_friendly_scanner/cl_init.lua
T

70 lines
2.5 KiB
Lua

include("shared.lua")
local healingBeam = Material("effects/laser1")
local healingGlow = Material("sprites/light_glow02_add")
local beamColor = Color(255, 218, 65, 235)
local beamCoreColor = Color(255, 252, 205, 255)
local function LightPosition(scanner)
local attachmentID = scanner:LookupAttachment("light")
local attachment = attachmentID and attachmentID > 0 and scanner:GetAttachment(attachmentID)
return attachment and attachment.Pos or (scanner:WorldSpaceCenter() + scanner:GetForward() * 16)
end
local function DrawHealingArc(startPosition, endPosition, scannerIndex)
local direction = endPosition - startPosition
local normalized = direction:GetNormalized()
local perpendicular = normalized:Cross(Vector(0, 0, 1))
if perpendicular:LengthSqr() < 0.01 then perpendicular = Vector(1, 0, 0) end
perpendicular:Normalize()
local vertical = normalized:Cross(perpendicular):GetNormalized()
local time = CurTime()
local segments = 12
render.SetMaterial(healingBeam)
render.StartBeam(segments + 1)
for segment = 0, segments do
local fraction = segment / segments
local position = LerpVector(fraction, startPosition, endPosition)
if segment > 0 and segment < segments then
local taper = math.sin(fraction * math.pi)
position = position
+ perpendicular * math.sin(time * 13 + segment * 2.31 + scannerIndex) * 6 * taper
+ vertical * math.cos(time * 17 + segment * 1.73 + scannerIndex) * 4 * taper
end
render.AddBeam(position, 4.5, fraction, beamColor)
end
render.EndBeam()
render.DrawBeam(startPosition, endPosition, 1.25, 0, 1, beamCoreColor)
end
function ENT:Draw()
self:DrawModel()
end
function ENT:DrawTranslucent()
if self:GetNW2Bool("CustomCoopScannerWreck", false) then return end
local lightPosition = LightPosition(self)
render.SetMaterial(healingGlow)
render.DrawSprite(lightPosition, 24, 24, beamColor)
local light = DynamicLight(self:EntIndex())
if light then
light.pos = lightPosition
light.r = 255
light.g = 205
light.b = 45
light.brightness = 2
light.Decay = 500
light.Size = 105
light.DieTime = CurTime() + 0.2
end
local patient = self:GetHealingTarget()
if IsValid(patient) and patient:IsPlayer() then
DrawHealingArc(lightPosition, patient:WorldSpaceCenter(), self:EntIndex())
render.DrawSprite(patient:WorldSpaceCenter(), 15, 15, beamCoreColor)
end
end