Guest User

EvilSensor Patch #8

a guest
Nov 18th, 2014
3
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 5.84 KB | None | 0 0
  1. diff --git a/Data/Scripts/EvilSensor/EvilSensor.cs b/Data/Scripts/EvilSensor/EvilSensor.cs
  2. index e851c4d..8e43484 100644
  3. --- a/Data/Scripts/EvilSensor/EvilSensor.cs
  4. +++ b/Data/Scripts/EvilSensor/EvilSensor.cs
  5. @@ -100,21 +100,20 @@ void sensor_StateChanged(bool obj)
  6.              // !obj would be when you exited the range, so nothing happens.
  7.              if (!obj) return;
  8.  
  9. -            // Define some mo' variables
  10. -            string objectName = "Iron";
  11. -
  12. -            string spawnType = "Ore";
  13. -
  14.              string sensorName = Sensor.CustomName;
  15.  
  16. -            VRageMath.Vector3 direction = Sensor.WorldMatrix.Forward;
  17. +            if (sensorName.Contains("[") && sensorName.Contains("]"))
  18. +            {
  19. +                // Define some mo' variables
  20. +                string objectName = "Iron";
  21.  
  22. -            var amount = 100;
  23. +                string spawnType = "Ore";
  24.  
  25. -            var distance = 1.5f;
  26. +                VRageMath.Vector3 direction = Sensor.WorldMatrix.Forward;
  27.  
  28. -            if (sensorName.Contains("[") && sensorName.Contains("]"))
  29. -            {
  30. +                var amount = 100;
  31. +
  32. +                var distance = 1.5f;
  33.                  /*
  34.                   * At this point, we parse the "data string" from the name,
  35.                   * break it down into sections, see what tags those sections
  36. @@ -273,39 +272,39 @@ void sensor_StateChanged(bool obj)
  37.                      direction = Sensor.WorldMatrix.Forward;
  38.                      Logging.Instance.WriteLine(String.Format("sensor_StateChanged(), String Parser: {0}", ex.ToString()));
  39.                  }
  40. -            }
  41. -            try
  42. -            {
  43. -                // Create the object to be spawned
  44. -                MyObjectBuilder_FloatingObject floatingBuilder = new MyObjectBuilder_FloatingObject();
  45. +                try
  46. +                {
  47. +                    // Create the object to be spawned
  48. +                    MyObjectBuilder_FloatingObject floatingBuilder = new MyObjectBuilder_FloatingObject();
  49.  
  50. -                floatingBuilder.PersistentFlags = MyPersistentEntityFlags2.InScene; // Very important, but I'm not sure why. I guess if not flagged as InScene, it won't be recognized as actually being there would be my guess.
  51. +                    floatingBuilder.PersistentFlags = MyPersistentEntityFlags2.InScene; // Very important, but I'm not sure why. I guess if not flagged as InScene, it won't be recognized as actually being there would be my guess.
  52.  
  53. -                // Set the postition and orientation of the object in the world.
  54. -                floatingBuilder.PositionAndOrientation = new MyPositionAndOrientation(Sensor.WorldMatrix.Translation + direction * distance, Sensor.WorldMatrix.Forward, Sensor.WorldMatrix.Up);
  55. +                    // Set the postition and orientation of the object in the world.
  56. +                    floatingBuilder.PositionAndOrientation = new MyPositionAndOrientation(Sensor.WorldMatrix.Translation + direction * distance, Sensor.WorldMatrix.Forward, Sensor.WorldMatrix.Up);
  57.  
  58. -                // Specify that the object is an inventory item of the type and amount specified
  59. -                switch (spawnType.ToLowerInvariant())
  60. +                    // Specify that the object is an inventory item of the type and amount specified
  61. +                    switch (spawnType.ToLowerInvariant())
  62. +                    {
  63. +                        case "component":
  64. +                            floatingBuilder.Item = new MyObjectBuilder_InventoryItem() { Amount = amount, Content = new MyObjectBuilder_Component { SubtypeName = objectName } };
  65. +                            break;
  66. +                        case "ingot":
  67. +                            floatingBuilder.Item = new MyObjectBuilder_InventoryItem() { Amount = amount, Content = new MyObjectBuilder_Ingot() { SubtypeName = objectName } };
  68. +                            break;
  69. +                        case "ore":
  70. +                            floatingBuilder.Item = new MyObjectBuilder_InventoryItem() { Amount = amount, Content = new MyObjectBuilder_Ore() { SubtypeName = objectName } };
  71. +                            break;
  72. +                        default:
  73. +                            break;
  74. +                    }
  75. +
  76. +                    // Finally, we actually create & spawn the damn thing in the world here. Enjoy!
  77. +                    var floatingObject = Sandbox.ModAPI.MyAPIGateway.Entities.CreateFromObjectBuilderAndAdd(floatingBuilder);
  78. +                }
  79. +                catch (Exception ex)
  80.                  {
  81. -                    case "component":
  82. -                        floatingBuilder.Item = new MyObjectBuilder_InventoryItem() { Amount = amount, Content = new MyObjectBuilder_Component { SubtypeName = objectName } };
  83. -                        break;
  84. -                    case "ingot":
  85. -                        floatingBuilder.Item = new MyObjectBuilder_InventoryItem() { Amount = amount, Content = new MyObjectBuilder_Ingot() { SubtypeName = objectName } };
  86. -                        break;
  87. -                    case "ore":
  88. -                        floatingBuilder.Item = new MyObjectBuilder_InventoryItem() { Amount = amount, Content = new MyObjectBuilder_Ore() { SubtypeName = objectName } };
  89. -                        break;
  90. -                    default:
  91. -                        break;
  92. +                    Logging.Instance.WriteLine(String.Format("sensor_StateChanged(), Object Builder: {0}", ex.ToString()));
  93.                  }
  94. -
  95. -                // Finally, we actually create & spawn the damn thing in the world here. Enjoy!
  96. -                var floatingObject = Sandbox.ModAPI.MyAPIGateway.Entities.CreateFromObjectBuilderAndAdd(floatingBuilder);
  97. -            }
  98. -            catch (Exception ex)
  99. -            {
  100. -                Logging.Instance.WriteLine(String.Format("sensor_StateChanged(), Object Builder: {0}", ex.ToString()));
  101.              }
  102.          }
Advertisement
Add Comment
Please, Sign In to add comment