Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TOOL.Category = "Constraints"
- TOOL.Name = "Multi-Parent"
- TOOL.Command = nil
- TOOL.ConfigName = ""
- if ( CLIENT ) then
- language.Add( "Tool_multi_parent_name", "Multi-Parent Tool" )
- language.Add( "Tool_multi_parent_desc", "Parent multiple props to one prop." )
- language.Add( "Tool_multi_parent_0", "Primary: Select a prop to Parent. (Use to select all) Secondary: Parent all selected props to prop. Reload: Clear Targets." )
- end
- TOOL.enttbl = {}
- function TOOL:LeftClick( trace )
- if (CLIENT) then return true end
- if (trace.Entity:IsValid()) and (trace.Entity:IsPlayer()) then return end
- if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
- if (trace.Entity:IsWorld()) then return false end
- local ent = trace.Entity
- if (self:GetOwner():KeyDown(IN_USE)) then
- for k,v in pairs(constraint.GetAllConstrainedEntities(ent)) do
- local eid = v:EntIndex()
- if not (self.enttbl[eid]) then
- local col = Color(0,0,0,0)
- col.r,col.g,col.b,col.a = v:GetColor()
- self.enttbl[eid] = col
- v:SetColor(0,255,0,100)
- else
- local col = self.enttbl[eid]
- v:SetColor(col.r,col.g,col.b,col.a)
- self.enttbl[eid] = nil
- end
- end
- else
- local eid = ent:EntIndex()
- if not (self.enttbl[eid]) then
- local col = Color(0,0,0,0)
- col.r,col.g,col.b,col.a = ent:GetColor()
- self.enttbl[eid] = col
- ent:SetColor(0,255,0,100)
- else
- local col = self.enttbl[eid]
- ent:SetColor(col.r,col.g,col.b,col.a)
- self.enttbl[eid] = nil
- end
- end
- return true
- end
- function TOOL:RightClick( trace )
- if (CLIENT) then return true end
- if (table.Count(self.enttbl) < 1) then return end
- if (trace.Entity:IsValid()) and (trace.Entity:IsPlayer()) then return end
- if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
- if (trace.Entity:IsWorld()) then return false end
- local ent = trace.Entity
- for k,v in pairs(self.enttbl) do
- local prop = ents.GetByIndex(k)
- if (prop:IsValid()) then
- local phys = prop:GetPhysicsObject()
- if phys:IsValid() then
- constraint.NoCollide(prop,ent,0,0)
- phys:EnableCollisions(false)
- phys:EnableMotion(false)
- phys:Sleep()
- prop:SetColor(v.r,v.g,v.b,v.a)
- prop:SetParent(ent)
- self.enttbl[k] = nil
- end
- end
- end
- self.enttbl = {}
- return true
- end
- function TOOL:Reload()
- if (CLIENT) then return false end
- if (table.Count(self.enttbl) < 1) then return end
- for k,v in pairs(self.enttbl) do
- local prop = ents.GetByIndex(k)
- if (prop:IsValid()) then
- prop:SetColor(v.r,v.g,v.b,v.a)
- self.enttbl[k] = nil
- end
- end
- self.enttbl = {}
- return true
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement