Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Meridius_IX's Wandering Turret Aim Script
- IMyBlockGroup turretGroup;
- Random rnd = new Random();
- void Main(string argument){
- float maxElevation = 0.5f;
- float maxAzimuth = 0.5f;
- turretGroup = null;
- List<IMyBlockGroup> blockGroups = new List<IMyBlockGroup>();
- List<IMyLargeTurretBase> turretList = new List<IMyLargeTurretBase>();
- GridTerminalSystem.GetBlockGroups(blockGroups);
- if(blockGroups.Count != 0){
- foreach(IMyBlockGroup group in blockGroups){
- if(argument.Contains(group.Name) == true){
- turretGroup = group;
- break;
- }
- }
- }
- if(turretGroup != null){
- turretGroup.GetBlocksOfType<IMyLargeTurretBase>(turretList);
- }
- if(turretList.Count != 0){
- string [] argSplit = argument.Split('|');
- if(argSplit.Length <= 3){
- Echo("Argument Format Invalid, Please Check.");
- return;
- }else{
- float.TryParse(argSplit[2], out maxElevation);
- float.TryParse(argSplit[3], out maxAzimuth);
- }
- foreach(IMyLargeTurretBase turret in turretList){
- float elevationWander = 0.1f;
- float azimuthWander = 0.1f;
- if(turret.IsFunctional == false){
- continue;
- }
- //Get/Init Custom Data
- if(turret.CustomData.Contains("AimWander") == false){
- turret.CustomData = "AimWander|";
- elevationWander = (float)RandomNumberBetween(0.005f, 0.015f);
- azimuthWander = (float)RandomNumberBetween(0.005f, 0.015f);
- turret.CustomData += elevationWander.ToString() + "|";
- turret.CustomData += azimuthWander.ToString();
- }else{
- string [] dataSplit = turret.CustomData.Split('|');
- float.TryParse(dataSplit[1], out elevationWander);
- float.TryParse(dataSplit[2], out azimuthWander);
- }
- turret.Elevation += elevationWander;
- Echo(turret.Elevation.ToString());
- Echo(elevationWander.ToString());
- Echo(maxElevation.ToString() + "\n");
- if(elevationWander > 0){
- if(turret.Elevation > maxElevation){
- elevationWander = (float)RandomNumberBetween(-0.015f, -0.005f);
- }
- }else{
- if(turret.Elevation < maxElevation * -1){
- elevationWander = (float)RandomNumberBetween(0.005f, 0.015f);
- }
- }
- turret.Azimuth += azimuthWander;
- if(azimuthWander > 0){
- if(turret.Azimuth > maxAzimuth){
- azimuthWander = (float)RandomNumberBetween(-0.015f, -0.005f);
- }
- }else{
- if(turret.Azimuth < maxAzimuth * -1){
- azimuthWander = (float)RandomNumberBetween(0.005f, 0.015f);
- }
- }
- if(argument.Contains("BroadsideOn")){
- turret.ApplyAction("ShootOnce");
- turret.ApplyAction("Shoot_On");
- }
- if(argument.Contains("BroadsideOff")){
- turret.ApplyAction("Shoot_Off");
- }
- if(argument.Contains("BroadsideToggle")){
- turret.ApplyAction("Shoot");
- }
- turret.CustomData = "AimWander|";
- turret.CustomData += elevationWander.ToString() + "|";
- turret.CustomData += azimuthWander.ToString();
- }
- }
- }
- double RandomNumberBetween(float minValue, float maxValue){
- var next = rnd.NextDouble();
- return minValue + (next * (maxValue - minValue));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement