/// <summary> /// Remember, this is only for server-side. /// </summary> public static void ChangeOwnershipSmart(this IMyCubeGrid Grid, long NewOwnerID, MyOwnershipShareModeEnum ShareMode) { if (!MyAPIGateway.Session.IsServer) { return; } try { var Subgrids = Grid.GetAllSubgrids(); Grid.ChangeGridOwnership(NewOwnerID, ShareMode); foreach (IMyCubeGrid Subgrid in Subgrids) { try { Subgrid.ChangeGridOwnership(NewOwnerID, ShareMode); } catch (Exception Scrap) { Grid.LogError("ChangeOwnershipSmart.ChangeSubgridOwnership", Scrap); } } } catch (Exception Scrap) { Grid.LogError("ChangeOwnershipSmart", Scrap); } }
public static void DeleteSmart(this IMyCubeGrid Grid) { if (!MyAPIGateway.Session.IsServer) { return; } List <IMyCubeGrid> Subgrids = Grid.GetAllSubgrids(); foreach (IMyCubeGrid Subgrid in Subgrids) { Subgrid.Close(); } Grid.Close(); }
/// <summary> /// Remember, this is only for server-side. /// </summary> public static void ChangeOwnershipSmart(this IMyCubeGrid Grid, long newOwnerId, MyOwnershipShareModeEnum shareMode) { if (!MyAPIGateway.Session.IsServer) { return; } try { List <IMyCubeGrid> subgrids = Grid.GetAllSubgrids(); Grid.ChangeGridOwnership(newOwnerId, shareMode); foreach (IMyCubeGrid subgrid in subgrids) { try { subgrid.ChangeGridOwnership(newOwnerId, shareMode); try { foreach (IMyProgrammableBlock pb in subgrid.GetTerminalSystem().GetBlocksOfType <IMyProgrammableBlock>()) { try { //if (!string.IsNullOrEmpty(pb.ProgramData)) continue; //ShowIngameMessage.ShowOverrideMessage($"PB's recompiling... {subgrid.CustomName}"); pb.Recompile(); } catch (Exception) { //ShowIngameMessage.ShowOverrideMessage($"Recompiling this pb threw and error: {e.TargetSite} {e} "); // MyAPIGateway.Utilities.InvokeOnGameThread(() => { pb.Recompile(); }); } } } catch (Exception) { //ShowIngameMessage.ShowOverrideMessage($"PB's recompile threw: {e} "); } } catch (Exception scrap) { Grid.LogError("ChangeOwnershipSmart.ChangeSubgridOwnership", scrap); } } } catch (Exception scrap) { Grid.LogError("ChangeOwnershipSmart", scrap); } }