diff --git a/Game.Server/BaseEntity.cs b/Game.Server/BaseEntity.cs index 3f04bb11..956dca97 100644 --- a/Game.Server/BaseEntity.cs +++ b/Game.Server/BaseEntity.cs @@ -1261,9 +1261,21 @@ public void SetParent(BaseEntity? parentEntity, int attachment = -1) { if (attachment == -1) attachment = ParentAttachment; + if (!IsPlayer() && Game.Client.GarrysMod.GarrysMod.IsSacredEntity(Classname ?? "")) { + Warning($"Refusing to set parent on {Classname}!\n"); + return; + } + + for (BaseEntity? ancestor = parentEntity; ancestor != null; ancestor = ancestor.GetParent()) { + if (ancestor.GetParent() == this) + ancestor.SetParent(null); + } + bool wasNotParented = GetParent() == null; BaseEntity? oldParent = GetParent(); + UnlinkFromParent(this); + Parent.Set(parentEntity); if (parentEntity == this) {