Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.67 KB | None | 0 0
  1.  
  2. TOOL.Category       = "Constraints"
  3. TOOL.Name           = "Multi-Parent"
  4. TOOL.Command        = nil
  5. TOOL.ConfigName     = ""
  6.  
  7. if ( CLIENT ) then
  8.     language.Add( "Tool_multi_parent_name", "Multi-Parent Tool" )
  9.     language.Add( "Tool_multi_parent_desc", "Parent multiple props to one prop." )
  10.     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." )
  11. end
  12.  
  13. TOOL.enttbl = {}
  14.  
  15. function TOOL:LeftClick( trace )
  16.  
  17.     if (CLIENT) then return true end
  18.     if (trace.Entity:IsValid()) and (trace.Entity:IsPlayer()) then return end
  19.     if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
  20.     if (trace.Entity:IsWorld()) then return false end
  21.    
  22.     local ent = trace.Entity
  23.     if (self:GetOwner():KeyDown(IN_USE)) then
  24.         for k,v in pairs(constraint.GetAllConstrainedEntities(ent)) do
  25.             local eid = v:EntIndex()
  26.             if not (self.enttbl[eid]) then
  27.                 local col = Color(0,0,0,0)
  28.                 col.r,col.g,col.b,col.a = v:GetColor()
  29.                 self.enttbl[eid] = col
  30.                 v:SetColor(0,255,0,100)
  31.             else
  32.                 local col = self.enttbl[eid]
  33.                 v:SetColor(col.r,col.g,col.b,col.a)
  34.                 self.enttbl[eid] = nil
  35.             end
  36.         end
  37.     else
  38.         local eid = ent:EntIndex()
  39.         if not (self.enttbl[eid]) then
  40.             local col = Color(0,0,0,0)
  41.             col.r,col.g,col.b,col.a = ent:GetColor()
  42.             self.enttbl[eid] = col
  43.             ent:SetColor(0,255,0,100)
  44.         else
  45.             local col = self.enttbl[eid]
  46.             ent:SetColor(col.r,col.g,col.b,col.a)
  47.             self.enttbl[eid] = nil
  48.         end
  49.     end
  50.  
  51.    
  52.     return true
  53. end
  54.  
  55. function TOOL:RightClick( trace )
  56.  
  57.     if (CLIENT) then return true end
  58.     if (table.Count(self.enttbl) < 1) then return end
  59.     if (trace.Entity:IsValid()) and (trace.Entity:IsPlayer()) then return end
  60.     if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
  61.     if (trace.Entity:IsWorld()) then return false end
  62.    
  63.     local ent = trace.Entity
  64.     for k,v in pairs(self.enttbl) do
  65.         local prop = ents.GetByIndex(k)
  66.         if (prop:IsValid()) then
  67.             local phys = prop:GetPhysicsObject()
  68.             if phys:IsValid() then
  69.                 constraint.NoCollide(prop,ent,0,0)
  70.                 phys:EnableCollisions(false)
  71.                 phys:EnableMotion(false)
  72.                 phys:Sleep()
  73.                 prop:SetColor(v.r,v.g,v.b,v.a)
  74.                 prop:SetParent(ent)
  75.                 self.enttbl[k] = nil
  76.             end
  77.         end
  78.     end
  79.     self.enttbl = {}
  80.     return true
  81. end
  82.  
  83. function TOOL:Reload()
  84.     if (CLIENT) then return false end
  85.     if (table.Count(self.enttbl) < 1) then return end
  86.     for k,v in pairs(self.enttbl) do
  87.         local prop = ents.GetByIndex(k)
  88.         if (prop:IsValid()) then
  89.             prop:SetColor(v.r,v.g,v.b,v.a)
  90.             self.enttbl[k] = nil
  91.         end
  92.     end
  93.     self.enttbl = {}
  94.     return true
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement