Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Meridius_IX's Pirate AI Systems - Territorial Drone
- double player_detect_range = 25000; //If player is further than this value from drone, it will not execute any behavioral scripting.
- double territory_radius = 10000; //If player is within this distance of the drone spawning point, the drone will pursue the player.
- bool use_raycast_ranged_weapons = true;
- bool use_raycast_close_weapons = false;
- //////////////////////////////////////////////////////
- //Do Not Touch Anything Below Here
- //////////////////////////////////////////////////////
- double player_drone_distance = 0;
- double player_origin_distance = 0;
- double drone_origin_distance = 0;
- //Raycast Scan Data
- MyDetectedEntityInfo scanned_target;
- bool valid_scanned_target = false;
- double scanned_target_distance = 0;
- Vector3D scanned_target_coords = new Vector3D(0,0,0);
- IMyRemoteControl remote_control;
- void Main(string argument){
- Vector3D world_center = new Vector3D(0,0,0);
- Vector3D player_coords = new Vector3D(0,0,0);
- Vector3D drone_coords = new Vector3D(0,0,0);
- Vector3D origin_coords = new Vector3D(0,0,0);
- //Find Remote Control Block(s)
- List<IMyTerminalBlock> remote_control_list = new List<IMyTerminalBlock>();
- GridTerminalSystem.GetBlocksOfType<IMyRemoteControl>(remote_control_list);
- if(remote_control_list.Count != 0){
- for(int i = 0; i < remote_control_list.Count; i++){
- if(remote_control_list[i].IsFunctional == true){
- remote_control = remote_control_list[i] as IMyRemoteControl;
- break;
- }
- }
- }else{
- Echo("No Remote Control Block Found. Script Cannot Execute.");
- return;
- }
- //Check If Drone is NPC Owned
- remote_control.GetNearestPlayer(out player_coords);
- if(player_coords == world_center){
- Echo("Drone is not owned by Hostile NPC. Script Cannot Continue.");
- return;
- }
- drone_coords = remote_control.GetPosition();
- valid_scanned_target = RaycastScan();
- //Get & Set Origin Coords
- if(this.Storage == null || this.Storage == ""){
- this.Storage = drone_coords.ToString();
- origin_coords = drone_coords;
- }else{
- Vector3D.TryParse(this.Storage, out origin_coords);
- }
- //Calculate Distances
- player_drone_distance = MeasureDistance(player_coords, drone_coords);
- player_origin_distance = MeasureDistance(player_coords, origin_coords);
- drone_origin_distance = MeasureDistance(drone_coords, origin_coords);
- scanned_target_distance = MeasureDistance(drone_coords, scanned_target_coords);
- if(player_drone_distance > player_detect_range){
- Echo("No Player Detected. Aborting Script Execution.");
- }
- //////////////////////////////////////////////////////
- //Pirate Behavior Start
- //////////////////////////////////////////////////////
- WeaponActivation("Ranged", "None");
- remote_control.ClearWaypoints();
- if(player_origin_distance < territory_radius){
- remote_control.AddWaypoint(player_coords, "Player");
- }else{
- remote_control.AddWaypoint(origin_coords, "Origin");
- }
- remote_control.ApplyAction("AutoPilot_On");
- //////////////////////////////////////////////////////
- //Pirate Behavior End
- //////////////////////////////////////////////////////
- }
- bool RaycastScan(){
- List<IMyTerminalBlock> camera_list = new List<IMyTerminalBlock>();
- GridTerminalSystem.GetBlocksOfType<IMyCameraBlock>(camera_list);
- if(camera_list.Count != 0){
- for(int i = 0; i < camera_list.Count; i++){
- IMyCameraBlock camera = camera_list[i] as IMyCameraBlock;
- if(camera.IsFunctional == true){
- camera.EnableRaycast = true;
- if(camera.CanScan(1600)){
- scanned_target = camera.Raycast(1600, 0, 0);
- if(scanned_target.Relationship.ToString() != "Owner" || scanned_target.Relationship.ToString() != "FactionShare"){
- if(scanned_target.Type.ToString() == "LargeGrid" || scanned_target.Type.ToString() == "SmallGrid" || scanned_target.Type.ToString() == "CharacterHuman"){
- scanned_target_coords = scanned_target.Position;
- return true;
- }
- }
- }
- }
- }
- }else{
- Echo("No Camera Block Found. Cannot Do Raycast Scan.");
- return false;
- }
- return false;
- }
- void WeaponActivation(string weapon_type, string weapon_action){
- List<IMyTerminalBlock> ranged_weapons_list = new List<IMyTerminalBlock>();
- List<IMyTerminalBlock> grinders_list = new List<IMyTerminalBlock>();
- List<IMyTerminalBlock> turrets_list = new List<IMyTerminalBlock>();
- GridTerminalSystem.GetBlocksOfType<IMyUserControllableGun>(ranged_weapons_list);
- GridTerminalSystem.GetBlocksOfType<IMyShipGrinder>(grinders_list);
- GridTerminalSystem.GetBlocksOfType<IMyLargeMissileTurret>(turrets_list);
- GridTerminalSystem.GetBlocksOfType<IMyLargeGatlingTurret>(turrets_list);
- GridTerminalSystem.GetBlocksOfType<IMyLargeInteriorTurret>(turrets_list);
- //Ranged Weapons
- if(weapon_type == "Ranged"){
- for(int i = 0; i < ranged_weapons_list.Count; i++){
- IMyUserControllableGun weapon = ranged_weapons_list[i] as IMyUserControllableGun;
- if(scanned_target_distance <= 800 && valid_scanned_target == true && use_raycast_ranged_weapons == true){
- weapon.ApplyAction("Shoot_On");
- }else{
- weapon.ApplyAction("Shoot_Off");
- }
- }
- }
- //Grinder
- if(weapon_type == "Grinder"){
- for(int i = 0; i < grinders_list.Count; i++){
- if(scanned_target_distance <= 100 && valid_scanned_target == true && use_raycast_close_weapons == true){
- grinders_list[i].ApplyAction("OnOff_On");
- }else{
- grinders_list[i].ApplyAction("OnOff_Off");
- }
- }
- }
- //Turrets
- if(weapon_type == "Turret"){
- for(int i = 0; i < turrets_list.Count; i++){
- turrets_list[i].ApplyAction(weapon_action);
- }
- }
- }
- double MeasureDistance(Vector3D point_a, Vector3D point_b){
- double result = Math.Round( Vector3D.Distance( point_a, point_b ), 2 );
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement