Skip to content

Commit 8969cf9

Browse files
committed
lock part update and fixes
add throw modes semi-revert previous change: add option to ignore pac projectiles from being considered as physics props option to limit the angle reset (if physics, don't reset. if player/npc, reset only roll) for the revert lock state, change the no collide collision type to avoid physics falling through the world, and fix the gravity on physics objects
1 parent 43dd8fb commit 8969cf9

File tree

2 files changed

+114
-4
lines changed

2 files changed

+114
-4
lines changed

lua/pac3/core/client/parts/lock.lua

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,19 @@ BUILDER:StartStorableVars()
5555
:GetSet("OverrideAngles", true, {description = "Whether the part will rotate the entity alongside it, otherwise it changes just the position"})
5656
:GetSet("RelativeGrab", false)
5757
:GetSet("RestoreDelay", 1, {description = "Seconds until the entity's original angles before self.grabbing are re-applied"})
58+
:GetSet("MinimalRestore", false, {description = "Skip the angle reset on physics entities. But for players and NPCs, it'll still have to reset pitch and roll"})
5859
:GetSet("NoCollide", true, {description = "Whether to disable collisions on the entity while grabbed."})
60+
:GetSet("ThrowMode", "None", {description = "send a force impulse when hidden", enums = {
61+
["None"] = "None",
62+
["Local"] = "Local",
63+
["Global"] = "Global",
64+
["DeltaPos"] = "DeltaPos",
65+
["DeltaPosSmooth"] = "DeltaPosSmooth",
66+
["Locus"] = "Locus",
67+
["EyeAngles"] = "EyeAngles",
68+
}})
69+
:GetSetPart("ThrowTargetPart")
70+
:GetSet("ThrowAmount", Vector(0,0,0))
5971

6072
:SetPropertyGroup("DetectionOrigin")
6173
:GetSet("Radius", 20)
@@ -85,6 +97,7 @@ BUILDER:StartStorableVars()
8597
:GetSet("AffectPlayerOwner", false)
8698
:GetSet("Players", false)
8799
:GetSet("PhysicsProps", false)
100+
:GetSet("ExcludeProjectiles", false)
88101
:GetSet("NPC", false)
89102

90103

@@ -125,6 +138,17 @@ function PART:OnThink()
125138
if pac.Blocked_Combat_Parts[self.ClassName] then return end
126139
end
127140

141+
local pos = self:GetWorldPosition()
142+
if self.last_pos then
143+
self.delta_pos = pos - self.last_pos
144+
self.last_pos = pos
145+
146+
self.delta_pos_smooth = (self.delta_pos_smooth + (self.delta_pos - self.delta_pos_smooth) * 10 * FrameTime())
147+
else
148+
self.last_pos = pos
149+
self.delta_pos_smooth = Vector()
150+
end
151+
128152
if self.forcebreak then
129153
if self.next_allowed_grab < CurTime() then --we're able to resume
130154
if self.ContinuousSearch then
@@ -390,6 +414,10 @@ function PART:OnShow()
390414
render.DrawWireframeSphere(origin_part:GetWorldPosition() + Vector(0,0,-self.OffsetDownAmount), self.Radius, 30, 30, Color(100,100,100),true)
391415
end
392416

417+
if self.ThrowMode ~= "" then
418+
local vec_ang, vec = self:GetThrowAngle()
419+
render.DrawLine(self:GetWorldPosition(),self:GetWorldPosition() + vec,Color(255,255,255))
420+
end
393421
end)
394422
if self.Mode == "Teleport" then
395423
if not convar_lock_teleport:GetBool() or pac.Blocked_Combat_Parts[self.ClassName] then return end
@@ -444,6 +472,36 @@ function PART:OnDoubleClickSpecified()
444472
end
445473
end
446474

475+
function PART:GetThrowAngle()
476+
local pos, ang = self:GetDrawPosition()
477+
local vec_ang = Angle()
478+
479+
if self.ThrowMode == "Local" then
480+
vec_ang = ang
481+
elseif self.ThrowMode == "Global" then
482+
return self.ThrowAmount:Angle(), self.ThrowAmount
483+
elseif self.ThrowMode == "Locus" and self.ThrowTargetPart:IsValid() then
484+
ang = (self.ThrowTargetPart:GetWorldPosition() - pos):Angle()
485+
local fwd = ang:Forward()
486+
local right = ang:Right()
487+
local up = ang:Up()
488+
vec_ang = (fwd*self.ThrowAmount.x + right*self.ThrowAmount.y + up*self.ThrowAmount.z):Angle()
489+
elseif self.ThrowMode == "EyeAngles" then
490+
vec_ang = self:GetPlayerOwner():EyeAngles()
491+
elseif self.ThrowMode == "DeltaPos" then
492+
self.delta_pos = self.delta_pos or Vector()
493+
vec_ang = self.delta_pos:Angle()
494+
elseif self.ThrowMode == "DeltaPosSmooth" then
495+
self.delta_pos_smooth = self.delta_pos_smooth or Vector()
496+
vec_ang = self.delta_pos_smooth:Angle()
497+
end
498+
local fwd = vec_ang:Forward()
499+
local right = vec_ang:Right()
500+
local up = vec_ang:Up()
501+
local vec = Vector(fwd*self.ThrowAmount.x + right*self.ThrowAmount.y + up*self.ThrowAmount.z)
502+
return vec_ang, vec
503+
end
504+
447505
function PART:OnHide()
448506
pac.RemoveHook("PostDrawOpaqueRenderables", "pace_draw_lockpart_preview"..self.UniqueID)
449507
self.teleported = false
@@ -452,20 +510,39 @@ function PART:OnHide()
452510
else self.target_ent.IsGrabbed = false self.target_ent.IsGrabbedByUID = nil end
453511
if util.NetworkStringToID( "pac_request_position_override_on_entity_grab" ) == 0 then self:SetError("This part is deactivated on the server") return end
454512
self:reset_ent_ang()
513+
514+
if self.ThrowMode ~= "None" then
515+
timer.Simple(0, function()
516+
local vec_ang, vec = self:GetThrowAngle()
517+
net.Start("pac_request_lock_toss")
518+
net.WriteEntity(self.target_ent)
519+
net.WriteVector(vec)
520+
net.SendToServer()
521+
end)
522+
end
455523
end
456524

457525
function PART:reset_ent_ang()
458526
if self.target_ent == nil then return end
459527
local reset_ent = self.target_ent
460528

461529
if reset_ent:IsValid() then
530+
local ang = Angle(0,0,0)
531+
if self.MinimalRestore then
532+
ang = reset_ent:GetAngles()
533+
if not physics_point_ent_classes[reset_ent:GetClass()] then
534+
ang.r = 0
535+
ang.p = 0
536+
end
537+
end
538+
462539
timer.Simple(math.min(self.RestoreDelay,5), function()
463540
if pac.LocalPlayer == self:GetPlayerOwner() then
464541
if not convar_combat_enforce_netrate:GetBool() then
465542
if not pac.CountNetMessage() then self:SetInfo("Went beyond the allowance") return end
466543
end
467544
net.Start("pac_request_angle_reset_on_entity")
468-
net.WriteAngle(Angle(0,0,0))
545+
net.WriteAngle(ang)
469546
net.WriteFloat(self.RestoreDelay)
470547
net.WriteEntity(reset_ent)
471548
net.WriteEntity(self:GetPlayerOwner())
@@ -521,9 +598,10 @@ function PART:DecideTarget()
521598
table.insert(ents_candidates, ent_candidate)
522599
end
523600
elseif self.PhysicsProps and (ent_candidate ~= self:GetRootPart():GetOwner()) and (physics_point_ent_classes[ent_candidate:GetClass()] or string.find(ent_candidate:GetClass(),"item_") or string.find(ent_candidate:GetClass(),"ammo_")) then
601+
if ent_candidate:GetClass() == "pac_projectile" and self.ExcludeProjectiles then continue end
524602
chosen_ent = ent_candidate
525603
table.insert(ents_candidates, ent_candidate)
526-
elseif self.NPC and (ent_candidate ~= self:GetRootPart():GetOwner()) and (ent_candidate:IsNPC() or ent_candidate:IsNextBot() or ent_candidate.IsDrGEntity or ent_candidate.IsVJBaseSNPC) then
604+
elseif self.NPC and (ent_candidate:IsNPC() or ent_candidate:IsNextBot() or ent_candidate.IsDrGEntity or ent_candidate.IsVJBaseSNPC) then
527605
chosen_ent = ent_candidate
528606
table.insert(ents_candidates, ent_candidate)
529607
end

lua/pac3/extra/shared/net_combat.lua

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,12 +427,13 @@ if SERVER then
427427
if ulx and (ent.frozen or ent.jail) then return end
428428
--the grab imposes MOVETYPE_NONE and no collisions
429429
--reverting the state requires to reset the eyeang roll in case it was modified
430+
local phys = ent:GetPhysicsObject()
430431
if ent:IsPlayer() then
431432
if bool then --apply lock
432433
active_grabbed_ents[ent] = true
433434
if nocollide then
434435
ent:SetMoveType(MOVETYPE_NONE)
435-
ent:SetCollisionGroup(COLLISION_GROUP_IN_VEHICLE)
436+
ent:SetCollisionGroup(COLLISION_GROUP_DEBRIS_TRIGGER)
436437
else
437438
ent:SetMoveType(MOVETYPE_WALK)
438439
ent:SetCollisionGroup(COLLISION_GROUP_NONE)
@@ -461,7 +462,7 @@ if SERVER then
461462
active_grabbed_ents[ent] = true
462463
if nocollide then
463464
ent:SetMoveType(MOVETYPE_NONE)
464-
ent:SetCollisionGroup(COLLISION_GROUP_IN_VEHICLE)
465+
ent:SetCollisionGroup(COLLISION_GROUP_DEBRIS_TRIGGER)
465466
else
466467
ent:SetMoveType(MOVETYPE_STEP)
467468
ent:SetCollisionGroup(COLLISION_GROUP_NONE)
@@ -474,6 +475,20 @@ if SERVER then
474475
ent_ang.r = 0
475476
ent:SetAngles(ent_ang)
476477
end
478+
else
479+
if IsValid(phys) then
480+
phys:EnableGravity(false)
481+
if bool then
482+
if nocollide then
483+
ent:SetCollisionGroup(COLLISION_GROUP_DEBRIS_TRIGGER)
484+
else
485+
ent:SetCollisionGroup(COLLISION_GROUP_NONE)
486+
end
487+
else
488+
ent:SetCollisionGroup(COLLISION_GROUP_NONE)
489+
end
490+
end
491+
if bool then return end
477492
end
478493

479494
if bool == nil then
@@ -490,6 +505,9 @@ if SERVER then
490505
ent:PhysWake()
491506
ent:SetGravity(1)
492507

508+
if IsValid(phys) then
509+
phys:EnableGravity(true)
510+
end
493511
end
494512

495513
local function maximized_ray_mins_maxs(startpos,endpos,padding)
@@ -2135,6 +2153,7 @@ if SERVER then
21352153
util.AddNetworkString("pac_lock_imposecalcview")
21362154
util.AddNetworkString("pac_signal_stop_lock")
21372155
util.AddNetworkString("pac_request_lock_break")
2156+
util.AddNetworkString("pac_request_lock_toss")
21382157
util.AddNetworkString("pac_mark_grabbed_ent")
21392158
util.AddNetworkString("pac_notify_grabbed_player")
21402159
--The lock part grab request net message
@@ -2404,6 +2423,19 @@ if SERVER then
24042423

24052424
end)
24062425

2426+
net.Receive("pac_request_lock_toss", function(len, ply)
2427+
local ent = net.ReadEntity()
2428+
local vec = net.ReadVector()
2429+
local phys_ent = ent:GetPhysicsObject()
2430+
if Is_NPC(ent) then
2431+
phys_ent = ent
2432+
end
2433+
if ent:IsPlayer() then
2434+
phys_ent:SetVelocity(-phys_ent:GetVelocity())
2435+
end
2436+
phys_ent:SetVelocity(vec)
2437+
end)
2438+
24072439

24082440
hook.Add("Tick", "pac_checklocks", function()
24092441
if nextchecklock > CurTime() then return else nextchecklock = CurTime() + 0.2 end

0 commit comments

Comments
 (0)