From b4b3442e1c3eeafeeab644801a01b337c0b4e08c Mon Sep 17 00:00:00 2001 From: William Moodhe / JetBoom Date: Thu, 22 Oct 2015 03:52:29 -0400 Subject: [PATCH] Melee can hit hitboxes Temporary workaround for melee not being able to hit crouched hitboxes. --- .../gamemode/obj_entity_extend.lua | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/gamemodes/zombiesurvival/gamemode/obj_entity_extend.lua b/gamemodes/zombiesurvival/gamemode/obj_entity_extend.lua index a99f165..d8d88a2 100644 --- a/gamemodes/zombiesurvival/gamemode/obj_entity_extend.lua +++ b/gamemodes/zombiesurvival/gamemode/obj_entity_extend.lua @@ -1,6 +1,56 @@ local meta = FindMetaTable("Entity") if not meta then return end +local LASTHITCLIPHULL = false +local ClipHullBulletsResult +local ClipHullBulletsReturn = {effects = false, damage = false} +local ClipHullBullets = { + Damage = 0, + Force = 0, + Tracer = 0, + Callback = function(from, tr, dmginfo) + ClipHullBulletsResult = tr + return ClipHullBulletsReturn + end +} +function meta:ClipHullTraceHull(distance, size, start, dir) + start = start or self:GetShootPos() + dir = dir or self:GetAimVector() + + ClipHullBullets.Src = start + ClipHullBullets.Dir = dir + ClipHullBullets.HullSize = size + ClipHullBulletsResult = nil + self:FireBullets(ClipHullBullets) + + LASTHITCLIPHULL = false + + if ClipHullBulletsResult and ClipHullBulletsResult.HitNonWorld and ClipHullBulletsResult.Entity:IsValid() and ClipHullBulletsResult.Entity:IsPlayer() and ClipHullBulletsResult.HitPos:Distance(start) <= distance then + LASTHITCLIPHULL = true + return ClipHullBulletsResult + end + + return self:TraceHull(distance, mask, size, filter, start) +end + +function meta:ClipHullMeleeTrace(distance, size, start) + return self:ClipHullTraceHull(distance, size, start) +end + +-- Extremely shitty workaround for util trace functions not using clip hulls +function meta:PenetratingClipHullMeleeTrace(distance, size, prehit, start, dir) + local t + local cliphullpretrace = self:ClipHullTraceHull(distance, size, start, dir) + self:LagCompensation(true) + t = self:PenetratingMeleeTrace(distance, size, prehit, start, dir) + if cliphullpretrace and LASTHITCLIPHULL and cliphullpretrace.Entity ~= prehit then + table.insert(t, 1, cliphullpretrace) + end + self:LagCompensation(false) + + return t +end + function meta:ApplyPlayerProperties(ply) self.GetPlayerColor = function() return ply:GetPlayerColor() end self:SetBodygroup( ply:GetBodygroup(1), 1 )