Skip to content

Commit

Permalink
more fixes (and attempts)
Browse files Browse the repository at this point in the history
- added a limit of visclips to pass per bullet in one tick. This means, the amount of visclips a bullet must pass after multiple checks while inside of the loop. The counter resets once out of visclips zones, case when the bullet no longer detects visclips during the loop.
- added ITPSV tank into preloads. Credits goes to Chiyo.
- better struct for the debris code. Trying if that can stop arbitrary lua errors.
- Added check for gun parent existent on ACF_CreateBullet()
  • Loading branch information
MartyX5555 committed Oct 21, 2023
1 parent 473336a commit bd37599
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 54 deletions.
32 changes: 15 additions & 17 deletions lua/acf/server/sv_acfballistics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@ function ACF_CreateBullet( BulletData )
BulletData.FuseLength = type(BulletData.FuseLength) == "number" and BulletData.FuseLength or 0

--Check the Gun's velocity and add a modifier to the flighttime so the traceback system doesn't hit the originating contraption if it's moving along the shell path
if IsValid(BulletData.Gun) then
local Parent = ACF_GetPhysicalParent(BulletData.Gun)

local Gun = BulletData.Gun
local physobj = ACF_GetPhysicalParent(Gun):GetPhysicsObject()

if IsValid(physobj) then
BulletData.TraceBackComp = math.max(physobj:GetVelocity():Dot(BulletData.Flight:GetNormalized()),0)
if IsValid(Parent) then
local physObj = Parent:GetPhysicsObject()
if IsValid(physObj) then
BulletData.TraceBackComp = math.max(physObj:GetVelocity():Dot(BulletData.Flight:GetNormalized()),0)
end

end

if BulletData.Filter then
Expand Down Expand Up @@ -176,6 +174,8 @@ end
]]--------------------------------------------------------------------------------------------------
do

local MaxvisclipPerBullet = 50

local function ACF_PerformTrace( Bullet )

-- perform the trace for damage
Expand All @@ -188,7 +188,7 @@ do
debugoverlay.Cross( FlightTr.start, 10, 20, Color(255,0,0), true )
debugoverlay.Cross( FlightTr.endpos, 10, 20, Color(0,255,0), true )

-- Disabled since for some reason, MASK_SHOT caused issues with bullets bypassing things should not (parented props if the tracehull had mins/maxs at 0,0,0). WHY??
-- Disabled since, for some reason, MASK_SHOT caused issues with bullets bypassing things should not (parented props if the tracehull had mins/maxs at 0,0,0). WHY??
--FlightTr.mask = Bullet.Caliber <= 3 and MASK_SHOT or MASK_SOLID -- cals 30mm and smaller will pass through things like chain link fences

--FlightTr.mask = MASK_SHOT -- Enable this to see the weird side
Expand All @@ -206,21 +206,14 @@ do

FlightTr.filter = Bullet.Filter -- any changes to bullet filter will be reflected in the trace

local Iteration = 0
local visCount = 0

--if trace hits clipped part of prop, add prop to trace filter and retry
while RetryTrace do
while RetryTrace and visCount < MaxvisclipPerBullet do

-- Disables so we dont overloop it again
RetryTrace = false

-- i temporally added this, because i crash this very often when testing.
Iteration = Iteration + 1
if Iteration > 100 then
print("FATAL ERROR")
break
end

-- Defining tracehull at first instance. If you want serious cases, change this to traceline
util.TraceHull(FlightTr)
--util.TraceLine(FlightTr)
Expand Down Expand Up @@ -266,7 +259,12 @@ do
end
end

-- Counts the amount of passed visclips during this tick. The loop will break if the limit is passed
visCount = visCount + 1

end

print("Count: " .. visCount)
end

do
Expand Down
89 changes: 52 additions & 37 deletions lua/acf/server/sv_acfdamage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -910,73 +910,79 @@ local function ACF_KillChildProps( Entity, BlastPos, Energy )
end
end


-- Creates a debris related to explosive destruction.
function ACF_HEKill( Entity , HitVector , Energy , BlastPos )

-- if it hasn't been processed yet, check for children
if not Entity.ACF_Killed then ACF_KillChildProps( Entity, BlastPos or Entity:GetPos(), Energy ) end

do

--ERA props should not create debris
local Mat = (Entity.ACF and Entity.ACF.Material) or "RHA"
local MatData = ACE_GetMaterialData( Mat )
if MatData.IsExplosive then return end

end

constraint.RemoveAll( Entity )
Entity:Remove()

if Entity:BoundingRadius() < ACF.DebrisScale then return nil end

-- Create a debris
local Debris = ents.Create( "ace_debris" )
Debris:SetModel( Entity:GetModel() )
Debris:SetAngles( Entity:GetAngles() )
Debris:SetPos( Entity:GetPos() )
Debris:SetMaterial("models/props_wasteland/metal_tram001a")
Debris:Spawn()
if IsValid(Debris) then

if math.random() < ACF.DebrisIgniteChance then Debris:Ignite(math.Rand(5,45),0) end

Debris:Activate()
Debris:SetModel( Entity:GetModel() )
Debris:SetAngles( Entity:GetAngles() )
Debris:SetPos( Entity:GetPos() )
Debris:SetMaterial("models/props_wasteland/metal_tram001a")
Debris:Spawn()
Debris:Activate()

-- Applies force to this debris
local phys = Debris:GetPhysicsObject()
local physent = Entity:GetPhysicsObject()
if math.random() < ACF.DebrisIgniteChance then
Debris:Ignite(math.Rand(5,45),0)
end

if phys:IsValid() and physent:IsValid() then
-- Applies force to this debris
local phys = Debris:GetPhysicsObject()
local physent = Entity:GetPhysicsObject()
local Parent = ACF_GetPhysicalParent( Entity )

phys:SetDragCoefficient( -50 )
phys:SetMass( physent:GetMass() )
phys:SetVelocity( ACF_GetPhysicalParent( Entity ):GetVelocity() )
phys:ApplyForceOffset( HitVector:GetNormalized() * Energy * 2, Debris:WorldSpaceCenter() + VectorRand() * 10 )
if IsValid(phys) and IsValid(physent) then
phys:SetDragCoefficient( -50 )
phys:SetMass( physent:GetMass() )
phys:SetVelocity( Parent:GetVelocity() )
phys:ApplyForceOffset( HitVector:GetNormalized() * Energy * 2, Debris:WorldSpaceCenter() + VectorRand() * 10 )

if IsValid(Parent) then
phys:SetVelocity(Parent:GetVelocity() )
end
end
end

-- Remove the entity
constraint.RemoveAll( Entity )
Entity:Remove()

return Debris
end

-- Creates a debris related to kinetic destruction.
function ACF_APKill( Entity , HitVector , Power )

-- kill the children of this ent, instead of disappearing them from removing parent
ACF_KillChildProps( Entity, Entity:GetPos(), Power )

do

--ERA props should not create debris
local Mat = (Entity.ACF and Entity.ACF.Material) or "RHA"
local MatData = ACE_GetMaterialData( Mat )
if MatData.IsExplosive then return end

end

constraint.RemoveAll( Entity )
Entity:Remove()

if Entity:BoundingRadius() < ACF.DebrisScale then return nil end

-- Create a debris
local Debris = ents.Create( "ace_debris" )
if IsValid(Debris) then

Debris:SetModel( Entity:GetModel() )
Debris:SetAngles( Entity:GetAngles() )
Debris:SetPos( Entity:GetPos() )
Expand All @@ -985,18 +991,27 @@ function ACF_APKill( Entity , HitVector , Power )
Debris:Spawn()
Debris:Activate()

--Applies force to this debris
local phys = Debris:GetPhysicsObject()
local physent = Entity:GetPhysicsObject()
--Applies force to this debris
local phys = Debris:GetPhysicsObject()
local physent = Entity:GetPhysicsObject()
local Parent = ACF_GetPhysicalParent( Entity )

if phys:IsValid() and physent:IsValid() then
phys:SetDragCoefficient( -50 )
phys:SetMass( physent:GetMass() )
phys:SetVelocity( ACF_GetPhysicalParent( Entity ):GetVelocity() )
phys:ApplyForceOffset( HitVector:GetNormalized() * Power * 100, Debris:WorldSpaceCenter() + VectorRand() * 10 )
if IsValid(phys) and IsValid(physent) then
phys:SetDragCoefficient( -50 )
phys:SetMass( physent:GetMass() )
phys:SetVelocity(Parent:GetVelocity() )
phys:ApplyForceOffset( HitVector:GetNormalized() * Power * 100, Debris:WorldSpaceCenter() + VectorRand() * 10 )

if IsValid(Parent) then
phys:SetVelocity( Parent:GetVelocity() )
end
end
end

-- Remove the entity
constraint.RemoveAll( Entity )
Entity:Remove()

return Debris
end

Expand All @@ -1017,7 +1032,7 @@ do
local MaxHE = ACF.ScaledHEMax -- Max amount of HE to be cached. This is useful when we dont want nukes being created by large amounts of clipped ammo.

local Inflictor = ent.Inflictor or nil
local Owner = CPPI and ent:CPPIGetOwner() or NULL
local Owner = ent:CPPIGetOwner() or NULL

if ent:GetClass() == "acf_fueltank" then

Expand Down Expand Up @@ -1060,7 +1075,7 @@ do

if not Found.Exploding then

local EOwner = CPPI and Found:CPPIGetOwner() or NULL
local EOwner = Found:CPPIGetOwner() or NULL

--Don't detonate explosives which we are not allowed to.
if Owner ~= EOwner then continue end
Expand Down
Binary file added scripts/vehicles/acedupe_tanks_itpsv 90.txt
Binary file not shown.

0 comments on commit bd37599

Please sign in to comment.