Skip to content

Commit 8c8759e

Browse files
committed
new lock part modes (aim)
SetEyeang sets your eyeang to lock's world angle AimToPos sets eyeang to point from eyeang to lock's world pos and some small revisions for uniformity related to use of cached cvars
1 parent 78f5491 commit 8c8759e

File tree

4 files changed

+60
-12
lines changed

4 files changed

+60
-12
lines changed

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

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ local convar_lock = GetConVar("pac_sv_lock")
2222
local convar_lock_grab = GetConVar("pac_sv_lock_grab")
2323
local convar_lock_max_grab_radius = GetConVar("pac_sv_lock_max_grab_radius")
2424
local convar_lock_teleport = GetConVar("pac_sv_lock_teleport")
25+
local convar_lock_aim = GetConVar("pac_sv_lock_aim")
2526
local convar_combat_enforce_netrate = GetConVar("pac_sv_combat_enforce_netrate_monitor_serverside")
2627

2728
--sorcerous hack fix
2829
if convar_lock == nil then timer.Simple(10, function() convar_lock = GetConVar("pac_sv_lock") end) end
2930
if convar_lock_grab == nil then timer.Simple(10, function() convar_lock_grab = GetConVar("pac_sv_lock_grab") end) end
3031
if convar_lock_teleport == nil then timer.Simple(10, function() convar_lock_teleport = GetConVar("pac_sv_lock_teleport") end) end
32+
if convar_lock_aim == nil then timer.Simple(10, function() convar_lock_aim = GetConVar("pac_sv_lock_aim") end) end
3133
if convar_lock_max_grab_radius == nil then timer.Simple(10, function() convar_lock_max_grab_radius = GetConVar("pac_sv_lock_max_grab_radius") end) end
3234
if convar_combat_enforce_netrate == nil then timer.Simple(10, function() convar_combat_enforce_netrate = GetConVar("pac_sv_combat_enforce_netrate_monitor_serverside") end) end
3335

@@ -41,7 +43,13 @@ PART.Icon = "icon16/lock.png"
4143

4244
BUILDER:StartStorableVars()
4345
:SetPropertyGroup("Behaviour")
44-
:GetSet("Mode", "None", {enums = {["None"] = "None", ["Grab"] = "Grab", ["Teleport"] = "Teleport"}})
46+
:GetSet("Mode", "None", {enums = {
47+
["None"] = "None",
48+
["Grab"] = "Grab",
49+
["Teleport"] = "Teleport",
50+
["SetEyeang"] = "SetEyeang",
51+
["AimToPos"] = "AimToPos"
52+
}})
4553
:GetSet("OverrideAngles", true, {description = "Whether the part will rotate the entity alongside it, otherwise it changes just the position"})
4654
:GetSet("RelativeGrab", false)
4755
:GetSet("RestoreDelay", 1, {description = "Seconds until the entity's original angles before self.grabbing are re-applied"})
@@ -54,6 +62,11 @@ BUILDER:StartStorableVars()
5462
:GetSet("ContinuousSearch", false, {description = "Will search for entities until one is found. Otherwise only try once when part is shown."})
5563
:GetSet("Preview", false)
5664

65+
:SetPropertyGroup("AimMode")
66+
:GetSet("AffectPitch", true)
67+
:GetSet("AffectYaw", true)
68+
:GetSet("ContinuousAim", true)
69+
5770
:SetPropertyGroup("TeleportSafety")
5871
:GetSet("ClampDistance", false, {description = "Prevents the teleport from going too far (By Radius amount). For example, if you use hitpos bone on a pac model, it can act as a safety in case the raycast falls out of bounds."})
5972
:GetSet("SlopeSafety", false, {description = "Teleports a bit up in case you end up on a slope and get stuck."})
@@ -73,6 +86,28 @@ BUILDER:StartStorableVars()
7386

7487
BUILDER:EndStorableVars()
7588

89+
local function set_eyeang(ply, self)
90+
if ply ~= pac.LocalPlayer or self:GetPlayerOwner() ~= ply then return end
91+
if not convar_lock_aim:GetBool() then
92+
self:SetWarning("lock part aiming is disabled on this server!")
93+
return
94+
end
95+
local plyang = ply:EyeAngles()
96+
local pos, ang = self:GetDrawPosition()
97+
98+
if self.Mode == "SetEyeang" then
99+
ang.r = 0
100+
if not self.AffectPitch then ang.p = plyang.p end
101+
if not self.AffectYaw then ang.y = plyang.y end
102+
ply:SetEyeAngles(ang)
103+
elseif self.Mode == "AimToPos" then
104+
local ang = (pos - ply:EyePos()):Angle()
105+
if not self.AffectPitch then ang.p = plyang.p end
106+
if not self.AffectYaw then ang.y = plyang.y end
107+
ply:SetEyeAngles(ang)
108+
end
109+
end
110+
76111
function PART:OnThink()
77112
if not convar_lock:GetBool() then return end
78113
if util.NetworkStringToID("pac_request_position_override_on_entity_grab") == 0 then self:SetError("This part is deactivated on the server") return end
@@ -216,6 +251,12 @@ function PART:OnThink()
216251
self.grabbing = true
217252
self.teleported = false
218253
end
254+
elseif self.Mode == "SetEyeang" then
255+
if not self.ContinuousAim then return end
256+
set_eyeang(self:GetPlayerOwner(), self)
257+
elseif self.Mode == "AimToPos" then
258+
if not self.ContinuousAim then return end
259+
set_eyeang(self:GetPlayerOwner(), self)
219260
end
220261
--if self.is_first_time then print("lock " .. self.UniqueID .. "did its first clock") end
221262
self.is_first_time = false
@@ -326,7 +367,7 @@ function PART:OnShow()
326367
origin_part = self
327368
end
328369
if origin_part == nil or not self.Preview or pac.LocalPlayer ~= self:GetPlayerOwner() then return end
329-
local sv_dist = GetConVar("pac_sv_lock_max_grab_radius"):GetInt()
370+
local sv_dist = convar_lock_max_grab_radius:GetInt()
330371

331372
render.DrawLine(origin_part:GetWorldPosition(),origin_part:GetWorldPosition() + Vector(0,0,-self.OffsetDownAmount),Color(255,255,255))
332373

@@ -342,7 +383,7 @@ function PART:OnShow()
342383

343384
end)
344385
if self.Mode == "Teleport" then
345-
if not GetConVar('pac_sv_lock_teleport'):GetBool() or pac.Blocked_Combat_Parts[self.ClassName] then return end
386+
if not convar_lock_teleport:GetBool() or pac.Blocked_Combat_Parts[self.ClassName] then return end
346387
if pace.still_loading_wearing then return end
347388
self.target_ent = nil
348389

@@ -363,7 +404,7 @@ function PART:OnShow()
363404
end
364405
end
365406
if self.SlopeSafety then teleport_pos_final = teleport_pos_final + Vector(0,0,30) end
366-
if not GetConVar("pac_sv_combat_enforce_netrate_monitor_serverside"):GetBool() then
407+
if not convar_combat_enforce_netrate:GetBool() then
367408
if not pac.CountNetMessage() then self:SetInfo("Went beyond the allowance") return end
368409
end
369410
timer.Simple(0, function()
@@ -381,14 +422,18 @@ function PART:OnShow()
381422
elseif self.Mode == "Grab" then
382423
self:DecideTarget()
383424
self:CheckEntValidity()
425+
elseif self.Mode == "SetEyeang" then
426+
set_eyeang(self:GetPlayerOwner(), self)
427+
elseif self.Mode == "AimToPos" then
428+
set_eyeang(self:GetPlayerOwner(), self)
384429
end
385430
end
386431

387432
function PART:OnHide()
388433
pac.RemoveHook("PostDrawOpaqueRenderables", "pace_draw_lockpart_preview"..self.UniqueID)
389434
self.teleported = false
390435
self.grabbing = false
391-
if not IsValid(self.target_ent) then return
436+
if self.target_ent == nil then return
392437
else self.target_ent.IsGrabbed = false self.target_ent.IsGrabbedByUID = nil end
393438
if util.NetworkStringToID( "pac_request_position_override_on_entity_grab" ) == 0 then self:SetError("This part is deactivated on the server") return end
394439
self:reset_ent_ang()
@@ -401,7 +446,7 @@ function PART:reset_ent_ang()
401446
if reset_ent:IsValid() then
402447
timer.Simple(math.min(self.RestoreDelay,5), function()
403448
if pac.LocalPlayer == self:GetPlayerOwner() then
404-
if not GetConVar("pac_sv_combat_enforce_netrate_monitor_serverside"):GetBool() then
449+
if not convar_combat_enforce_netrate:GetBool() then
405450
if not pac.CountNetMessage() then self:SetInfo("Went beyond the allowance") return end
406451
end
407452
net.Start("pac_request_angle_reset_on_entity")
@@ -521,21 +566,21 @@ end
521566

522567
function PART:Initialize()
523568
self.default_ang = Angle(0,0,0)
524-
if not GetConVar('pac_sv_lock_grab'):GetBool() then
525-
if not GetConVar('pac_sv_lock_teleport'):GetBool() then
569+
if not convar_lock_grab:GetBool() then
570+
if not convar_lock_teleport:GetBool() then
526571
self:SetWarning("lock part grabs and teleports are disabled on this server!")
527572
else
528573
self:SetWarning("lock part grabs are disabled on this server!")
529574
end
530575
end
531-
if not GetConVar('pac_sv_lock_teleport'):GetBool() then
532-
if not GetConVar('pac_sv_lock_grab'):GetBool() then
576+
if not convar_lock_teleport:GetBool() then
577+
if not convar_lock_grab:GetBool() then
533578
self:SetWarning("lock part grabs and teleports are disabled on this server!")
534579
else
535580
self:SetWarning("lock part teleports are disabled on this server!")
536581
end
537582
end
538-
if not GetConVar('pac_sv_lock'):GetBool() then self:SetError("lock parts are disabled on this server!") end
583+
if not convar_lock:GetBool() then self:SetError("lock parts are disabled on this server!") end
539584
end
540585

541586

lua/pac3/editor/client/settings.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ local convar_params_lock = {
2121
{"pac_sv_lock", "Allow lock part", "", -1, 0, 200},
2222
{"pac_sv_lock_teleport", "Allow lock part teleportation", "", -1, 0, 200},
2323
{"pac_sv_lock_grab", "Allow lock part grabbing", "", -1, 0, 200},
24+
{"pac_sv_lock_aim", "Allow lock part aiming", "", -1, 0, 200},
2425
{"pac_sv_lock_allow_grab_ply", "Allow grabbing players", "", -1, 0, 200},
2526
{"pac_sv_lock_allow_grab_npc", "Allow grabbing NPCs", "", -1, 0, 200},
2627
{"pac_sv_lock_allow_grab_ent", "Allow grabbing other entities", "", -1, 0, 200},

lua/pac3/editor/client/spawnmenu.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ function pace.AdminSettingsMenu(self)
192192
self:CheckBox(L"Enable lock part", "pac_sv_lock")
193193
self:CheckBox(L"Allow grab", "pac_sv_lock_grab")
194194
self:CheckBox(L"Allow teleport", "pac_sv_lock_teleport")
195-
195+
self:CheckBox(L"Allow aiming", "pac_sv_lock_aim")
196+
196197
self:Help(L"Force part"):SetFont("DermaDefaultBold")
197198
self:CheckBox(L"Enable force part", "pac_sv_force")
198199
self:NumSlider(L"Max amount", "pac_sv_force_max_amount", 0, 10000000, 0)

lua/pac3/extra/shared/net_combat.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ local damagezone_allow_ragdoll_networking_for_hitpart = CreateConVar("pac_sv_dam
2929
local lock_allow = CreateConVar("pac_sv_lock", master_default, CLIENT and {FCVAR_REPLICATED} or {FCVAR_NOTIFY, FCVAR_ARCHIVE, FCVAR_REPLICATED}, "Allow lock parts serverside")
3030
local lock_allow_grab = CreateConVar("pac_sv_lock_grab", 1, CLIENT and {FCVAR_REPLICATED} or {FCVAR_NOTIFY, FCVAR_ARCHIVE, FCVAR_REPLICATED}, "Allow lock part grabs serverside")
3131
local lock_allow_teleport = CreateConVar("pac_sv_lock_teleport", 1, CLIENT and {FCVAR_REPLICATED} or {FCVAR_NOTIFY, FCVAR_ARCHIVE, FCVAR_REPLICATED}, "Allow lock part teleports serverside")
32+
local lock_allow_aim = CreateConVar("pac_sv_lock_aim", 1, CLIENT and {FCVAR_REPLICATED} or {FCVAR_NOTIFY, FCVAR_ARCHIVE, FCVAR_REPLICATED}, "Allow lock part aim serverside")
3233
local lock_max_radius = CreateConVar("pac_sv_lock_max_grab_radius", "200", CLIENT and {FCVAR_REPLICATED} or {FCVAR_NOTIFY, FCVAR_ARCHIVE, FCVAR_REPLICATED}, "lock part maximum grab radius")
3334
local lock_allow_grab_ply = CreateConVar("pac_sv_lock_allow_grab_ply", 1, CLIENT and {FCVAR_REPLICATED} or {FCVAR_NOTIFY, FCVAR_ARCHIVE, FCVAR_REPLICATED}, "allow grabbing players with lock part")
3435
local lock_allow_grab_npc = CreateConVar("pac_sv_lock_allow_grab_npc", 1, CLIENT and {FCVAR_REPLICATED} or {FCVAR_NOTIFY, FCVAR_ARCHIVE, FCVAR_REPLICATED}, "allow grabbing NPCs with lock part")

0 commit comments

Comments
 (0)