Advertisement
AndrewmanGaming

Slightly Adjust Rotor/Hinge/Piston Script

Aug 16th, 2021
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.33 KB | None | 0 0
  1.         //To use this script: Set the blocknames below. Then when you call the "Run" script, pass in an argument.
  2.         //The two argument types are:
  3.         //  - Decimal Number: Any number value to adjust the block speed by. ex: 0.01, -1.53, 2.12, -0.02
  4.         //  - STOP: If you pass the "STOP" argument into the script, it will set the velocity to 0.
  5.         //Then whenever you run the script, it will adjust the block's velocity by the amount in the argument, or stop it
  6.         //if the argument was STOP.
  7.  
  8.         //Config stuff:
  9.         //Set the name of the block. Make sure to set the correct name to the correct block type.
  10.         //Leave the other block types you are not using blank.
  11.         //NOTE: I did not program in any failure prevention, so if it cant find the block, it will just crash the script.
  12.         String rotorName = "";
  13.         String hingeName = "";
  14.         String pistonName = "";
  15.  
  16.         //Just some program stuff
  17.         IMyMotorStator rotor;
  18.         IMyPistonBase piston;
  19.         IMyMotorAdvancedStator hinge;
  20.  
  21.         float currentVelocity;
  22.  
  23.         public Program()
  24.         {
  25.             //Set current velocity to 0 at the start
  26.             currentVelocity = 0f;
  27.         }
  28.  
  29.         public void Main(string argument, UpdateType updateSource)
  30.         {
  31.             //Change current velocity
  32.             if (argument.Equals("STOP"))
  33.             {
  34.                 currentVelocity = 0f;
  35.             }
  36.             else
  37.             {
  38.                 currentVelocity += float.Parse(argument);
  39.             }
  40.             Echo("New Velocity = " + currentVelocity);
  41.            
  42.             //Get block and set to velocity
  43.             if (!rotorName.Equals(""))
  44.             {
  45.                 rotor = GridTerminalSystem.GetBlockWithName(rotorName) as IMyMotorStator;
  46.                 rotor.SetValueFloat("Velocity", currentVelocity);
  47.             } else if (!hingeName.Equals(""))
  48.             {
  49.                 hinge = GridTerminalSystem.GetBlockWithName(hingeName) as IMyMotorAdvancedStator;
  50.                 hinge.SetValueFloat("Velocity", currentVelocity);
  51.             } else if (!pistonName.Equals(""))
  52.             {
  53.                 piston = GridTerminalSystem.GetBlockWithName(pistonName) as IMyPistonBase;
  54.                 piston.SetValueFloat("Velocity", currentVelocity);
  55.             }
  56.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement