From a8de63b52af1d4eb9363d2f931c91b030b06f4a4 Mon Sep 17 00:00:00 2001 From: relaxtakenotes <134127331+jeffthekillerz@users.noreply.github.com> Date: Sun, 4 Jun 2023 13:31:28 +0500 Subject: [PATCH] fov based bullet detection yuh --- .../gamemode/player_class/player_beatrun.lua | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/beatrun/gamemodes/beatrun/gamemode/player_class/player_beatrun.lua b/beatrun/gamemodes/beatrun/gamemode/player_class/player_beatrun.lua index 081759c..9e10a32 100644 --- a/beatrun/gamemodes/beatrun/gamemode/player_class/player_beatrun.lua +++ b/beatrun/gamemodes/beatrun/gamemode/player_class/player_beatrun.lua @@ -305,9 +305,7 @@ hook.Add("ShouldCollide", "NoPlayerCollisions", function(ent1, ent2) if ent2.BRCollisionFunc then return ent2:BRCollisionFunc(ent1) else - if ent1.br_Fired or ent2.br_Fired then - return true - end + if (ent1.br_Fired and ent2.br_FiredBy == ent1) or (ent2.br_Fired and ent1.br_FiredBy == ent2) then return true end return false end @@ -316,10 +314,35 @@ hook.Add("ShouldCollide", "NoPlayerCollisions", function(ent1, ent2) if ent2:IsPlayer() and ent1:IsNPC() then return true end end) +local function calc_fov(src, dst) + local v_src = src:Forward() + local v_dst = dst:Forward() + + local result = math.deg(math.acos(v_dst:Dot(v_src) / v_dst:Length())) + + if result != result or (result == math.huge or result == -math.huge) then + result = 0 + end + + return result +end + // i was forced -hook.Add("EntityFireBullets", "thisengineismadebyacrackhead", function(ent, data) +hook.Add("EntityFireBullets", "thisengineismadebyacrackhead", function(ent, data) + if not IsValid(ent) or not isfunction(ent.GetShootPos) or not ent:IsPlayer() then return end + + for i, ply in ipairs(player.GetAll()) do + if ply == ent then continue end + local fov = calc_fov(data.Dir:Angle(), (ply:GetShootPos() - data.Src):Angle()) + print(fov) + if fov > 60 then continue end + + ply.br_FiredBy = ent + timer.Simple(engine.TickInterval()*3, function() if IsValid(ply) then ply.br_FiredBy = nil end end) + end + ent.br_Fired = true - timer.Simple(engine.TickInterval()*2, function() if IsValid(ent) then ent.br_Fired = false end end) + timer.Simple(engine.TickInterval()*3, function() if IsValid(ent) then ent.br_Fired = false end end) end) hook.Add("PhysgunPickup", "AllowPlayerPickup", function(ply, ent)