Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- namespace Oxide.Plugins
- {
- [Info("StructureDestroyer", "PsychoTea", "1.0.0")]
- class StructureDestroyer : RustPlugin
- {
- [ChatCommand("destroy")]
- void DestroyCommand(BasePlayer player, string command, string[] args)
- {
- if (!player.IsAdmin) return;
- if (args.Length < 1)
- {
- SendReply(player, "Incorrect usage! /destroy {range} [name]");
- return;
- }
- int range = 0;
- if (!Int32.TryParse(args[0], out range))
- {
- SendReply(player, "Error! The range must be a number!");
- return;
- }
- string name = args.Length > 1 ? string.Join(" ", args.Skip(1).ToArray()) : "";
- TempSphere(player.transform.position, range);
- int count = 0;
- if (string.IsNullOrEmpty(name))
- {
- foreach (BuildingBlock buildBlock in GetBuildBlocksInRange(player.transform.position, range).Where(block => !block.IsDestroyed))
- {
- buildBlock.Kill();
- count++;
- }
- }
- foreach (BaseEntity ent in GetDeployablesInRange(player.transform.position, range))
- {
- if (!string.IsNullOrEmpty(name) && ent.ShortPrefabName == name)
- {
- ent.Kill();
- count++;
- }
- }
- SendReply(player, $"Destroyed {count.ToString()} {(string.IsNullOrEmpty(name) ? "building blocks and deployables" : $"\"{name}\"'s")}.");
- }
- [ChatCommand("deployables")]
- void DeployablesCommand(BasePlayer player, string command, string[] args)
- {
- if (!player.IsAdmin) return;
- if (args.Length < 1)
- {
- SendReply(player, "Incorrect usage! /deployables {range}");
- return;
- }
- int range = 0;
- if (!Int32.TryParse(args[0], out range))
- {
- SendReply(player, "Error! The range must be a number!");
- return;
- }
- var deployables = GetDeployablesInRange(player.transform.position, range);
- var deployableNames = deployables.Select(x => x.ShortPrefabName).Distinct();
- string deplMessage = string.Join(", ", deployableNames.ToArray());
- SendReply(player, $"Deployables in {range.ToString("N0")}m:\n{deplMessage}");
- }
- void TempSphere(Vector3 pos, float radius)
- {
- List<SphereEntity> spheres = new List<SphereEntity>();
- for (int i = 0; i < 10; i++)
- {
- var sphere = GameManager.server.CreateEntity("assets/prefabs/visualization/sphere.prefab", pos).GetComponent<SphereEntity>();
- sphere.currentRadius = radius;
- sphere.lerpSpeed = 1f;
- sphere.Spawn();
- spheres.Add(sphere);
- }
- timer.Once(5f, () =>
- {
- foreach (var sphere in spheres.Where(x => !x.IsDestroyed))
- sphere.Kill();
- });
- }
- List<BuildingBlock> GetBuildBlocksInRange(Vector3 pos, float range) => UnityEngine.Object.FindObjectsOfType<BuildingBlock>().Where(x => Vector3.Distance(x.transform.position, pos) <= range).ToList();
- 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();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement