SHARE
TWEET

SE Shield Generator - Status on LCD [Mini]

scadl Jan 26th, 2018 (edited) 258 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This is simplified version of this script
  2. // http://steamcommunity.com/sharedfiles/filedetails/?id=902088441
  3.  
  4. List<IMyTerminalBlock> ShieldsArray;
  5. List<IMyTerminalBlock> LCDsArray;
  6.  
  7. public void SEStatusInit()
  8. {
  9.     // Search for Shileds in Grid
  10.     ShieldsArray = new List<IMyTerminalBlock>();
  11.     GridTerminalSystem.SearchBlocksOfName("Shield Generator", ShieldsArray);
  12.  
  13.     // Building list of Displays to show status
  14.     LCDsArray = new List<IMyTerminalBlock>();
  15.     GridTerminalSystem.SearchBlocksOfName("[ShieldM]", LCDsArray);
  16.  
  17. }
  18.  
  19. public Program()
  20. {
  21.     // Setting script for self-update eache 100 ticks = 1.6 sec
  22.     Runtime.UpdateFrequency = UpdateFrequency.Update100;
  23.  
  24.     // Call init on 1st run!
  25.     SEStatusInit();
  26. }
  27.  
  28. public void Main(string argument)
  29. {
  30.  
  31.     // Loop through all lcds with designated name
  32.     for (int i = 0; i < LCDsArray.Count; i++)
  33.     {
  34.  
  35.         if (LCDsArray[i] == null)
  36.         {
  37.             Echo("You lost some lcds. ReCompile this script!");
  38.             return;
  39.         }
  40.  
  41.         IMyTextPanel LCD = (IMyTextPanel)LCDsArray[i];
  42.         LCD.WritePublicText("", false);
  43.  
  44.         string ShieldsData = "";
  45.         string OverallShield = "";
  46.         string CurrentShield = "";
  47.         string ShieldUnits = "";
  48.  
  49.         // Let's read date from shields, if we have them
  50.         for (int j = 0; j < ShieldsArray.Count; j++)
  51.         {
  52.  
  53.             if (ShieldsArray[j] == null)
  54.             {
  55.                 Echo("You lost some shields. ReCompile this script!");
  56.                 LCD.WritePublicText("You lost some shields. ReCompile this script!", false);
  57.                 return;
  58.             }
  59.  
  60.             ShieldsData = ShieldsArray[j].CustomInfo.Split('\n')[1];
  61.             CurrentShield = ShieldsData.Split(' ')[2];
  62.             OverallShield = ShieldsData.Split(' ')[3].Split('/')[1];
  63.             ShieldUnits = ShieldsData.Split(' ')[3].Split('/')[0];
  64.  
  65.         }
  66.  
  67.         // Okay, shield data preserved.
  68.         // Let's adjust lcd's and post data to them
  69.         if (ShieldsArray.Count > 0)
  70.         {
  71.             LCD.SetValueFloat("FontSize", 1.4f);
  72.             LCD.WritePublicText("Overall: " + CurrentShield + " of " + OverallShield + " " + ShieldUnits + "\n");
  73.  
  74.             float Cur = Convert.ToSingle(CurrentShield);
  75.             float Max = Convert.ToSingle(OverallShield);
  76.             float prog = (Cur / Max) * 67;
  77.             float empt = (67 - prog) / 2;
  78.  
  79.             // This is where we went through lcds, and showing formated data
  80.             for (int k = 0; k < prog; k++)
  81.             {
  82.                 LCD.WritePublicText(LCD.GetPublicText() + "|");
  83.             }
  84.  
  85.         }
  86.         else
  87.         {
  88.             // This obviously will be shown if something wrong happend
  89.             LCD.WritePublicText("You don't have Energy Shields\nor named them incorrectly.\n-------------------------------------------\n");
  90.             LCD.WritePublicText(LCD.GetPublicText() + "Please, make shure you have \nmod installed, and shield \nblocks have 'Energy Shield'\n");
  91.             LCD.WritePublicText(LCD.GetPublicText() + "phrase in blocks's name");
  92.         }
  93.  
  94.  
  95.     }
  96. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top