Advertisement
Guest User

Untitled

a guest
May 24th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. // In space oxygen is a very valuable ressource
  2. // keeping a large place supplied with oxygen
  3. // when ressources are getting low can be a waste
  4. // therefore it can be relevant if the case happen to
  5. // reduce the oxygenated area and bring back
  6. // oxygen where needed.
  7.  
  8. // This script ensure that when the oxygen generator
  9. // ice ressources become low oxygen gets sucked
  10. // out and then reserved for the medical room.
  11.  
  12. /* PS:
  13. * Try to understand the code. If you cant, focus on what is
  14. * missing in the damaged programs. In this series of exercices
  15. * The code is always mirrored in a way so that working
  16. * examples can help you complete the non working ones
  17. * by changing very few things.
  18. */
  19.  
  20. void DepressurizeAllAirVents()
  21. {
  22. var myAirVents = new List<IMyAirVent>();
  23. GridTerminalSystem.GetBlocksOfType<IMyAirVent>(myAirVents);
  24. for (int i = 0; i < myAirVents.Count; i++)
  25. {
  26. //We exclude the Airvent of the sas of course
  27. if (myAirVents[i].CustomName != "SasAirVent")
  28. myAirVents[i].ApplyAction("Depressurize_On");
  29. }
  30. }
  31.  
  32. /* PS:
  33. * This function code is here to show you how you can access
  34. * Inventories of your blocks. It is yet not relevant to fix the actual
  35. * issue as it does not have to be changed from one code to the other.
  36. */
  37. float GetGeneratorRemainingIceAmount()
  38. {
  39. float IceAmount = 0.0f;
  40.  
  41. // To access the inventory of a block you can slice it to IMyInventoryOwner.
  42. var myOxygenGenerator = GridTerminalSystem.GetBlockWithName("OxygenGenerator") as IMyGasGenerator;
  43.  
  44. if (myOxygenGenerator != null)
  45. {
  46. // Searching every slots in the inventory is done this way
  47. // in Space engineers an inventory is a slot that contains
  48. // items of a given type. So basicly when you open the
  49. // inventory tab what you see is in fact a list of inventories
  50. // characters and blocks possess thus a list of inventories.
  51. for (var i = 0; i < myOxygenGenerator.InventoryCount; i++)
  52. {
  53. var slot = myOxygenGenerator.GetInventory(i);
  54. var items = new List<MyInventoryItem>();
  55. slot.GetItems(items);
  56. for (int j = 0; j < items.Count; j++)
  57. {
  58. IceAmount += (float)items[j].Amount;
  59. Echo(items[j].Amount.ToString());
  60. }
  61. }
  62. }
  63. return IceAmount;
  64. }
  65.  
  66. void ChangeOxygenRoomLightsColor()
  67. {
  68. var myLights = new List<IMyTerminalBlock>();
  69. GridTerminalSystem.SearchBlocksOfName("Light_OxygenRoom", myLights);
  70. var myColor = new Color(255, 0, 0);
  71.  
  72. for (int i =0; i< myLights.Count; i++)
  73. {
  74. var light = myLights[i] as IMyInteriorLight;
  75. light.SetValue("Color", myColor);
  76. }
  77. }
  78.  
  79. void Main(string argument)
  80. {
  81. if (GetGeneratorRemainingIceAmount() < 100)
  82. {
  83. DepressurizeAllAirVents();
  84. ChangeOxygenRoomLightsColor();
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement