Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEngine;
  5.  
  6. namespace Oxide.Plugins
  7. {
  8. [Info("StructureDestroyer", "PsychoTea", "1.0.0")]
  9.  
  10. class StructureDestroyer : RustPlugin
  11. {
  12. [ChatCommand("destroy")]
  13. void DestroyCommand(BasePlayer player, string command, string[] args)
  14. {
  15. if (!player.IsAdmin) return;
  16.  
  17. if (args.Length < 1)
  18. {
  19. SendReply(player, "Incorrect usage! /destroy {range} [name]");
  20. return;
  21. }
  22.  
  23. int range = 0;
  24. if (!Int32.TryParse(args[0], out range))
  25. {
  26. SendReply(player, "Error! The range must be a number!");
  27. return;
  28. }
  29.  
  30. string name = args.Length > 1 ? string.Join(" ", args.Skip(1).ToArray()) : "";
  31.  
  32. TempSphere(player.transform.position, range);
  33.  
  34. int count = 0;
  35.  
  36. if (string.IsNullOrEmpty(name))
  37. {
  38. foreach (BuildingBlock buildBlock in GetBuildBlocksInRange(player.transform.position, range).Where(block => !block.IsDestroyed))
  39. {
  40. buildBlock.Kill();
  41. count++;
  42. }
  43. }
  44.  
  45. foreach (BaseEntity ent in GetDeployablesInRange(player.transform.position, range))
  46. {
  47. if (!string.IsNullOrEmpty(name) && ent.ShortPrefabName == name)
  48. {
  49. ent.Kill();
  50. count++;
  51. }
  52. }
  53.  
  54. SendReply(player, $"Destroyed {count.ToString()} {(string.IsNullOrEmpty(name) ? "building blocks and deployables" : $"\"{name}\"'s")}.");
  55. }
  56.  
  57. [ChatCommand("deployables")]
  58. void DeployablesCommand(BasePlayer player, string command, string[] args)
  59. {
  60. if (!player.IsAdmin) return;
  61.  
  62. if (args.Length < 1)
  63. {
  64. SendReply(player, "Incorrect usage! /deployables {range}");
  65. return;
  66. }
  67.  
  68. int range = 0;
  69. if (!Int32.TryParse(args[0], out range))
  70. {
  71. SendReply(player, "Error! The range must be a number!");
  72. return;
  73. }
  74.  
  75. var deployables = GetDeployablesInRange(player.transform.position, range);
  76. var deployableNames = deployables.Select(x => x.ShortPrefabName).Distinct();
  77. string deplMessage = string.Join(", ", deployableNames.ToArray());
  78. SendReply(player, $"Deployables in {range.ToString("N0")}m:\n{deplMessage}");
  79. }
  80.  
  81. void TempSphere(Vector3 pos, float radius)
  82. {
  83. List<SphereEntity> spheres = new List<SphereEntity>();
  84.  
  85. for (int i = 0; i < 10; i++)
  86. {
  87. var sphere = GameManager.server.CreateEntity("assets/prefabs/visualization/sphere.prefab", pos).GetComponent<SphereEntity>();
  88. sphere.currentRadius = radius;
  89. sphere.lerpSpeed = 1f;
  90. sphere.Spawn();
  91. spheres.Add(sphere);
  92. }
  93.  
  94. timer.Once(5f, () =>
  95. {
  96. foreach (var sphere in spheres.Where(x => !x.IsDestroyed))
  97. sphere.Kill();
  98. });
  99. }
  100.  
  101. List<BuildingBlock> GetBuildBlocksInRange(Vector3 pos, float range) => UnityEngine.Object.FindObjectsOfType<BuildingBlock>().Where(x => Vector3.Distance(x.transform.position, pos) <= range).ToList();
  102.  
  103. List<BaseEntity> GetDeployablesInRange(Vector3 pos, float range) => BaseNetworkable.serverEntities.Where(x => x.name.Contains("deploy")).Cast<BaseEntity>().Where(x => Vector3.Distance(pos, x.transform.position) <= range).ToList();
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement