From fffdc769915f4c53817be8ac2fb92e87c81c64c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Mon, 1 Apr 2024 21:38:18 +0300 Subject: [PATCH 1/4] Update the physcannon launch effect and core beams --- entities/effects/lambda_physcannon_impact.lua | 101 ++++++++++++++++++ entities/weapons/weapon_physcannon.lua | 60 +++++++---- 2 files changed, 139 insertions(+), 22 deletions(-) create mode 100644 entities/effects/lambda_physcannon_impact.lua diff --git a/entities/effects/lambda_physcannon_impact.lua b/entities/effects/lambda_physcannon_impact.lua new file mode 100644 index 00000000..2d3ce1b2 --- /dev/null +++ b/entities/effects/lambda_physcannon_impact.lua @@ -0,0 +1,101 @@ +local MAT_PHYSBEAM = Material("sprites/physbeam.vmt") +function EFFECT:Init(data) + local pos = data:GetOrigin() + local ent = data:GetEntity() + if not IsValid(ent) then return end + if ent:GetClass() ~= "weapon_physcannon" then return end + self.SourceEntity = ent + self.TargetPos = pos + self.DieTime = CurTime() + 0.01 + self.Color = ent:GetWeaponColor() + self.HasLight = false + local efSparks = EffectData() + efSparks:SetOrigin(pos) + efSparks:SetMagnitude(2) + efSparks:SetScale(2) + util.Effect("Sparks", efSparks) + local glowConvar = GetConVar("lambda_physcannon_glow") + if glowConvar:GetInt() > 0 then + self.EnableLights = true + else + self.EnableLights = false + end +end + +function EFFECT:Think() + local ent = self.SourceEntity + if not IsValid(ent) then return false end + if ent:GetClass() ~= "weapon_physcannon" then return false end + local owner = ent:GetOwner() + if not IsValid(owner) then return false end + if CurTime() > self.DieTime then return false end + -- Emit light. + if self.EnableLights and self.HasLight == false then + local targetPos = self.TargetPos + local startPos = ent:GetAttachment(1).Pos + local center = (startPos + targetPos) * 0.5 + local dist = startPos:Distance(targetPos) + local color = self.Color + local dlight = DynamicLight(self:EntIndex()) + dlight.dietime = self.DieTime + dlight.pos = center + dlight.r = color.r + dlight.g = color.g + dlight.b = color.b + dlight.brightness = 1 + dlight.decay = 2000 + dlight.size = dist + + self.HasLight = true + end + + return true +end + +function EFFECT:RenderBeam(startPos, endPos, seed) + local numSegments = 20 + local frequency = 5 -- Adjust the frequency of the sine wave + local color = self.Color + local curTime = CurTime() + local range = 5 + render.StartBeam(numSegments) + for i = 0, numSegments - 1 do + local t = i / numSegments + local pos = LerpVector(t, startPos, endPos) + if i > 0 then + local yOffset = math.sin(i + (seed * 10) + curTime * frequency) * range + local xOffset = math.cos(i + (seed * 20) + seed + curTime * frequency) * range + local zOffset = math.sin(i + (seed * 30) + seed + curTime * frequency * 0.5) * range + pos.x = pos.x + xOffset + pos.y = pos.y + yOffset + pos.z = pos.z + zOffset + pos = pos + VectorRand() * 0.2 + end + + render.AddBeam(pos, 5 + (math.random() * 5), 1, color) + end + + render.EndBeam() +end + +function EFFECT:Render() + local ent = self.SourceEntity + local wepPos + local owner = ent:GetOwner() + if ent:GetOwner() == LocalPlayer() then + local vm = owner:GetViewModel() + if not IsValid(vm) then return end + local wepCenter = vm:GetAttachment(1) + wepPos = ent:FormatViewModelAttachment(wepCenter.Pos, true) + wepPos = wepPos - (wepCenter.Ang:Forward() * 10) + else + local wepCenter = ent:GetAttachment(1) + wepPos = wepCenter.Pos + end + + render.SetMaterial(MAT_PHYSBEAM) + local targetPos = self.TargetPos + for n = 1, 5 do + self:RenderBeam(wepPos, targetPos, n) + end +end \ No newline at end of file diff --git a/entities/weapons/weapon_physcannon.lua b/entities/weapons/weapon_physcannon.lua index d97bfa83..7ebae3a7 100644 --- a/entities/weapons/weapon_physcannon.lua +++ b/entities/weapons/weapon_physcannon.lua @@ -1042,17 +1042,32 @@ function SWEP:GetLightBrightness() brightness = 0.5 end - if self:GetEffectState() == EFFECT_HOLDING then + local efState = self:GetEffectState() + if efState == EFFECT_HOLDING then brightness = brightness * (2.5 + (math.sin(CurTime() * 100) * 0.12)) + elseif efState == EFFECT_LAUNCH then + brightness = brightness * 2.5 end return brightness end +function SWEP:StopLights() + if self.ProjectedTexture ~= nil and IsValid(self.ProjectedTexture) then + self.ProjectedTexture:Remove() + self.ProjectedTexture = nil + end +end + function SWEP:UpdateGlow() if self:IsEffectActive(EF_NODRAW) == true then return end local glowMode = physcannon_glow_mode - if glowMode == 0 then return end + if glowMode == 0 then + self:StopLights() + + return + end + local curTime = CurTime() if curTime < self.NextGlowUpdate then return end local lightPos = self:GetLightPosition() @@ -1653,14 +1668,14 @@ function SWEP:DoEffectLaunch(pos) ef:SetOrigin(endPos) ef:SetEntity(self) if CLIENT and IsFirstTimePredicted() then - util.Effect("PhyscannonImpact", ef) + util.Effect("lambda_physcannon_impact", ef) elseif SERVER then - util.Effect("PhyscannonImpact", ef) + util.Effect("lambda_physcannon_impact", ef) end if CLIENT then local blast = self.EffectParameters[PHYSCANNON_BLAST] - blast.Scale:Init(8.0, 64, 0.1) + blast.Scale:Init(8.0, 128, 0.3) blast.Alpha:Init(255, 0, 0.2) blast.Visible = true end @@ -1895,26 +1910,27 @@ local render_StartBeam = render and render.StartBeam or nil local render_EndBeam = render and render.EndBeam or nil function SWEP:DrawBeam(startPos, endPos, width, color) color = color or Color(255, 255, 255, 255) - local len = endPos - startPos - local split = len / BEAM_SEGMENTS + local frequency = 5 + local curTime = CurTime() + local range = 1 for n = 0, BEAM_GROUPS - 1 do + local seed = n render_StartBeam(BEAM_SEGMENTS) for i = 0, BEAM_SEGMENTS - 1 do - local offset = Vector(0, 0, 0) - local pos - if i == 0 then - pos = startPos - elseif i == BEAM_SEGMENTS - 1 then - pos = endPos - else - local t = CurTime() * 15 - local p = (t + (n * n)) + (i / BEAM_SEGMENTS - 1) * math.pi - local randVec = Vector(1, 1, 1) - randVec.x = randVec.x * util.SharedRandom("beam_posx" .. tostring(i), -0.1, 0.1) - randVec.y = randVec.y * util.SharedRandom("beam_posy" .. tostring(i), -0.1, 0.1) - randVec.z = randVec.z * util.SharedRandom("beam_posz" .. tostring(i), -0.1, 0.1) - offset = Vector(1, 1, 1) * math.sin(p) + (randVec * ((n / BEAM_GROUPS) - 0.5)) - pos = startPos + (i * split) + offset + local p = i / (BEAM_SEGMENTS - 1) + local pos = LerpVector(p, startPos, endPos) + local randVec = Vector(1, 1, 1) + randVec.x = randVec.x * util.SharedRandom("beam_posx" .. tostring(i), -0.1, 0.1) + randVec.y = randVec.y * util.SharedRandom("beam_posy" .. tostring(i), -0.1, 0.1) + randVec.z = randVec.z * util.SharedRandom("beam_posz" .. tostring(i), -0.1, 0.1) + if i > 0 then + local yOffset = math.sin(i + (seed * 10) + curTime * frequency) * range + local xOffset = math.cos(i + (seed * 20) + seed + curTime * frequency) * range + local zOffset = math.sin(i + (seed * 30) + seed + curTime * frequency * 0.5) * range + pos.x = pos.x + xOffset + pos.y = pos.y + yOffset + pos.z = pos.z + zOffset + pos = pos + VectorRand() * 0.2 end local texcoord = util.SharedRandom("beam_tex" .. tostring(i), 0.5, 1) From baed9656f614d38079171bc4e4c9ddb6ea4a2abe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Mon, 1 Apr 2024 22:07:15 +0300 Subject: [PATCH 2/4] Fix physcannon dry fire not working on clients --- gamemode/sh_entity_extend.lua | 3 --- 1 file changed, 3 deletions(-) diff --git a/gamemode/sh_entity_extend.lua b/gamemode/sh_entity_extend.lua index 844d0c7f..af1179b4 100644 --- a/gamemode/sh_entity_extend.lua +++ b/gamemode/sh_entity_extend.lua @@ -397,12 +397,9 @@ end function ENTITY_META:CanTakeDamage() local data = self:GetInternalVariable("m_takedamage") - if data ~= nil then -- DAMAGE_NO return data ~= 0 - else - if self:IsNPC() == false and self:IsPlayer() == false and self:IsVehicle() == false then return false end end return true From 26dc7e9b6ea17ee68543e20aaa5e3605e7a402d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Mon, 1 Apr 2024 22:38:03 +0300 Subject: [PATCH 3/4] Improve lighting of the punt effect a bit --- entities/effects/lambda_physcannon_impact.lua | 62 +++++++++++-------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/entities/effects/lambda_physcannon_impact.lua b/entities/effects/lambda_physcannon_impact.lua index 2d3ce1b2..45405ad1 100644 --- a/entities/effects/lambda_physcannon_impact.lua +++ b/entities/effects/lambda_physcannon_impact.lua @@ -1,4 +1,5 @@ local MAT_PHYSBEAM = Material("sprites/physbeam.vmt") +local EFFECT_TIME = 0.01 function EFFECT:Init(data) local pos = data:GetOrigin() local ent = data:GetEntity() @@ -6,7 +7,7 @@ function EFFECT:Init(data) if ent:GetClass() ~= "weapon_physcannon" then return end self.SourceEntity = ent self.TargetPos = pos - self.DieTime = CurTime() + 0.01 + self.DieTime = CurTime() + EFFECT_TIME self.Color = ent:GetWeaponColor() self.HasLight = false local efSparks = EffectData() @@ -22,6 +23,24 @@ function EFFECT:Init(data) end end +function EFFECT:GetStartPos() + local ent = self.SourceEntity + local wepPos + local owner = ent:GetOwner() + if ent:GetOwner() == LocalPlayer() then + local vm = owner:GetViewModel() + if not IsValid(vm) then return end + local wepCenter = vm:GetAttachment(1) + wepPos = ent:FormatViewModelAttachment(wepCenter.Pos, true) + wepPos = wepPos - (wepCenter.Ang:Forward() * 10) + else + local wepCenter = ent:GetAttachment(1) + wepPos = wepCenter.Pos + end + + return wepPos +end + function EFFECT:Think() local ent = self.SourceEntity if not IsValid(ent) then return false end @@ -32,19 +51,23 @@ function EFFECT:Think() -- Emit light. if self.EnableLights and self.HasLight == false then local targetPos = self.TargetPos - local startPos = ent:GetAttachment(1).Pos - local center = (startPos + targetPos) * 0.5 + local startPos = self:GetStartPos() local dist = startPos:Distance(targetPos) local color = self.Color - local dlight = DynamicLight(self:EntIndex()) - dlight.dietime = self.DieTime - dlight.pos = center - dlight.r = color.r - dlight.g = color.g - dlight.b = color.b - dlight.brightness = 1 - dlight.decay = 2000 - dlight.size = dist + for i = 1, 3 do + local p = i / 3 + local pos = LerpVector(p, startPos, targetPos) + local index = bit.rshift(i, 16) + i + local dlight = DynamicLight(index) + dlight.dietime = self.DieTime + dlight.pos = pos + dlight.r = color.r + dlight.g = color.g + dlight.b = color.b + dlight.brightness = 2 + dlight.decay = 500 + dlight.size = dist + end self.HasLight = true end @@ -79,20 +102,7 @@ function EFFECT:RenderBeam(startPos, endPos, seed) end function EFFECT:Render() - local ent = self.SourceEntity - local wepPos - local owner = ent:GetOwner() - if ent:GetOwner() == LocalPlayer() then - local vm = owner:GetViewModel() - if not IsValid(vm) then return end - local wepCenter = vm:GetAttachment(1) - wepPos = ent:FormatViewModelAttachment(wepCenter.Pos, true) - wepPos = wepPos - (wepCenter.Ang:Forward() * 10) - else - local wepCenter = ent:GetAttachment(1) - wepPos = wepCenter.Pos - end - + local wepPos = self:GetStartPos() render.SetMaterial(MAT_PHYSBEAM) local targetPos = self.TargetPos for n = 1, 5 do From ea083d8146c1767a4142439878b11b47af4df3a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 1 May 2024 18:38:03 +0300 Subject: [PATCH 4/4] Update changelog.md --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index 3687a740..57e60090 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,7 @@ - Improved: Lambda no longer override the localization already existing in the game. - Improved: d2_coast_03: Give more supplies, hope this can help player fight with multiple gunships better. - Improved: d2_coast_03: Mission critical NPCs now have protection to prevent dying from a car accident. +- Improved: The gravity gun punt has now an energy effect. - Fixed: Pickup SMG grenade showing wrong icon. - Fixed: d2_coast_03: G-Man and Oddssa stay in the balcony forever. - Fixed: d2_coast_03: Blocked a exploit where player can use it to skip the final scene.