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
28 changes: 26 additions & 2 deletions lua/weapons/gmod_tool/stools/multi_parent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,38 @@ function TOOL:ParentCheck( child, parent )
return true
end

function TOOL:GetParentedEnt(trace)
local ent = trace.Entity

-- Hacky way to hit parented entity
if not ent:IsValid() then
local owner = self:GetOwner()
local trace = util.GetPlayerTrace( owner )

-- Identical to the toolgun code
trace.mask = bit.bor(CONTENTS_SOLID, CONTENTS_MOVEABLE, CONTENTS_MONSTER, CONTENTS_WINDOW, CONTENTS_DEBRIS, CONTENTS_GRATE, CONTENTS_AUX)
trace.mins = vector_origin
trace.maxs = vector_origin
trace.filter = { owner, owner:GetVehicle() }

local parented_ent = util.TraceHull(trace).Entity

if parented_ent:IsValid() and self:IsPropOwner(owner, parented_ent) then
ent = parented_ent
end
end

return ent
end

local function sendNotification( selected, ply )
net.Start( "MultiParent_SendNotification" )
net.WriteUInt( selected, MAX_EDICT_BITS )
net.Send( ply )
end

function TOOL:LeftClick( trace )
local ent = trace.Entity
local ent = self:GetParentedEnt(trace)

if ent:IsValid() and ent:IsPlayer() then return end
if SERVER and not util.IsValidPhysicsObject( ent, trace.PhysicsBone ) then return false end
Expand Down Expand Up @@ -250,7 +274,7 @@ function TOOL:RightClick( trace )
return true
end

local ent = trace.Entity
local ent = self:GetParentedEnt(trace)

if ent:IsValid() and ent:IsPlayer() then return false end
if SERVER and not util.IsValidPhysicsObject( ent, trace.PhysicsBone ) then return false end
Expand Down