Advertisement
midspace

SE Build blocker

Sep 29th, 2014
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.63 KB | None | 0 0
  1. namespace midspace
  2. {
  3.     using Sandbox.Common;
  4.     using Sandbox.Common.Components;
  5.     using Sandbox.Common.ObjectBuilders;
  6.     using Sandbox.ModAPI;
  7.     using VRage.Components;
  8.     using VRage.ModAPI;
  9.     using VRage.ObjectBuilders;
  10.     using VRageMath;
  11.  
  12.     /// <summary>
  13.     /// This will prevent anyone from building anything.
  14.     /// Tested in creative and survival mode.
  15.     /// Tested in single player and dedicated server.
  16.     ///
  17.     /// Only issue is, sometimes the build block appears for a moment when switching between nothing and a build block.
  18.     /// Have not been able to build/destroy anything during that small moment, so it seems stable.
  19.     ///
  20.     /// Recommend turning off Copy and Paste at the same time complete the effect.
  21.     ///
  22.     /// This is suitable for game scenarios where you want players to compete in something but not have access to building anything.
  23.     /// Another method for achieving this would be to remove all buildable cubes from the game menu,
  24.     /// but they may require a tailored mod depending on how many other modded cubes are loaded.
  25.     /// </summary>
  26.     /// <permission cref="midspace. Use however you want." />
  27.     [MyEntityComponentDescriptor(typeof(MyObjectBuilder_CubePlacer))]
  28.     public class MyBuildBlockerLogic : MyGameLogicComponent
  29.     {
  30.         private MyObjectBuilder_EntityBase _objectBuilder;
  31.  
  32.         public override void Close()
  33.         {
  34.         }
  35.  
  36.         public override void Init(MyObjectBuilder_EntityBase objectBuilder)
  37.         {
  38.             _objectBuilder = objectBuilder;
  39.             Entity.NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;
  40.  
  41.             if (MyAPIGateway.CubeBuilder != null)
  42.             {
  43.                 MyAPIGateway.CubeBuilder.DeactivateBlockCreation();
  44.                 MyAPIGateway.CubeBuilder.Deactivate();
  45.             }
  46.         }
  47.  
  48.         public override void MarkForClose()
  49.         {
  50.         }
  51.  
  52.         public override void UpdateAfterSimulation()
  53.         {
  54.             if (MyAPIGateway.CubeBuilder != null)
  55.             {
  56.                 MyAPIGateway.CubeBuilder.DeactivateBlockCreation();
  57.                 MyAPIGateway.CubeBuilder.Deactivate();
  58.             }
  59.         }
  60.  
  61.         public override void UpdateAfterSimulation10()
  62.         {
  63.         }
  64.  
  65.         public override void UpdateAfterSimulation100()
  66.         {
  67.         }
  68.  
  69.         public override void UpdateBeforeSimulation()
  70.         {
  71.             if (MyAPIGateway.CubeBuilder != null)
  72.             {
  73.                 MyAPIGateway.CubeBuilder.DeactivateBlockCreation();
  74.                 MyAPIGateway.CubeBuilder.Deactivate();
  75.             }
  76.         }
  77.  
  78.         public override void UpdateBeforeSimulation10()
  79.         {
  80.         }
  81.  
  82.         public override void UpdateBeforeSimulation100()
  83.         {
  84.             if (MyAPIGateway.Utilities != null)
  85.             {
  86.                 MyAPIGateway.Utilities.ShowNotification("Building is Disabled.", 1000, MyFontEnum.Blue);
  87.             }
  88.             if (MyAPIGateway.CubeBuilder != null)
  89.             {
  90.                 MyAPIGateway.CubeBuilder.DeactivateBlockCreation();
  91.                 MyAPIGateway.CubeBuilder.Deactivate();
  92.             }
  93.         }
  94.  
  95.         public override void UpdateOnceBeforeFrame()
  96.         {
  97.             if (MyAPIGateway.CubeBuilder != null)
  98.             {
  99.                 MyAPIGateway.CubeBuilder.DeactivateBlockCreation();
  100.                 MyAPIGateway.CubeBuilder.Deactivate();
  101.             }
  102.         }
  103.  
  104.         public override MyObjectBuilder_EntityBase GetObjectBuilder(bool copy = false)
  105.         {
  106.             return copy ? Entity.GetObjectBuilder() : _objectBuilder;
  107.         }
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement