Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // In space oxygen is a very valuable ressource
- // keeping a large place supplied with oxygen
- // when ressources are getting low can be a waste
- // therefore it can be relevant if the case happen to
- // reduce the oxygenated area and bring back
- // oxygen where needed.
- // This script ensure that when the oxygen generator
- // ice ressources become low oxygen gets sucked
- // out and then reserved for the medical room.
- /* PS:
- * Try to understand the code. If you cant, focus on what is
- * missing in the damaged programs. In this series of exercices
- * The code is always mirrored in a way so that working
- * examples can help you complete the non working ones
- * by changing very few things.
- */
- void DepressurizeAllAirVents()
- {
- var myAirVents = new List<IMyAirVent>();
- GridTerminalSystem.GetBlocksOfType<IMyAirVent>(myAirVents);
- for (int i = 0; i < myAirVents.Count; i++)
- {
- //We exclude the Airvent of the sas of course
- if (myAirVents[i].CustomName != "SasAirVent")
- myAirVents[i].ApplyAction("Depressurize_On");
- }
- }
- /* PS:
- * This function code is here to show you how you can access
- * Inventories of your blocks. It is yet not relevant to fix the actual
- * issue as it does not have to be changed from one code to the other.
- */
- float GetGeneratorRemainingIceAmount()
- {
- float IceAmount = 0.0f;
- // To access the inventory of a block you can slice it to IMyInventoryOwner.
- var myOxygenGenerator = GridTerminalSystem.GetBlockWithName("OxygenGenerator") as IMyGasGenerator;
- if (myOxygenGenerator != null)
- {
- // Searching every slots in the inventory is done this way
- // in Space engineers an inventory is a slot that contains
- // items of a given type. So basicly when you open the
- // inventory tab what you see is in fact a list of inventories
- // characters and blocks possess thus a list of inventories.
- for (var i = 0; i < myOxygenGenerator.InventoryCount; i++)
- {
- var slot = myOxygenGenerator.GetInventory(i);
- var items = new List<MyInventoryItem>();
- slot.GetItems(items);
- for (int j = 0; j < items.Count; j++)
- {
- IceAmount += (float)items[j].Amount;
- Echo(items[j].Amount.ToString());
- }
- }
- }
- return IceAmount;
- }
- void ChangeOxygenRoomLightsColor()
- {
- var myLights = new List<IMyTerminalBlock>();
- GridTerminalSystem.SearchBlocksOfName("Light_OxygenRoom", myLights);
- var myColor = new Color(255, 0, 0);
- for (int i =0; i< myLights.Count; i++)
- {
- var light = myLights[i] as IMyInteriorLight;
- light.SetValue("Color", myColor);
- }
- }
- void Main(string argument)
- {
- if (GetGeneratorRemainingIceAmount() < 100)
- {
- DepressurizeAllAirVents();
- ChangeOxygenRoomLightsColor();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement