midspace

SE broadcast blocker

Sep 3rd, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.66 KB | None | 0 0
  1. // Code to block broadcasts from antennas and beacons.
  2. // Works in situations as player, cockpit, camera.
  3. // Does not work when player is controlling a turretm or a remote control!!
  4. // Note: I have no idea how efficient the script is. there may be performance issues
  5.  
  6. namespace midspace.BroadcastBlocker.
  7. {
  8.     using Sandbox.Game.Entities;
  9.     using Sandbox.ModAPI;
  10.     using VRage.Game;
  11.     using VRage.Game.Components;
  12.     using VRage.Game.ModAPI;
  13.     using VRageMath;
  14.  
  15.     [MySessionComponentDescriptor(MyUpdateOrder.BeforeSimulation)]
  16.     public class SessionComponentLogic : MySessionComponentBase
  17.     {
  18.         private bool _isInitialized;
  19.  
  20.         public override void UpdateBeforeSimulation()
  21.         {
  22.             if (!_isInitialized && MyAPIGateway.Session != null && MyAPIGateway.Session.Player != null)
  23.             {
  24.                 _isInitialized = true; // Set this first to block any other calls from UpdateAfterSimulation().
  25.             }
  26.  
  27.             if (_isInitialized)
  28.             {
  29.                 var character = MyAPIGateway.Session.ControlledObject as IMyCharacter;
  30.                 var cockpit = MyAPIGateway.Session.ControlledObject as MyShipController;
  31.                 if (character != null)
  32.                 {
  33.                     MyDataReceiver radioReceiver = character.Components.Get<MyDataReceiver>();
  34.                     radioReceiver.Clear();
  35.                 }
  36.                 if (cockpit != null)
  37.                 {
  38.                     MyDataReceiver radioReceiver = ((IMyCharacter)(cockpit).Pilot).Components.Get<MyDataReceiver>();
  39.                     radioReceiver.Clear();
  40.                 }
  41.             }
  42.         }
  43.     }
  44. }
Add Comment
Please, Sign In to add comment