Skip to content

Commit

Permalink
Fix for seat alias collisions, slightly better player hitbox checks
Browse files Browse the repository at this point in the history
Hopefully finally stopped the last of the issues with seat alias collisions??
Also made them massless (or nearly) instead of the model's default 100kg

Also made the player hitbox default to grabbing the nearest hitbox instead of defaulting to "none" so damage is more consistent, and just in case that still failed, boosted default damage a bit against squishies
  • Loading branch information
LiddulBOFH committed Aug 31, 2024
1 parent 3bde914 commit ea65fb2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
43 changes: 37 additions & 6 deletions lua/acf/core/utilities/util_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ end

do -- Special squishy functions
local BoneList = {
head = {boneName = "ValveBiped.Bip01_Head1", group = "head", min = Vector(-6, -6, -4), max = Vector(8, 4, 4)},
head = {boneName = "ValveBiped.Bip01_Head1", group = "head", min = Vector(-6, -6, -6), max = Vector(8, 4, 6)},

chest = {boneName = "ValveBiped.Bip01_Spine", group = "chest", min = Vector(-6, -4, -9), max = Vector(18, 10, 9)},

Expand All @@ -932,7 +932,7 @@ do -- Special squishy functions
}

local ArmorHitboxes = { -- only applied if the entity has armor greater than 0
helmet = {boneName = "ValveBiped.Bip01_Head1", group = "helmet", min = Vector(4.5, -6.5, -4.5), max = Vector(8.5, 4.5, 4.5)},
helmet = {boneName = "ValveBiped.Bip01_Head1", group = "helmet", min = Vector(4.5, -6.5, -6.5), max = Vector(8.5, 4.5, 6.5)},
vest = {boneName = "ValveBiped.Bip01_Spine", group = "vest", min = Vector(-5, -5, -8), max = Vector(17, 11, 8)},
}

Expand Down Expand Up @@ -974,7 +974,7 @@ do -- Special squishy functions
local HitPos = util.IntersectRayWithOBB(LocalRay, LocalRayDir * 64, v.pos, v.ang, v.min, v.max)

--debugoverlay.Text(Alias:LocalToWorld(v.pos),k,10,false)
--debugoverlay.BoxAngles(Alias:LocalToWorld(v.pos),v.min,v.max,Alias:LocalToWorldAngles(v.ang),10,Color(255,0,0,50))
--debugoverlay.BoxAngles(Alias:LocalToWorld(v.pos), v.min, v.max, Alias:LocalToWorldAngles(v.ang), 10, Color(255, 0, 0, 50))

if HitPos ~= nil then
HitBones[k] = HitPos
Expand All @@ -988,13 +988,28 @@ do -- Special squishy functions
local HitPos = util.IntersectRayWithOBB(LocalRay, LocalRayDir * 64, parentBox.pos, parentBox.ang, v.min, v.max)

--debugoverlay.Text(Alias:LocalToWorld(parentBox.pos),k,10,false)
--debugoverlay.BoxAngles(Alias:LocalToWorld(parentBox.pos),v.min,v.max,Alias:LocalToWorldAngles(parentBox.ang),10,Color(0,0,255,50))
--debugoverlay.BoxAngles(Alias:LocalToWorld(parentBox.pos), v.min, v.max, Alias:LocalToWorldAngles(parentBox.ang), 10, Color(0, 0, 255, 50))

if HitPos ~= nil then
HitBones[k] = HitPos
end
end
end

if table.IsEmpty(HitBones) then
local nearest, nearestdist = "none", 16384

for k, v in pairs(AliasInfo.Hitboxes) do
local DistToLine = util.DistanceToLine(LocalRay, LocalRay + LocalRayDir * 64, Alias:LocalToWorld(v.pos))

if DistToLine < nearestdist then
nearest = k
nearestdist = DistToLine
end
end

return CheckList[nearest].group
end
else
for k, v in pairs(Bones) do
local BoneData = CheckList[k]
Expand All @@ -1003,15 +1018,31 @@ do -- Special squishy functions
local HitPos = util.IntersectRayWithOBB(RayStart, RayDir * 64, BonePos, BoneAng, BoneData.min, BoneData.max)

--debugoverlay.Text(BonePos,k,5,false)
--debugoverlay.BoxAngles(BonePos,BoneData.min,BoneData.max,BoneAng,5,Color(255,0,0,50))
--debugoverlay.BoxAngles(BonePos, BoneData.min, BoneData.max, BoneAng, 5, Color(255, 0, 0, 50))

if HitPos ~= nil then
HitBones[k] = HitPos
end
end

if table.IsEmpty(HitBones) then
local nearest, nearestdist = "none", 16384

for k, v in pairs(Bones) do
local BonePos = Entity:GetBonePosition(v)

local DistToLine = util.DistanceToLine(RayStart, RayStart + RayDir * 64, BonePos)

if DistToLine < nearestdist then
nearest = k
nearestdist = DistToLine
end
end

return CheckList[nearest].group
end
end

if table.IsEmpty(HitBones) then return "none" end -- No boxes got hit, so return the default
if table.Count(HitBones) == 1 then return CheckList[next(HitBones)].group end -- Single box got hit, just return that

local BestChoice = next(HitBones)
Expand Down
4 changes: 2 additions & 2 deletions lua/acf/damage/damage_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function Damage.doSquishyDamage(Entity, DmgResult, DmgInfo)
DmgResult:SetThickness(Size * 0.1)

HitRes = DmgResult:Compute()
Damage = HitRes.Damage * 5
Damage = HitRes.Damage * 15
else
-- Using player armor for fake armor works decently, as even if you don't take actual damage, the armor takes 1 point of damage, so it can potentially wear off
-- These funcs are also done on a hierarchy sort of system, so if the helmet is penetrated, then DamageHead is called, same for Vest -> Chest
Expand All @@ -74,7 +74,7 @@ function Damage.doSquishyDamage(Entity, DmgResult, DmgInfo)
DmgResult:SetThickness(Size * 0.1)

HitRes = DmgResult:Compute()
Damage = HitRes.Damage * 5
Damage = HitRes.Damage * 15
end
end

Expand Down
7 changes: 4 additions & 3 deletions lua/entities/acf_seat_alias/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ do -- Spawn functions
Ent:Spawn()

Ent:SetCollisionGroup(COLLISION_GROUP_NONE)
Ent:SetSolidFlags(FSOLID_CUSTOMRAYTEST)
Ent:SetSolidFlags(bit.bor(FSOLID_CUSTOMRAYTEST, FSOLID_NOT_STANDABLE, FSOLID_CUSTOMBOXTEST))

local Ply = Vehicle:GetDriver()
Ent.Driver = Ply
Expand All @@ -65,6 +65,8 @@ do -- Spawn functions
Ent:CPPISetOwner(Ply)
Ent:SetOwner(Ply)

Contraption.SetMass(Ent, 0.0001)

UpdateClient(Vehicle)
end

Expand Down Expand Up @@ -142,8 +144,7 @@ do -- Metamethods

if IsValid(self.Driver) then
local Seat = self.Seat
local Driver = self.Driver
timer.Simple(0, function() if IsValid(Seat) and IsValid(Driver) then ACF.ApplyAlias(Seat, Driver) end end)
timer.Simple(0, function() if IsValid(Seat) and IsValid(Seat:GetDriver()) then ACF.ApplyAlias(Seat, Seat:GetDriver()) end end)
end
end
end
Expand Down

0 comments on commit ea65fb2

Please sign in to comment.