Space Engineers

Space Engineers

Energy Shields
 This topic has been pinned, so it's probably important
Mazen IIXIS Jul 26, 2015 @ 10:14pm
Shield Status LCD scripting code completed
I tried to upload the in game script code to workshop but I was unable to do so. So I'm putting the source code here. Feel free to use it in your game. Copy the codes below and paste them to the programmable block. It should work for everyone. Hopefully. As of right now I don't know of any bugs that might occur on other people's games. It's still early and I may add features to it, but because it's not on workshop I may will have to update it manually.

/* Mazen's LCD Shield status display

This program takes the Alpha Shield's name and derive the shield strength
and output it to the LCD screen so that the user can read it and know the shield strength
This code can be expanded upon to have textures if I have them.

* Requirements for the code to work:
- shield generator with ":" at the beginning
- Text Panel with name "shield_LCD"
- timer block set to 1 sec interval
*/

// Global variables
List<IMyTerminalBlock> shieldGenerator = null;
IMyTextPanel shield_display = null;

// initialize the shieldGenerator and find the shield generator
void shieldFinder()
{
shieldGenerator = new List<IMyTerminalBlock>();
GridTerminalSystem.SearchBlocksOfName(":", shieldGenerator);
}

// change string into int and return the percent of shield strength.
int percentage(string [] numbers)
{
int current_shield = Int32.Parse(numbers[0]);
int full_shield = Int32.Parse(numbers[1]);
if (full_shield == 0) return 0;
int percent = (current_shield * 100) / full_shield;
return percent;
}

// display the shield strength on the LCD so that users can see the shield strength
void LCD_display_shield(int shield)
{
shield_display = GridTerminalSystem.GetBlockWithName("shield_LCD") as IMyTextPanel;
shield_display.WritePublicText("Shield strength: " + shield + "%");
shield_display.ShowPublicTextOnScreen();
}

// split the string into two arrays with only numbers in them.
string [] splitter()
{
shieldFinder();
string [] shieldBoth = {"", ""};
char[] shieldCata = shieldGenerator[0].CustomName.ToCharArray();


// bool section
bool secondNumber = false;
bool isNumber = false;
bool isDecimal = false;

// loop section to loop for the numbers
int shieldSlot = 0;
foreach (char c in shieldCata)
{
if (c == '.') {isDecimal = true;} // should capture the '.' so that the code won't do anything weird.
else if (Char.IsDigit(c) && !isDecimal)
{
shieldBoth[shieldSlot] += c;
isNumber = true;
}
else if (isNumber && !secondNumber && !isDecimal)
{
shieldSlot++;
isNumber = !isNumber;
secondNumber = !secondNumber;
}
else if (isDecimal && c == '/')
{
isDecimal = !isDecimal;
isNumber = !isNumber;
secondNumber = !secondNumber;
shieldSlot++;
}
}

return shieldBoth;
}

void Main(string argument)
{
string [] readme = splitter();
LCD_display_shield(percentage(readme));
}
< >
Showing 1-8 of 8 comments
Cython  [developer] Jul 27, 2015 @ 5:32am 
Nice!
flori1994 Jul 27, 2015 @ 6:17am 
yes that is nice
Mazen IIXIS Jul 28, 2015 @ 3:38am 
Alright. I got the workshop to upload the in game script that will display shield strength as % AND bar indicator. It's at http://steamcommunity.com/sharedfiles/filedetails/?id=489633552 if anyone want to pick it up.
EasternGamer Jul 7, 2016 @ 11:09am 
The script doesn't work well. It gets rid of the energy in the shields and then it can't recharge.
Mazen IIXIS Jul 7, 2016 @ 12:59pm 
You mean in my script? As for the recharging and energy, that is the mod itself. The script only read the shield's strength and control what the LCDs output, and give the users the option to turn them on and off directly from the script, and a few other things. You will have to report the energy and recharge bug to Cython.
EasternGamer Jul 7, 2016 @ 1:43pm 
Originally posted by Mazen IIXIS:
You mean in my script? As for the recharging and energy, that is the mod itself. The script only read the shield's strength and control what the LCDs output, and give the users the option to turn them on and off directly from the script, and a few other things. You will have to report the energy and recharge bug to Cython.
Also the script didn't seem to work I'll try again I guess.
Mazen IIXIS Jul 7, 2016 @ 1:44pm 
Are you using the dev branch or the stable branch version? Because in dev branch they changed some of the in game script codes. If you see error message on it, let me know.
Mazen IIXIS Jul 7, 2016 @ 1:56pm 
^ Right now I'm refactoring the codes so that should hopefully fix it. If not, well, I will have to update the script for dev branch.
< >
Showing 1-8 of 8 comments
Per page: 1530 50