Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 43 additions & 5 deletions lua/pac3/core/client/parts/event.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1179,12 +1179,17 @@ PART.OldEvents = {
ranger = {
operator_type = "number", preferred_operator = "below",
tutorial_explanation = "ranger looks in a line to see if something is in front (red arrow) of its host's (parent) model;\ndetected things could be found before(below) or beyond(above) the distance defined in compare;\nthe event will only look as far as the distance defined in distance",
arguments = {{distance = "number"}, {compare = "number"}, {npcs_and_players_only = "boolean"}},
arguments = {{distance = "number"}, {compare = "number"}, {npcs_and_players_only = "boolean"}, {ignore_you = "boolean"}, {ignore_viewer = "boolean"}, {ignore_players = "boolean"}, {ignore_npcs = "boolean"}},
userdata = {
{default = 15, editor_panel = "ranger", ranger_property = "distance"},
{default = 5, editor_panel = "ranger", ranger_property = "compare"}
{default = 5, editor_panel = "ranger", ranger_property = "compare"},
{default = false},
{default = false},
{default = false},
{default = false},
{default = false},
},
callback = function(self, ent, distance, compare, npcs_and_players_only)
callback = function(self, ent, distance, compare, npcs_and_players_only, ignore_you, ignore_viewer, ignore_players, ignore_npcs)

local parent = self:GetParentEx()

Expand All @@ -1193,13 +1198,46 @@ PART.OldEvents = {
distance = distance or 1
compare = compare or 0

local filter = ent

if ignore_npcs then
local ownerPly = self:GetPlayerOwner() -- Has to traverse root, slow.
local localPly = LocalPlayer()

-- NPCs need a function filter since there isn't a clean and *performant* way to get all of them into a table.
filter = function(e)
if e == ent then return false end
if e:IsNPC() or e:IsNextBot() then return false end
if ignore_you and e == ownerPly then return false end
if ignore_viewer and e == localPly then return false end
if ignore_players and e:IsPlayer() then return false end

return true
end
elseif ignore_you or ignore_viewer or ignore_players then
-- Make a table for other ignores, more performant than a function.
filter = {ent}

if ignore_players then
table.Add(filter, player.GetAll())
else -- Other options are redundant if ignoring players.
if ignore_you then
table.insert(filter, self:GetPlayerOwner())
end

if ignore_viewer then
table.insert(filter, LocalPlayer())
end
end
end

local res = util.TraceLine({
start = parent:GetWorldPosition(),
endpos = parent:GetWorldPosition() + parent:GetWorldAngles():Forward() * distance,
filter = ent,
filter = filter,
})

if npcs_and_players_only and (not res.Entity:IsPlayer() and not res.Entity:IsNPC()) then
if npcs_and_players_only and (not res.Entity:IsPlayer() and not res.Entity:IsNPC() and not res.Entity:IsNextBot()) then
return false
end

Expand Down