TOOL.Category = "Construction" TOOL.Name = "#Remover" TOOL.Command = nil TOOL.ConfigName = nil /*--------------------------------------------------------- Name: LeftClick Desc: Remove a single entity ---------------------------------------------------------*/ function TOOL:LeftClick( trace ) local ent = trace.Entity if ( !ent ) || ( !ent:IsValid() ) || ( ent:IsPlayer() ) then return false end if ( CLIENT ) then return true end // Make a backup of what we're about to delete. self.Redo = { duplicator.Copy( {ent}, constraint.FindConstraints( ent ) ) } ent:NiceRemove() MsgAll( self:GetOwner():Nick(), " removed ", ent:GetClass(), "\n" ) return true end /*--------------------------------------------------------- Name: RightClick Desc: Remove this entity and everything constrained ---------------------------------------------------------*/ function TOOL:RightClick( trace ) local ent = trace.Entity if ( !ent ) || ( !ent:IsValid() ) || ( ent:IsPlayer() ) then return false end if ( CLIENT ) then return true end local ConstrainedEntities, Constraints = constraint.GetAllConstrainedEntitiesAndConstraints( ent ) local Count = {} // Make a backup of what we're about to delete. self.Redo = { duplicator.Copy( ConstrainedEntities, Constraints ) } // Loop through all the entities in the system for _, Ent in pairs( ConstrainedEntities ) do local class = Ent:GetClass() if !Count[ class ] then Count[ class ] = 0 end Count[ class ] = Count[ class ] + 1 Ent:NiceRemove() end // Display count text ( bit complicated but it looks good ) local text = self:GetOwner():Nick().. " removed " local dil = " " if ( table.Count( Count ) > 1 ) then dil = "\n" .. string.rep( " ",text:len() ) //text = text..":" end local concat = {} for class,count in pairs( Count ) do table.insert( concat,count.." "..class ) end MsgAll( text, table.concat( concat, dil ) ) return true end //Redo is here for now until i find a better way of implementing it function TOOL:Reload( trace ) -- if (!trace.Entity || !trace.Entity:IsValid() || trace.Entity:IsPlayer() ) then return false if ( CLIENT ) then return true end local Ents,Cons = duplicator.Paste( self:GetOwner(), unpack( self.Redo ) ) undo.Create("Remover Redo") for _,Ent in pairs( Ents ) do undo.AddEntity( Ent ) end for _,Con in pairs( Cons ) do undo.AddEntity( Con ) end undo.SetPlayer( self:GetOwner() ) undo.Finish() //todo, hold multiple redo levels self.Redo = nil -- constraint.Remove( trace.Entity ) -- return true end