Advertisement
Whiplash141

Whip's Weapon Sequencer v11 [SpaceEngineers]

Aug 19th, 2015
5,414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.09 KB | None | 0 0
  1. /*    
  2. Whiplash's Weapon Sequencing Script v11 - Revision: 9/1/15  
  3. ////PUBLIC RELEASE////
  4. HOWDY!
  5. ______________________________________________________________________________________  
  6. Instructions:  
  7.  
  8.     1.) Create a timer. Assign the actions to the following:    
  9.         * "trigger now" itself
  10.         * Run this program [NO ARGUMENTS YET!]  
  11.     2.) Add the phrase "[Sequenced]" into the name of weapons u want to sequence (without quotes)
  12.     3.) Start the timer
  13. ______________________________________________________________________________________      
  14. Arguments:
  15.  
  16. Type in these arguments without quotes. These arguments can be input manually,
  17. through timers, or through sensors. Letter case is unimportant. Seperate  
  18. multiple arguments with a semicolon (see examples further down)
  19.    
  20. "rate [integer]"  
  21.     changes the rate of fire in rounds per second.
  22.     > [Maximum ROF] = [Standard ROF] * [Number of sequenced weapons]
  23.         NOTE: The script will round the ROF, this is not a bug!
  24. "delay [integer]"  
  25.     changes delay between shots to be in terms of frames (60 frames = 1 sec)  
  26. "default"  
  27.     Lets the script to set the fire rate automatically based on the number of    
  28.     available weapons. The script will attempt to fire ALL sequenced weapons in the
  29.     span of ONE second with this particular setting. The script will start in this
  30.     mode by default (hence the name :P)
  31. "on"  
  32.     Toggles fire on only  
  33. "off"  
  34.     Toggles fire off only  
  35. "toggle"  
  36.     Toggles fire on/off  
  37. ______________________________________________________________________________________    
  38. Examples:
  39.  
  40. "on;default" will toggle the weapons on and use default rate of fire
  41. "rate 10" will set the rate of fire to 10 rounds per second
  42. "delay 3" will set the delay between weapons to 3 frames    
  43. ______________________________________________________________________________________    
  44.  
  45. If you have any questions feel free to post them on the workshop page!            
  46. Workshop link: http://steamcommunity.com/sharedfiles/filedetails/?id=510805229
  47.    
  48. - Whiplash141 - http://steamcommunity.com/id/Whiplash141/  
  49.     Please do not send me random friend requests! Leave comments
  50.     on my profile if you wish to contact me directly :)
  51. */    
  52.    
  53. //-------------------------------------------------    
  54. //This is the ID string for the weapons that you want to fire  
  55. //You can place it anywhere in the weapon's name  
  56. string unique_identification_string = "[Sequenced]";    
  57. //-------------------------------------------------    
  58.  
  59. List<IMyTerminalBlock> UIS_list = new List<IMyTerminalBlock>();    
  60. List<IMyTerminalBlock> sequence_weapons = new List<IMyTerminalBlock>();        
  61. IMyUserControllableGun weaponToFire;        
  62. int weapon_count=0;    
  63. int time_count=0;      
  64. int delay;    
  65. int value_integer;
  66. int n; //test value
  67. double delay_unrounded;      
  68. bool executeToggle = false;  //tracks if the script should toggle on/off
  69. bool manualOverride = false;  //tracks if player has overriden default values
  70. bool isInteger = true; //for checking if input is an integer
  71. string messageToggle;  
  72. string messageOverride;
  73. string value;  
  74.          
  75. void Main(string argument)        
  76. {  
  77.    
  78.     GridTerminalSystem.SearchBlocksOfName(unique_identification_string,UIS_list);
  79.     sequence_weapons.Clear(); //clears all weapons each iteration
  80.    
  81.     for (int i=0 ; i < UIS_list.Count ; i++)
  82.     {
  83.         if(UIS_list[i] is IMyLargeTurretBase) continue; //ignore turrets
  84.         if(!(UIS_list[i] is IMyUserControllableGun)) continue; //ignore everything not a weapon
  85.         sequence_weapons.Add(UIS_list[i] as IMyUserControllableGun); //add weapons to list
  86.     }
  87.        
  88.    
  89.     if(sequence_weapons.Count  == 0)
  90.     {
  91.         Echo("No weapons found to sequence. Weapon names must contain '[Sequenced]' in their name to be sequenced.");
  92.         return;
  93.     }
  94.    
  95.    
  96.     //It's splittin' time!    
  97.     string[] argument_split = argument.Split(';');  //split at semi colons  
  98.    
  99.     for (int i=0 ; i < argument_split.Length ; i++)    
  100.     {    
  101.         string[] argument_fields = argument_split[i].Split(' '); //splits commands in two fields      
  102.          
  103.         if (argument_fields.Length == 2) //2 fields
  104.         {    
  105.             value = argument_fields[1];    
  106.         }else{    
  107.             value = "null";    
  108.         }  
  109.        
  110.         switch (argument_fields[0].ToLower())    
  111.         {    
  112.             case "rate": //change rate of fire manually  
  113.                 isInteger = int.TryParse(value, out n);
  114.                 if (isInteger == false) return;
  115.                
  116.                 value_integer = Convert.ToInt32(value);    
  117.                 delay_unrounded = 60 / value_integer; //Dont change this from 60  
  118.                 delay = Convert.ToInt32(Math.Ceiling(delay_unrounded));    
  119.                 manualOverride = true;      
  120.                 break;  
  121.                    
  122.             case "delay": //change delay (in frames )between shots; 60 frames = 1 sec  
  123.                 isInteger = int.TryParse(value, out n);
  124.                 if (isInteger == false) return;
  125.                
  126.                 value_integer = Convert.ToInt32(value);  
  127.                 delay = value_integer;  
  128.                 manualOverride = true;      
  129.                 break;  
  130.                    
  131.             case "default": //lets the script set fire rate      
  132.                 delay_unrounded = 60 / sequence_weapons.Count; //set delay between weapons        
  133.                 delay = Convert.ToInt32(Math.Ceiling(delay_unrounded));  
  134.                 manualOverride = false;  
  135.                 break;  
  136.                        
  137.             case "on": //toggle fire on  
  138.                 executeToggle = true;  
  139.                 break;  
  140.                    
  141.             case "off": //toggle fire off  
  142.                 executeToggle = false;  
  143.                 break;  
  144.                    
  145.             case "toggle": //toggle fire on or off  
  146.                 if (executeToggle == false) //if false switch true  
  147.                 {  
  148.                     executeToggle = true;  
  149.                 }else{ //if true switch false  
  150.                     executeToggle = false;  
  151.                 }  
  152.                 break;    
  153.                
  154.             default:    
  155.                 if (manualOverride == false)  
  156.                 {    
  157.                     delay_unrounded = 60 / sequence_weapons.Count; //set delay between weapons        
  158.                     delay = Convert.ToInt32(Math.Ceiling(delay_unrounded));    
  159.                 }  
  160.                 break;  
  161.         }    
  162.     }  
  163.              
  164.      
  165.     //This will only run if delay has elapsed        
  166.     if (time_count >= delay)        
  167.     {            
  168.         time_count = 0; //start count over    
  169.    
  170.         //Turns all weapons off        
  171.         for (int i=0 ; i < sequence_weapons.Count ; i++)        
  172.         {      
  173.             var weaponReset = sequence_weapons[i];          
  174.             if (executeToggle == true)    
  175.             {  
  176.                 weaponReset.ApplyAction("OnOff_On"); //Turns all weapons on for toggle fire      
  177.             }else{        
  178.                 weaponReset.ApplyAction("OnOff_Off");  
  179.             }  
  180.         }              
  181.    
  182.         //Activates specified weapon and iterates count var        
  183.         if (weapon_count < sequence_weapons.Count)      
  184.         {        
  185.             var weaponToFire = sequence_weapons[weapon_count];  
  186.             weaponToFire.ApplyAction("OnOff_On");    
  187.             weapon_count++; //counts once per delay      
  188.                
  189.             if (executeToggle == true)  
  190.             {  
  191.                 weaponToFire.ApplyAction("ShootOnce");  
  192.                 messageToggle = "-Toggle Fire Enabled-";  
  193.             }else{  
  194.                 messageToggle = "-Toggle Fire Disabled-";  
  195.             }  
  196.        
  197.         }else{        
  198.             weapon_count=0;    
  199.             var weaponToFire = sequence_weapons[weapon_count];        
  200.             weaponToFire.ApplyAction("OnOff_On");  
  201.             weapon_count++;    
  202.                
  203.             if (executeToggle == true)  
  204.             {  
  205.                 weaponToFire.ApplyAction("ShootOnce");  
  206.                 messageToggle = "-Toggle Fire Enabled-";  
  207.             }else{  
  208.                 messageToggle = "-Toggle Fire Disabled-";  
  209.             }  
  210.         }        
  211.            
  212.     }else{        
  213.     time_count++;//continues to count until delay is hit             
  214.     }
  215.  
  216.     if (manualOverride == true)
  217.     {
  218.         messageOverride = "-Defaults Overriden-";
  219.     }else{
  220.         messageOverride = "-Defaults Applied-";
  221.     }
  222.    
  223.     if (isInteger == false)
  224.     {
  225.         Echo("Error: value must be an integer!\n>Value ignored");
  226.     }
  227.    
  228.     //Debug  
  229.     Echo(messageToggle + "\n" + messageOverride + "\nNo. Weapons:" + sequence_weapons.Count + "\nRate of Fire: " + 60/delay + " RPS" + "\nDelay: " + delay + " frames" + "\nCurrent Time: " + time_count + "\nWeapon Count: " + weapon_count);          
  230. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement