Skip to content

Commit c247ce7

Browse files
committed
force part update
split AffectSelf into two to distinguish between player owner and root owner (e.g. projectiles) for backward compatibility, AffectSelf will still act as both by default, but with AlternateAffectSelf the split occurs. you can then use AffectPlayerOwner to affect your player, and AffectSelf to affect the root part owner separately
1 parent fa93cd7 commit c247ce7

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

lua/pac3/core/client/parts/force.lua

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ Radial gets the base directions from the targets to the force part]]})
6767
:GetSet("DampingReverseFalloff", false, {description = "Whether the damping should fade with distance but reverse (closer is weaker influence)"})
6868

6969
:SetPropertyGroup("Targets")
70-
:GetSet("AffectSelf",false)
70+
:GetSet("AffectSelf", false, {description = "Affect Root Owner (i.e. it can be a projectile entity)"})
71+
:GetSet("AlternateAffectSelf", false, {description = "'Affect Self' was split into two. For backward compatibility reasons, this must be a setting.\nif this is off, affect self will affect both player owner and root owner, which may not be desired"})
72+
:GetSet("AffectPlayerOwner", false)
7173
:GetSet("Players",true)
7274
:GetSet("PhysicsProps", true)
7375
:GetSet("PointEntities",true, {description = "other entities not covered by physics props but with potential physics"})
@@ -85,6 +87,9 @@ end
8587
function PART:Initialize()
8688
self.next_impulse = CurTime() + 0.05
8789
if not GetConVar("pac_sv_force"):GetBool() or pac.Blocked_Combat_Parts[self.ClassName] then self:SetError("force parts are disabled on this server!") end
90+
timer.Simple(0, function()
91+
self.initialized = true
92+
end)
8893
end
8994

9095
function PART:OnShow()
@@ -213,9 +218,6 @@ local function ProcessForcesList(ents_hits, tbl, pos, ang, ply)
213218
end
214219
for _,ent in pairs(ents_hits) do
215220
if ent:IsWeapon() or ent:GetClass() == "viewmodel" or ent:GetClass() == "func_physbox_multiplayer" then continue end
216-
if ent:GetPos():Distance(ply:GetPos()) < 300 then
217-
print(ent)
218-
end
219221
local phys_ent
220222
local is_player = ent:IsPlayer()
221223
local is_physics = (physics_point_ent_classes[ent:GetClass()] or string.find(ent:GetClass(),"item_") or string.find(ent:GetClass(),"ammo_") or (ent:IsWeapon() and not IsValid(ent:GetOwner())))
@@ -503,6 +505,8 @@ function PART:Impulse(on)
503505
if not pac.CountNetMessage() then self:SetInfo("Went beyond the allowance") return end
504506
end
505507

508+
if not self.initialized then return end
509+
506510
local locus_pos = Vector(0,0,0)
507511
if self.Locus ~= nil then
508512
if self.Locus:IsValid() then
@@ -518,7 +522,8 @@ function PART:Impulse(on)
518522
end
519523
end
520524

521-
if not self.NPC and not self.Players and not self.AffectSelf and not self.PhysicsProps and not self.PointEntities then return end
525+
if not self.NPC and not self.Players and not self.AffectSelf and not self.AffectPlayerOwner and not self.PhysicsProps and not self.PointEntities then return end
526+
522527
net.Start("pac_request_force", true)
523528
net.WriteVector(self:GetWorldPosition())
524529
net.WriteAngle(self:GetWorldAngles())
@@ -549,7 +554,14 @@ function PART:Impulse(on)
549554
net.WriteBool(self.DampingFalloff)
550555
net.WriteBool(self.DampingReverseFalloff)
551556
net.WriteBool(self.Levitation)
552-
net.WriteBool(self.AffectSelf)
557+
if self.AlternateAffectSelf then
558+
net.WriteBool(self.AffectSelf)
559+
net.WriteBool(self.AffectPlayerOwner)
560+
else
561+
net.WriteBool(self.AffectSelf)
562+
net.WriteBool(self.AffectPlayerOwner or self.AffectSelf)
563+
end
564+
553565
net.WriteBool(self.Players)
554566
net.WriteBool(self.PhysicsProps)
555567
net.WriteBool(self.PointEntities)

lua/pac3/extra/shared/net_combat.lua

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,27 +1316,35 @@ if SERVER then
13161316
if v.CPPICanPickup and not v:CPPICanPickup(ply) then ents_hits[i] = nil end
13171317
if v.CPPICanPunt and not v:CPPICanPunt(ply) then ents_hits[i] = nil end
13181318
if v:IsConstraint() then ents_hits[i] = nil end
1319-
if pre_excluded_ent_classes[v:GetClass()] or (Is_NPC(v) and not tbl.NPC) or (v:IsPlayer() and not tbl.Players and not (v == ply and tbl.AffectSelf)) then ents_hits[i] = nil
1320-
else ent_count = ent_count + 1 end
1319+
1320+
if v == ply then
1321+
if not tbl.AffectPlayerOwner then ents_hits[i] = nil end
1322+
elseif v == tbl.RootPartOwner then
1323+
if (not tbl.AffectSelf) and v == tbl.RootPartOwner then ents_hits[i] = nil end
1324+
end
1325+
1326+
if pre_excluded_ent_classes[v:GetClass()] or (Is_NPC(v) and not tbl.NPC) or (v:IsPlayer() and not tbl.Players and not (v == ply and tbl.AffectPlayerOwner)) then ents_hits[i] = nil
1327+
end
1328+
if ents_hits[i] ~= nil then
1329+
ent_count = ent_count + 1
1330+
end
13211331
end
1322-
if TooManyEnts(ent_count, ply) and not (tbl.AffectSelf and not tbl.Players and not tbl.NPC and not tbl.PhysicsProps and not tbl.PointEntities) then return end
1332+
if TooManyEnts(ent_count, ply) and not ((tbl.AffectSelf or tbl.AffectPlayerOwner) and not tbl.Players and not tbl.NPC and not tbl.PhysicsProps and not tbl.PointEntities) then return end
13231333
for _,ent in pairs(ents_hits) do
13241334
local phys_ent
13251335
local ent_getphysobj = ent:GetPhysicsObject()
13261336
local owner = Try_CPPIGetOwner(ent)
13271337
local is_player = ent:IsPlayer()
13281338
local is_physics = (physics_point_ent_classes[ent:GetClass()] or string.find(ent:GetClass(),"item_") or string.find(ent:GetClass(),"ammo_") or (ent:IsWeapon() and not IsValid(ent:GetOwner())))
13291339
local is_npc = Is_NPC(ent)
1330-
1331-
1332-
if (ent ~= tbl.RootPartOwner or (tbl.AffectSelf and ent == tbl.RootPartOwner))
1340+
if (ent ~= tbl.RootPartOwner or (tbl.AffectSelf and ent == tbl.RootPartOwner) or (tbl.AffectPlayerOwner and ent == ply))
13331341
and (
13341342
is_player
13351343
or is_npc
13361344
or is_physics
13371345
or IsValid( ent_getphysobj )
13381346
) then
1339-
1347+
13401348
local is_phys = true
13411349
if ent_getphysobj ~= nil then
13421350
phys_ent = ent_getphysobj
@@ -1465,8 +1473,8 @@ if SERVER then
14651473
local unconsenting_owner = owner ~= ply and force_consents[owner] == false
14661474

14671475
if is_player then
1468-
if tbl.Players or (ent == ply and tbl.AffectSelf) then
1469-
if (ent ~= ply and force_consents[ent] ~= false) or (ent == ply and tbl.AffectSelf) then
1476+
if tbl.Players or (ent == ply and tbl.AffectPlayerOwner) then
1477+
if (ent ~= ply and force_consents[ent] ~= false) or (ent == ply and tbl.AffectPlayerOwner) then
14701478
oldvel = ent:GetVelocity()
14711479
phys_ent:SetVelocity(oldvel * (-1 + final_damping) + addvel)
14721480
ent:SetVelocity(oldvel * (-1 + final_damping) + addvel)
@@ -1513,7 +1521,7 @@ if SERVER then
15131521
end
15141522
end
15151523

1516-
elseif tbl.PointEntities then
1524+
elseif tbl.PointEntities or (tbl.AffectSelf and ent == tbl.RootPartOwner) then
15171525
if not (IsPropProtected(ent, ply) and global_combat_prop_protection:GetBool()) or not unconsenting_owner then
15181526
phys_ent:SetVelocity(final_damping * oldvel + addvel)
15191527
end
@@ -1757,6 +1765,7 @@ if SERVER then
17571765
tbl.DampingReverseFalloff = net.ReadBool()
17581766
tbl.Levitation = net.ReadBool()
17591767
tbl.AffectSelf = net.ReadBool()
1768+
tbl.AffectPlayerOwner = net.ReadBool()
17601769
tbl.Players = net.ReadBool()
17611770
tbl.PhysicsProps = net.ReadBool()
17621771
tbl.PointEntities = net.ReadBool()

0 commit comments

Comments
 (0)