Advertisement
Guest User

RemoverTool.cs

a guest
Jul 26th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 53.27 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System;
  3. using System.Reflection;
  4. using System.Data;
  5. using UnityEngine;
  6. using Facepunch;
  7. using Oxide.Core;
  8. using Oxide.Core.Libraries;
  9. using Oxide.Core.Plugins;
  10.  
  11. using System.Linq;
  12.  
  13. namespace Oxide.Plugins
  14. {
  15. [Info("RemoverTool", "Reneb", "3.1.3", ResourceId = 651)]
  16. class RemoverTool : RustPlugin
  17. {
  18. int CheckSpam = 0;
  19.  
  20. static FieldInfo serverinput;
  21. static FieldInfo buildingPrivlidges;
  22. static FieldInfo meshinstances;
  23. static int constructionColl = UnityEngine.LayerMask.GetMask(new string[] { "Construction", "Deployable", "Prevent Building", "Deployed" });
  24. static int blockColl = UnityEngine.LayerMask.GetMask(new string[] { "Construction" });
  25. static int playerColl = UnityEngine.LayerMask.GetMask(new string[] { "Player (Server)" });
  26.  
  27. enum RemoveType
  28. {
  29. Normal,
  30. Target,
  31. Admin,
  32. All
  33. }
  34.  
  35. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  36. /// Oxide Hooks
  37. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  38.  
  39. void Loaded()
  40. {
  41. serverinput = typeof(BasePlayer).GetField("serverInput", (BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic));
  42. buildingPrivlidges = typeof(BasePlayer).GetField("buildingPrivilege", (BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic));
  43. meshinstances = typeof(MeshColliderBatch).GetField("instances", (BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic));
  44. }
  45.  
  46. void OnServerInitialized()
  47. {
  48. InitializeRustIO();
  49. InitializeTable();
  50. permission.RegisterPermission(normalPermission, this);
  51. permission.RegisterPermission(adminPermission, this);
  52. permission.RegisterPermission(allPermission, this);
  53. permission.RegisterPermission(targetPermission, this);
  54.  
  55. mainjson = mainjson.Replace("{xmin}", xmin).Replace("{ymin}", ymin);
  56. double xminint = Convert.ToSingle(xmin);
  57. double yminint = Convert.ToSingle(ymin);
  58. double xmaxint = System.Math.Floor((xminint + 0.20) * 100) / 100;
  59. double ymaxint = System.Math.Floor((yminint + 0.25) * 100) / 100;
  60.  
  61. double yboxminint = 0.0;
  62. if (!usePay)
  63. yboxminint = 0.45;
  64. mainjson = mainjson.Replace("{ymax}", ymaxint.ToString()).Replace("{xmax}", xmaxint.ToString()).Replace("{yboxmin}", yboxminint.ToString());
  65. }
  66.  
  67. void Unload()
  68. {
  69. foreach (ToolRemover toolremover in Resources.FindObjectsOfTypeAll<ToolRemover>())
  70. {
  71. GameObject.Destroy(toolremover);
  72. }
  73. }
  74.  
  75. private static Dictionary<string, string> displaynameToShortname = new Dictionary<string, string>();
  76. private static Dictionary<string, int> deployedToItem = new Dictionary<string, int>();
  77. private void InitializeTable()
  78. {
  79. displaynameToShortname.Clear();
  80. deployedToItem.Clear();
  81. List<ItemDefinition> ItemsDefinition = ItemManager.GetItemDefinitions() as List<ItemDefinition>;
  82. foreach (ItemDefinition itemdef in ItemsDefinition)
  83. {
  84. displaynameToShortname.Add(itemdef.displayName.english.ToString().ToLower(), itemdef.shortname.ToString());
  85. if (itemdef.GetComponent<ItemModDeployable>() != null) deployedToItem.Add(itemdef.GetComponent<ItemModDeployable>().entityPrefab.resourcePath, itemdef.itemid);
  86. }
  87. }
  88.  
  89. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  90. /// Configs
  91. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  92.  
  93. protected override void LoadDefaultConfig() { }
  94.  
  95. private void CheckCfg<T>(string Key, ref T var)
  96. {
  97. if (Config[Key] is T)
  98. var = (T)Config[Key];
  99. else
  100. Config[Key] = var;
  101. }
  102.  
  103. static string xmin = "0.1";
  104. static string xmax = "0.4";
  105. static string ymin = "0.65";
  106. static string ymax = "0.90";
  107.  
  108. static int RemoveTimeDefault = 30;
  109. static int MaxRemoveTime = 120;
  110. static int playerDistanceRemove = 3;
  111. static int adminDistanceRemove = 20;
  112. static int allDistanceRemove = 300;
  113.  
  114. static int adminAuthLevel = 1;
  115. static int playerAuthLevel = 0;
  116. static string normalPermission = "removertool.canremove";
  117. static string adminPermission = "removertool.canremoveadmin";
  118. static string allPermission = "removertool.canremoveall";
  119. static string targetPermission = "removertool.canremovetarget";
  120.  
  121. static bool useBuildingOwners = true;
  122. static bool useBuilt = true;
  123. static bool useRustIO = false;
  124. static bool useToolCupboard = false;
  125.  
  126. static bool useRaidBlocker = true;
  127. static int RaidBlockerTime = 300;
  128. static int RaidBlockerRadius = 80;
  129.  
  130. static Dictionary<string, object> allowedDeployables = defaultDeployables();
  131.  
  132. static bool usePay = true;
  133. static bool PayWithXP = false;
  134. static bool payDeployable = true;
  135. static bool payStructure = true;
  136. static Dictionary<string, object> payForRemove = defaultPay();
  137.  
  138. static bool useRefund = true;
  139. static bool refundDeployable = true;
  140. static bool refundStructure = true;
  141. static Dictionary<string, object> refundPercentage = defaultRefund();
  142.  
  143. static string MessageErrorNoAccess = "You are not allowed to use this command";
  144. static string MessageMultiplePlayersFound = "Multiple players found";
  145. static string MessageNoPlayersFound = "No players found";
  146. static string MessageTargetRemoveEnded = "The Remover Tool for {0} has ended";
  147. static string MessageErrorNothingToRemove = "Couldn't find anything to remove. Are you close enough?";
  148. static string MessageErrorNotAllowedToRemove = "You have no rights to remove this";
  149. static string MessageErrorNotEnoughPay = "You don't have enough to pay for this remove";
  150. static string MessageErrorExternalBlock = "You are not allowed use the remover tool at the moment";
  151. static string MessageOverrideDisabled = "The remover tool was disabled for the time being.";
  152. static string MessageToolDeactivated = "{0}: Remover Tool Deactivated";
  153. static string MessageRaidBlocked = "RaidBlocker: You need to wait for {0}s before being allowed to remove again";
  154. static string MessageErrorCantUseRemoveWithItem = "You can't use the remover tool while you are holding an item";
  155. static string MessageErrorUnvalidDeployable = "This Deployable is not valid for removal";
  156. static string MessageErrorRestrictedDeployable = "This deployable has been restricted from being removed";
  157.  
  158. void Init()
  159. {
  160. CheckCfg<bool>("Remove - RaidBlocker", ref useRaidBlocker);
  161. CheckCfg<int>("Remove - RaidBlocker - Time To Block", ref RaidBlockerTime);
  162. CheckCfg<int>("Remove - RaidBlocker - Radius To Block", ref RaidBlockerRadius);
  163.  
  164. CheckCfg<string>("GUI - Position - X Min", ref xmin);
  165. CheckCfg<string>("GUI - Position - Y Min", ref ymin);
  166.  
  167. CheckCfg<int>("Remove - Default Time", ref RemoveTimeDefault);
  168. CheckCfg<int>("Remove - Max Remove Time", ref MaxRemoveTime);
  169. if (MaxRemoveTime > 300)
  170. {
  171. Debug.Log("RemoverTool: Sorry but i won't let you use the Max Remove Time for longer then 300seconds");
  172. MaxRemoveTime = 300;
  173. }
  174. CheckCfg<int>("Remove - Distance - Player", ref playerDistanceRemove);
  175. CheckCfg<int>("Remove - Distance - Admin", ref adminDistanceRemove);
  176. CheckCfg<int>("Remove - Distance - All", ref allDistanceRemove);
  177.  
  178. CheckCfg<int>("Remove - Auth - AuthLevel - Normal Remove", ref playerAuthLevel);
  179. CheckCfg<int>("Remove - Auth - AuthLevel - Admin Commands", ref adminAuthLevel);
  180. CheckCfg<string>("Remove - Auth - Permission - Normal Remove", ref normalPermission);
  181. CheckCfg<string>("Remove - Auth - Permission - Admin Remove", ref adminPermission);
  182. CheckCfg<string>("Remove - Auth - Permission - All Remove", ref allPermission);
  183. CheckCfg<string>("Remove - Auth - Permission - Target Remove", ref targetPermission);
  184.  
  185. CheckCfg<bool>("Remove - Access - Allow Remove If Building Owner (Need Building Owners)", ref useBuildingOwners);
  186. CheckCfg<bool>("Remove - Access - Allow Remove If Built Entity But Not Building Owner (No Other Plugins Required)", ref useBuilt);
  187. CheckCfg<bool>("Remove - Access - Allow Remove If Friend Of Building Owner (Need Building Owners + RustIO)", ref useRustIO);
  188. CheckCfg<bool>("Remove - Access - Allow Remove If Access To All Cupboards Surrounding", ref useToolCupboard);
  189.  
  190. CheckCfg<string>("Message - Not Allowed", ref MessageErrorNoAccess);
  191. CheckCfg<string>("Message - Multiple Players Found", ref MessageMultiplePlayersFound);
  192. CheckCfg<string>("Message - No Players Found", ref MessageNoPlayersFound);
  193. CheckCfg<string>("Message - Target Remover Tool Ended", ref MessageTargetRemoveEnded);
  194. CheckCfg<string>("Message - Nothing To Remove", ref MessageErrorNothingToRemove);
  195. CheckCfg<string>("Message - No Rights To Remove This", ref MessageErrorNotAllowedToRemove);
  196. CheckCfg<string>("Message - Not Enough To Pay", ref MessageErrorNotEnoughPay);
  197. CheckCfg<string>("Message - External Plugin Blocking Remove", ref MessageErrorExternalBlock);
  198. CheckCfg<string>("Message - Admin Override Disabled the Remover Tool", ref MessageOverrideDisabled);
  199. CheckCfg<string>("Message - Remover Tool Ended", ref MessageToolDeactivated);
  200. CheckCfg<string>("Message - Raid Blocked", ref MessageRaidBlocked);
  201. CheckCfg<string>("Message - Cant Use Remove With Item", ref MessageErrorCantUseRemoveWithItem);
  202.  
  203.  
  204. CheckCfg<Dictionary<string, object>>("Remove - Allow - Deployables", ref allowedDeployables);
  205.  
  206. CheckCfg<bool>("Remove - Pay", ref usePay);
  207. CheckCfg<bool>("Remove - Pay - XP", ref PayWithXP);
  208. CheckCfg<bool>("Remove - Pay - Deployables", ref payDeployable);
  209. CheckCfg<bool>("Remove - Pay - Structures", ref payStructure);
  210. CheckCfg<Dictionary<string, object>>("Remove - Pay - Costs", ref payForRemove);
  211.  
  212. CheckCfg<bool>("Remove - Refund", ref useRefund);
  213. CheckCfg<bool>("Remove - Refund - Deployables", ref refundDeployable);
  214. CheckCfg<bool>("Remove - Refund - Structures", ref refundStructure);
  215. CheckCfg<Dictionary<string, object>>("Remove - Refund - Percentage (Structures Only)", ref refundPercentage);
  216.  
  217. SaveConfig();
  218. }
  219.  
  220. static Dictionary<string, object> defaultDeployables()
  221. {
  222. var dp = new Dictionary<string, object>();
  223.  
  224. List<ItemDefinition> ItemsDefinition = ItemManager.GetItemDefinitions() as List<ItemDefinition>;
  225. foreach (ItemDefinition itemdef in ItemsDefinition)
  226. {
  227. if (itemdef.GetComponent<ItemModDeployable>() != null)
  228. {
  229. dp.Add(itemdef.GetComponent<ItemModDeployable>().entityPrefab.resourcePath, true);
  230. }
  231. }
  232.  
  233. return dp;
  234. }
  235.  
  236. static Dictionary<string, object> defaultPay()
  237. {
  238. var dp = new Dictionary<string, object>()
  239. {
  240. {"0", new Dictionary<string,object>
  241. {
  242. {"wood","1" }
  243. }
  244. },
  245. {"1", new Dictionary<string,object>
  246. {
  247. {"wood","100" }
  248. }
  249. },
  250. {"2", new Dictionary<string,object>
  251. {
  252. {"wood","100" },
  253. {"stones","150" }
  254. }
  255. },
  256. {"3", new Dictionary<string,object>
  257. {
  258. {"wood","100" },
  259. {"stones","50" },
  260. {"metal fragments","75" }
  261. }
  262. },
  263. {"4", new Dictionary<string,object>
  264. {
  265. {"wood","250" },
  266. {"stones","350" },
  267. {"metal fragments","75" },
  268. {"high quality metal","25" }
  269. }
  270. }
  271. };
  272.  
  273. foreach (var itemdef in ItemManager.GetItemDefinitions())
  274. {
  275. if (itemdef.GetComponent<ItemModDeployable>() == null) continue;
  276. dp.Add(itemdef.GetComponent<ItemModDeployable>().entityPrefab.resourcePath, new Dictionary<string, object>() { { "wood", "50" } });
  277. }
  278.  
  279. return dp;
  280. }
  281.  
  282. static Dictionary<string, object> defaultRefund()
  283. {
  284. return new Dictionary<string, object>()
  285. {
  286. {"0","100.0" },
  287. {"1","80.0" },
  288. {"2","60.0" },
  289. {"3","40.0" },
  290. {"4","20.0" }
  291. };
  292. }
  293.  
  294.  
  295. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  296. /// RustIO Inclusion
  297. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  298.  
  299. private static Library RustIO;
  300. private static MethodInfo isInstalled;
  301. private static MethodInfo hasFriend;
  302.  
  303. private static bool RustIOIsInstalled()
  304. {
  305. if (RustIO == null) return false;
  306. return (bool)isInstalled.Invoke(RustIO, new object[] { });
  307. }
  308. private void InitializeRustIO()
  309. {
  310. if (!useRustIO)
  311. {
  312. RustIO = null;
  313. return;
  314. }
  315. RustIO = Interface.GetMod().GetLibrary<Library>("RustIO");
  316. if (RustIO == null || (isInstalled = RustIO.GetFunction("IsInstalled")) == null || (hasFriend = RustIO.GetFunction("HasFriend")) == null)
  317. {
  318. RustIO = null;
  319. Puts("{0}: {1}", Title, "Rust:IO is not present. You need to install Rust:IO first in order to use the RustIO option!");
  320. }
  321. }
  322. private static bool HasFriend(string playerId, string friendId)
  323. {
  324. if (RustIO == null) return false;
  325. return (bool)hasFriend.Invoke(RustIO, new object[] { playerId, friendId });
  326. }
  327.  
  328. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  329. /// Random Functions
  330. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  331.  
  332. bool hasAccess(BasePlayer player, string permissionName, int minimumAuth)
  333. {
  334. if (player.net.connection.authLevel >= minimumAuth) return true;
  335. if (permission.UserHasPermission(player.userID.ToString(), permissionName)) return true;
  336. SendReply(player, MessageErrorNoAccess);
  337. return false;
  338. }
  339.  
  340. object FindOnlinePlayer(string arg, out BasePlayer playerFound)
  341. {
  342. playerFound = null;
  343.  
  344. ulong steamid = 0L;
  345. ulong.TryParse(arg, out steamid);
  346. string lowerarg = arg.ToLower();
  347.  
  348. foreach (BasePlayer player in BasePlayer.activePlayerList)
  349. {
  350. if (steamid != 0L)
  351. if (player.userID == steamid)
  352. {
  353. playerFound = player;
  354. return true;
  355. }
  356. string lowername = player.displayName.ToLower();
  357. if (lowername.Contains(lowerarg))
  358. {
  359. if (playerFound == null)
  360. playerFound = player;
  361. else
  362. return MessageMultiplePlayersFound;
  363. }
  364. }
  365. if (playerFound == null) return MessageNoPlayersFound;
  366. return true;
  367. }
  368.  
  369. static void PrintToChat(BasePlayer player, string message)
  370. {
  371. player.SendConsoleCommand("chat.add", new object[] { 0, message, 1f });
  372. }
  373.  
  374. static BaseEntity FindRemoveObject(Ray ray, float distance)
  375. {
  376. RaycastHit hit;
  377. if (!UnityEngine.Physics.Raycast(ray, out hit, distance, constructionColl))
  378. return null;
  379. return hit.GetEntity();
  380. }
  381.  
  382. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  383. /// class Tool Remover
  384. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  385.  
  386. class ToolRemover : MonoBehaviour
  387. {
  388. public BasePlayer player;
  389. public int endTime;
  390. public int timeLeft;
  391. public RemoveType removeType;
  392. public BasePlayer playerActivator;
  393. public float distance;
  394. public float lastUpdate;
  395.  
  396. public InputState inputState;
  397.  
  398. void Awake()
  399. {
  400. player = GetComponent<BasePlayer>();
  401. lastUpdate = UnityEngine.Time.realtimeSinceStartup;
  402. }
  403.  
  404. public void RefreshDestroy()
  405. {
  406. timeLeft = endTime;
  407. CancelInvoke("DoDestroy");
  408. CancelInvoke("RefreshRemoveGui");
  409. Invoke("DoDestroy", endTime);
  410. InvokeRepeating("RefreshRemoveGui", 1, 1);
  411. DestroyGUI(player);
  412. NewGUI(this);
  413. }
  414.  
  415. void DoDestroy()
  416. {
  417. GameObject.Destroy(this);
  418. }
  419.  
  420. void RefreshRemoveGui()
  421. {
  422. timeLeft--;
  423. RefreshGUI(this);
  424. }
  425.  
  426. void FixedUpdate()
  427. {
  428. if (!player.IsConnected() || player.IsDead()) { GameObject.Destroy(this); return; }
  429. inputState = serverinput.GetValue(player) as InputState;
  430. if (inputState.WasJustPressed(BUTTON.FIRE_PRIMARY))
  431. {
  432. float currentTime = UnityEngine.Time.realtimeSinceStartup;
  433. if (lastUpdate + 0.5f < currentTime)
  434. {
  435. lastUpdate = currentTime;
  436. if (player.GetActiveItem() != null)
  437. {
  438. PrintToChat(player, MessageErrorCantUseRemoveWithItem);
  439. return;
  440. }
  441. Ray ray = new Ray(player.eyes.position, Quaternion.Euler(inputState.current.aimAngles) * Vector3.forward);
  442. TryRemove(player, ray, removeType, distance);
  443. }
  444. }
  445. }
  446.  
  447. void OnDestroy()
  448. {
  449. DestroyGUI(player);
  450. if (playerActivator != player)
  451. {
  452. if (playerActivator.IsConnected())
  453. PrintToChat(playerActivator, string.Format(MessageTargetRemoveEnded, player.displayName));
  454. }
  455. }
  456. }
  457. void EndRemoverTool(BasePlayer player)
  458. {
  459. ToolRemover toolremover = player.GetComponent<ToolRemover>();
  460. if (toolremover == null) return;
  461. GameObject.Destroy(toolremover);
  462. }
  463. static void DestroyGUI(BasePlayer player)
  464. {
  465. if (player.net == null) return;
  466. Oxide.Game.Rust.Cui.CuiHelper.DestroyUi(player, "RemoveMsg");
  467. }
  468. static void NewGUI(ToolRemover toolremover)
  469. {
  470. BasePlayer player = toolremover.player;
  471. CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "AddUI", new Facepunch.ObjectList(mainjson, null, null, null, null));
  472. CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "AddUI", new Facepunch.ObjectList(timeleftjsonheader, null, null, null, null));
  473. CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "AddUI", new Facepunch.ObjectList(titlejson.Replace("{removeType}", toolremover.removeType == RemoveType.Normal ? string.Empty : toolremover.removeType == RemoveType.Admin ? "(Admin)" : "(All)"), null, null, null, null));
  474. CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "AddUI", new Facepunch.ObjectList(entityjsonheader, null, null, null, null));
  475. if (usePay)
  476. CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "AddUI", new Facepunch.ObjectList(costjsonheader, null, null, null, null));
  477. }
  478. static void RefreshGUI(ToolRemover toolPlayer)
  479. {
  480. Oxide.Game.Rust.Cui.CuiHelper.DestroyUi(toolPlayer.player, "RemoveTimeleftMsg");
  481. Oxide.Game.Rust.Cui.CuiHelper.DestroyUi(toolPlayer.player, "RemoveEntityMsg");
  482. Oxide.Game.Rust.Cui.CuiHelper.DestroyUi(toolPlayer.player, "RemoveCostMsg");
  483. string cost = string.Empty;
  484. string entity = string.Empty;
  485.  
  486. toolPlayer.inputState = serverinput.GetValue(toolPlayer.player) as InputState;
  487. Ray ray = new Ray(toolPlayer.player.eyes.position, Quaternion.Euler(toolPlayer.inputState.current.aimAngles) * Vector3.forward);
  488.  
  489. BaseEntity removeObject = FindRemoveObject(ray, toolPlayer.distance);
  490. if (removeObject != null)
  491. {
  492. entity = removeObject.ToString();
  493. entity = entity.Substring(entity.LastIndexOf("/") + 1).Replace(".prefab", "").Replace("_deployed", "").Replace(".deployed", "");
  494. entity = entity.Substring(0, entity.IndexOf("["));
  495. if (usePay && toolPlayer.removeType == RemoveType.Normal)
  496. {
  497. if (!PayWithXP)
  498. {
  499. Dictionary<string, object> costList = GetCost(removeObject);
  500. foreach (KeyValuePair<string, object> pair in costList)
  501. {
  502. cost += string.Format("{0} x{1}\n", pair.Key, pair.Value.ToString());
  503. }
  504. }
  505. else
  506. {
  507. cost = "1";
  508. }
  509. }
  510. }
  511. string ejson = entityjsonmsg.Replace("{entity}", entity);
  512. string cjson = costjsonmsg.Replace("{cost}", cost);
  513. string tjson = timeleftjsonmsg.Replace("{timeleft}", toolPlayer.timeLeft.ToString());
  514. CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = toolPlayer.player.net.connection }, null, "AddUI", new Facepunch.ObjectList(ejson, null, null, null, null));
  515. if (usePay)
  516. CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = toolPlayer.player.net.connection }, null, "AddUI", new Facepunch.ObjectList(cjson, null, null, null, null));
  517.  
  518. CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = toolPlayer.player.net.connection }, null, "AddUI", new Facepunch.ObjectList(tjson, null, null, null, null));
  519. }
  520.  
  521. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  522. /// GUI
  523. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  524. public static string mainjson = @"[
  525. {
  526. ""name"": ""RemoveMsg"",
  527. ""parent"": ""Overlay"",
  528. ""components"":
  529. [
  530. {
  531. ""type"":""UnityEngine.UI.Image"",
  532. ""color"":""0 0 0 0"",
  533. },
  534. {
  535. ""type"":""RectTransform"",
  536. ""anchormin"": ""{xmin} {ymin}"",
  537. ""anchormax"": ""{xmax} {ymax}""
  538. }
  539. ]
  540. },
  541. {
  542. ""parent"": ""RemoveMsg"",
  543. ""components"":
  544. [
  545. {
  546. ""type"":""UnityEngine.UI.Image"",
  547. ""color"":""0.1 0.1 0.1 0.4"",
  548. },
  549. {
  550. ""type"":""RectTransform"",
  551. ""anchormin"": ""0 {yboxmin}"",
  552. ""anchormax"": ""1 1""
  553. }
  554. ]
  555. }
  556. ]
  557. ";
  558. public static string titlejson = @"[
  559. {
  560. ""parent"": ""RemoveMsg"",
  561. ""components"":
  562. [
  563. {
  564. ""type"":""UnityEngine.UI.Text"",
  565. ""text"":""<color=red>Remover Tool {removeType}</color>"",
  566. ""fontSize"":15,
  567. ""align"": ""MiddleCenter"",
  568. },
  569. {
  570. ""type"":""RectTransform"",
  571. ""anchormin"": ""0.0 0.83"",
  572. ""anchormax"": ""1.0 0.98""
  573. }
  574. ]
  575. }
  576. ]
  577. ";
  578. public static string timeleftjsonheader = @"[
  579. {
  580. ""parent"": ""RemoveMsg"",
  581. ""components"":
  582. [
  583. {
  584. ""type"":""UnityEngine.UI.Text"",
  585. ""text"":""Time left"",
  586. ""fontSize"":15,
  587. ""align"": ""MiddleLeft"",
  588. },
  589. {
  590. ""type"":""RectTransform"",
  591. ""anchormin"": ""0.05 0.65"",
  592. ""anchormax"": ""0.3 0.80""
  593. }
  594. ]
  595. }
  596. ]
  597. ";
  598. public static string timeleftjsonmsg = @"[
  599. {
  600. ""name"": ""RemoveTimeleftMsg"",
  601. ""parent"": ""RemoveMsg"",
  602. ""components"":
  603. [
  604. {
  605. ""type"":""UnityEngine.UI.Text"",
  606. ""text"":""{timeleft}s"",
  607. ""fontSize"":15,
  608. ""align"": ""MiddleLeft"",
  609. },
  610. {
  611. ""type"":""RectTransform"",
  612. ""anchormin"": ""0.4 0.65"",
  613. ""anchormax"": ""1.0 0.80""
  614. }
  615. ]
  616. }
  617. ]
  618. ";
  619. public static string entityjsonheader = @"[
  620. {
  621. ""parent"": ""RemoveMsg"",
  622. ""components"":
  623. [
  624. {
  625. ""type"":""UnityEngine.UI.Text"",
  626. ""text"":""Entity"",
  627. ""fontSize"":15,
  628. ""align"": ""MiddleLeft"",
  629. },
  630. {
  631. ""type"":""RectTransform"",
  632. ""anchormin"": ""0.05 0.50"",
  633. ""anchormax"": ""0.3 0.65""
  634. }
  635. ]
  636. }
  637. ]
  638. ";
  639. public static string entityjsonmsg = @"[
  640. {
  641. ""name"": ""RemoveEntityMsg"",
  642. ""parent"": ""RemoveMsg"",
  643. ""components"":
  644. [
  645. {
  646. ""type"":""UnityEngine.UI.Text"",
  647. ""text"":""{entity}"",
  648. ""fontSize"":15,
  649. ""align"": ""MiddleLeft"",
  650. },
  651. {
  652. ""type"":""RectTransform"",
  653. ""anchormin"": ""0.4 0.50"",
  654. ""anchormax"": ""1.0 0.65""
  655. }
  656. ]
  657. }
  658. ]
  659. ";
  660. public static string costjsonheader = @"[
  661. {
  662. ""parent"": ""RemoveMsg"",
  663. ""components"":
  664. [
  665. {
  666. ""type"":""UnityEngine.UI.Text"",
  667. ""text"":""Cost"",
  668. ""fontSize"":15,
  669. ""align"": ""MiddleLeft"",
  670. },
  671. {
  672. ""type"":""RectTransform"",
  673. ""anchormin"": ""0.05 0.0"",
  674. ""anchormax"": ""0.3 0.50""
  675. }
  676. ]
  677. }
  678. ]
  679. ";
  680. public static string costjsonmsg = @"[
  681. {
  682. ""name"": ""RemoveCostMsg"",
  683. ""parent"": ""RemoveMsg"",
  684. ""components"":
  685. [
  686. {
  687. ""type"":""UnityEngine.UI.Text"",
  688. ""text"":""{cost}"",
  689. ""fontSize"":15,
  690. ""align"": ""MiddleLeft"",
  691. },
  692. {
  693. ""type"":""RectTransform"",
  694. ""anchormin"": ""0.4 0.0"",
  695. ""anchormax"": ""1.0 0.5""
  696. }
  697. ]
  698. }
  699. ]
  700. ";
  701.  
  702. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  703. /// Remove functions
  704. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  705. static void TryRemove(BasePlayer player, Ray ray, RemoveType removeType, float distance)
  706. {
  707. BaseEntity removeObject = FindRemoveObject(ray, distance);
  708. if (removeObject == null)
  709. {
  710. PrintToChat(player, MessageErrorNothingToRemove);
  711. return;
  712. }
  713. var success = CanRemoveEntity(player, removeObject, removeType);
  714. if (success is string)
  715. {
  716. PrintToChat(player, (string)success);
  717. return;
  718. }
  719. if (usePay && !CanPay(player, removeObject, removeType))
  720. {
  721. PrintToChat(player, MessageErrorNotEnoughPay);
  722. return;
  723. }
  724. if (removeType == RemoveType.All)
  725. {
  726. Interface.Call("RemoveAllFrom", removeObject.transform.position);
  727. return;
  728. }
  729. if (usePay)
  730. {
  731. Pay(player, removeObject, removeType);
  732. }
  733. if (useRefund)
  734. Refund(player, removeObject, removeType);
  735. DoRemove(removeObject);
  736.  
  737. }
  738.  
  739. List<Vector3> removeFrom = new List<Vector3>();
  740. int currentRemove = 0;
  741. void RemoveAllFrom(Vector3 pos)
  742. {
  743. removeFrom.Add(pos);
  744. DelayRemoveAll();
  745. }
  746.  
  747. List<BaseEntity> wasRemoved = new List<BaseEntity>();
  748. void DelayRemoveAll()
  749. {
  750. if (currentRemove >= removeFrom.Count)
  751. {
  752. currentRemove = 0;
  753. removeFrom.Clear();
  754. wasRemoved.Clear();
  755. return;
  756. }
  757. List<BaseEntity> list = Pool.GetList<BaseEntity>();
  758. Vis.Entities<BaseEntity>(removeFrom[currentRemove], 3f, list, constructionColl);
  759. for (int i = 0; i < list.Count; i++)
  760. {
  761. BaseEntity ent = list[i];
  762. if (wasRemoved.Contains(ent)) continue;
  763. if (!removeFrom.Contains(ent.transform.position))
  764. removeFrom.Add(ent.transform.position);
  765. wasRemoved.Add(ent);
  766. DoRemove(ent);
  767. }
  768. currentRemove++;
  769. timer.Once(0.01f, () => DelayRemoveAll());
  770. }
  771.  
  772. static void DoRemove(BaseEntity removeObject)
  773. {
  774. if (removeObject == null) return;
  775. Interface.Oxide.CallHook("OnRemovedEntity", removeObject);
  776. removeObject.KillMessage();
  777. }
  778.  
  779. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  780. /// Refund
  781. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  782. static void Refund(BasePlayer player, BaseEntity entity, RemoveType removeType)
  783. {
  784. if (removeType == RemoveType.All) return;
  785. if (refundDeployable && entity.GetComponentInParent<Deployable>() != null)
  786. {
  787. Deployable worlditem = entity.GetComponentInParent<Deployable>();
  788. if (deployedToItem.ContainsKey(worlditem.gameObject.name))
  789. player.inventory.GiveItem(ItemManager.CreateByItemID(deployedToItem[worlditem.gameObject.name], 1));
  790. }
  791. else if (refundStructure && entity is BuildingBlock)
  792. {
  793. BuildingBlock buildingblock = entity as BuildingBlock;
  794. if (buildingblock.blockDefinition == null) return;
  795.  
  796. int buildingblockGrade = (int)buildingblock.grade;
  797. if (buildingblock.blockDefinition.grades[buildingblockGrade] != null && refundPercentage.ContainsKey(buildingblockGrade.ToString()))
  798. {
  799. decimal refundRate = decimal.Parse((string)refundPercentage[buildingblockGrade.ToString()]) / 100.0m;
  800. List<ItemAmount> currentCost = buildingblock.blockDefinition.grades[buildingblockGrade].costToBuild as List<ItemAmount>;
  801. foreach (ItemAmount ia in currentCost)
  802. {
  803. player.inventory.GiveItem(ItemManager.CreateByItemID(ia.itemid, Convert.ToInt32((decimal)ia.amount * refundRate)));
  804. }
  805. }
  806. }
  807. }
  808.  
  809. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  810. /// Check Access
  811. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  812. static bool hasTotalAccess(BasePlayer player)
  813. {
  814. List<BuildingPrivlidge> playerpriv = buildingPrivlidges.GetValue(player) as List<BuildingPrivlidge>;
  815. if (playerpriv.Count == 0)
  816. {
  817. return false;
  818. }
  819. foreach (BuildingPrivlidge priv in playerpriv.ToArray())
  820. {
  821. List<ProtoBuf.PlayerNameID> authorized = priv.authorizedPlayers;
  822. bool foundplayer = false;
  823. foreach (ProtoBuf.PlayerNameID pni in authorized.ToArray())
  824. {
  825. if (pni.userid == player.userID)
  826. foundplayer = true;
  827. }
  828. if (!foundplayer)
  829. {
  830. return false;
  831. }
  832. }
  833. return true;
  834. }
  835.  
  836. static object CanRemoveEntity(BasePlayer player, BaseEntity entity, RemoveType removeType)
  837. {
  838. if (entity.isDestroyed) return "Entity is already destroyed";
  839. if (removeType == RemoveType.Admin || removeType == RemoveType.All) return true;
  840. var externalPlugins = Interface.CallHook("canRemove", player);
  841. if (externalPlugins != null)
  842. return externalPlugins is string ? (string)externalPlugins : MessageErrorExternalBlock;
  843. if (raidBlockedPlayers[player] != null)
  844. {
  845. if (raidBlockedPlayers[player] > UnityEngine.Time.realtimeSinceStartup)
  846. return string.Format(MessageRaidBlocked, Mathf.Ceil(raidBlockedPlayers[player] - UnityEngine.Time.realtimeSinceStartup).ToString());
  847. raidBlockedPlayers.Remove(player);
  848. }
  849. var buildingBlock = entity.GetComponent<BuildingBlock>();
  850. var deployable = entity.GetComponent<Deployable>();
  851.  
  852. if(buildingBlock)
  853. {
  854. if(useBuilt)
  855. {
  856. if (buildingBlock.OwnerID == player.userID) return true;
  857. if (useRustIO && RustIOIsInstalled())
  858. if (HasFriend(buildingBlock.OwnerID.ToString(), player.userID.ToString()))
  859. return true;
  860. }
  861. if(useBuildingOwners)
  862. {
  863. var returnhook = Interface.GetMod().CallHook("FindBlockData", new object[] { entity.GetComponent<BuildingBlock>() });
  864. if (returnhook is string)
  865. {
  866. string ownerid = (string)returnhook;
  867. if (player.userID.ToString() == ownerid) return true;
  868. if (useRustIO && RustIOIsInstalled())
  869. if (HasFriend(ownerid, player.userID.ToString()))
  870. return true;
  871. }
  872. }
  873. }
  874. else if (deployable)
  875. {
  876. if (!allowedDeployables.ContainsKey(entity.PrefabName)) return MessageErrorUnvalidDeployable;
  877. if (!(bool)allowedDeployables[entity.PrefabName]) return MessageErrorRestrictedDeployable;
  878.  
  879. if (useBuilt)
  880. {
  881. if (entity.OwnerID == player.userID) return true;
  882. if (useRustIO && RustIOIsInstalled())
  883. if (HasFriend(entity.OwnerID.ToString(), player.userID.ToString()))
  884. return true;
  885. }
  886. if (useBuildingOwners)
  887. {
  888. RaycastHit supportHit;
  889. if (Physics.Raycast(entity.transform.position + new Vector3(0f, 0.1f, 0f), new Vector3(0f, -1f, 0f), out supportHit, 3f, blockColl))
  890. {
  891. BaseEntity supportEnt = supportHit.GetEntity();
  892. if (supportEnt != null)
  893. {
  894. BuildingBlock supportBlock = supportEnt.GetComponent<BuildingBlock>();
  895. if (supportBlock != null)
  896. {
  897. var returnhook = Interface.GetMod().CallHook("FindBlockData", new object[] { supportBlock });
  898. if (returnhook is string)
  899. {
  900. string ownerid = (string)returnhook;
  901. if (player.userID.ToString() == ownerid) return true;
  902. if (useRustIO && RustIOIsInstalled())
  903. if (HasFriend(ownerid, player.userID.ToString()))
  904. return true;
  905. }
  906. }
  907. }
  908. }
  909. }
  910. }
  911. if (useToolCupboard)
  912. if (hasTotalAccess(player))
  913. return true;
  914.  
  915. return MessageErrorNotAllowedToRemove;
  916. }
  917. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  918. /// Pay functions
  919. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  920. static void Pay(BasePlayer player, BaseEntity entity, RemoveType removeType)
  921. {
  922. if (removeType == RemoveType.Admin || removeType == RemoveType.All) return;
  923. if (!PayWithXP)
  924. {
  925. Dictionary<string, object> cost = GetCost(entity);
  926. List<Item> collect = new List<Item>();
  927. foreach (KeyValuePair<string, object> pair in cost)
  928. {
  929. string itemname = pair.Key.ToLower();
  930. if (displaynameToShortname.ContainsKey(itemname))
  931. itemname = displaynameToShortname[itemname];
  932. ItemDefinition itemdef = ItemManager.FindItemDefinition(itemname);
  933. if (itemdef == null) continue;
  934. player.inventory.Take(collect, itemdef.itemid, Convert.ToInt32(pair.Value));
  935. player.Command(string.Format("note.inv {0} -{1}", itemdef.itemid.ToString(), pair.Value.ToString()), new object[0]);
  936. }
  937. foreach (Item item in collect)
  938. {
  939. item.Remove(0f);
  940. }
  941. }
  942. else
  943. {
  944. var unused = player.xp.UnspentXp;
  945. player.xp.Reset();
  946. player.xp.Add(Rust.Xp.Definitions.Cheat, unused - 1);
  947. }
  948. }
  949. static bool CanPay(BasePlayer player, BaseEntity entity, RemoveType removeType)
  950. {
  951. if (removeType == RemoveType.Admin || removeType == RemoveType.All) return true;
  952. if (!PayWithXP)
  953. {
  954. Dictionary<string, object> cost = GetCost(entity);
  955.  
  956. foreach (KeyValuePair<string, object> pair in cost)
  957. {
  958. string itemname = pair.Key.ToLower();
  959. if (displaynameToShortname.ContainsKey(itemname))
  960. itemname = displaynameToShortname[itemname];
  961. ItemDefinition itemdef = ItemManager.FindItemDefinition(itemname);
  962. if (itemdef == null) continue;
  963. int amount = player.inventory.GetAmount(itemdef.itemid);
  964. if (amount < Convert.ToInt32(pair.Value))
  965. return false;
  966. }
  967. }
  968. else
  969. {
  970. if (Mathf.FloorToInt(player.xp.UnspentXp) >= 1)
  971. {
  972. return true;
  973. }
  974. return false;
  975. }
  976. return true;
  977. }
  978. static Dictionary<string, object> GetCost(BaseEntity entity)
  979. {
  980. Dictionary<string, object> cost = new Dictionary<string, object>();
  981. if (entity.GetComponent<BuildingBlock>() != null)
  982. {
  983. BuildingBlock block = entity.GetComponent<BuildingBlock>();
  984. string grade = ((int)block.grade).ToString();
  985. if (!payForRemove.ContainsKey(grade)) return cost;
  986. cost = payForRemove[grade] as Dictionary<string, object>;
  987. }
  988. else if (entity.GetComponent<Deployable>() != null)
  989. {
  990. if (!payForRemove.ContainsKey(entity.PrefabName)) return cost;
  991. cost = payForRemove[entity.PrefabName] as Dictionary<string, object>;
  992. }
  993. return cost;
  994. }
  995.  
  996.  
  997. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  998. /// Raid Blocker
  999. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1000.  
  1001. void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
  1002. {
  1003. if (!useRaidBlocker) return;
  1004. if (info == null) return;
  1005. BuildingBlock block = entity.GetComponent<BuildingBlock>();
  1006. if (block == null) return;
  1007. if (info.damageTypes.GetMajorityDamageType() == Rust.DamageType.Explosion)
  1008. BlockRemoveFromPlayersAroundPos(entity.transform.position);
  1009. }
  1010.  
  1011. static Hash<BasePlayer, float> raidBlockedPlayers = new Hash<BasePlayer, float>();
  1012. void BlockRemoveFromPlayersAroundPos(Vector3 pos)
  1013. {
  1014. foreach (Collider col in Physics.OverlapSphere(pos, (float)RaidBlockerRadius, playerColl))
  1015. {
  1016. raidBlockedPlayers[col.GetComponentInParent<BasePlayer>()] = UnityEngine.Time.realtimeSinceStartup + (float)RaidBlockerTime;
  1017. }
  1018. }
  1019.  
  1020. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1021. /// Console Commands
  1022. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1023.  
  1024. bool overrideDisabled = false;
  1025.  
  1026.  
  1027. [ConsoleCommand("remove")]
  1028. void cmdConsoleAcCheck(ConsoleSystem.Arg arg)
  1029. {
  1030. if (arg != null && arg.connection != null && arg.connection.player != null)
  1031. {
  1032. BasePlayer player = (BasePlayer)arg.connection.player;
  1033.  
  1034. CheckSpam++;
  1035.  
  1036. PrintWarning(string.Format("[REMOVE]: {0} activated remove count:{1}", player.displayName, CheckSpam));
  1037.  
  1038. if (CheckSpam == 5)
  1039. {
  1040. string reason = "Не стоит так часто нажимать это, а то баном пахнет. Чуешь запах?!";
  1041. Network.Net.sv.Kick(player.net.connection, reason);
  1042. }
  1043.  
  1044. timer.Once(5f, () => { Puts("111111"); CheckSpam = 0; });
  1045.  
  1046.  
  1047.  
  1048. int removeTime = RemoveTimeDefault;
  1049. BasePlayer target = player;
  1050. RemoveType removetype = RemoveType.Normal;
  1051. int distanceRemove = playerDistanceRemove;
  1052.  
  1053.  
  1054. if (removeTime > MaxRemoveTime) removeTime = MaxRemoveTime;
  1055.  
  1056. if (overrideDisabled && removetype == RemoveType.Normal)
  1057. {
  1058. SendReply(player, MessageOverrideDisabled);
  1059. return;
  1060. }
  1061.  
  1062. ToolRemover toolremover = target.GetComponent<ToolRemover>();
  1063. if (toolremover != null)
  1064. {
  1065. EndRemoverTool(target);
  1066. SendReply(player, string.Format(MessageToolDeactivated, target.displayName));
  1067. return;
  1068. }
  1069.  
  1070. if (toolremover == null)
  1071. toolremover = target.gameObject.AddComponent<ToolRemover>();
  1072.  
  1073. toolremover.endTime = removeTime;
  1074. toolremover.removeType = removetype;
  1075. toolremover.playerActivator = player;
  1076. toolremover.distance = (int)distanceRemove;
  1077. toolremover.RefreshDestroy();
  1078.  
  1079. }
  1080.  
  1081. }
  1082.  
  1083.  
  1084.  
  1085. [ConsoleCommand("remove.allow")]
  1086. void ccmdRemoveAllow(ConsoleSystem.Arg arg)
  1087. {
  1088. if (arg.Args == null || arg.Args.Length == 0)
  1089. {
  1090. SendReply(arg, "remove.allow true/false");
  1091. return;
  1092. }
  1093. if (arg.connection != null)
  1094. {
  1095. if (!hasAccess(arg.connection.player as BasePlayer, adminPermission, adminAuthLevel)) return;
  1096. {
  1097. SendReply(arg, MessageErrorNoAccess);
  1098. return;
  1099. }
  1100. }
  1101. switch (arg.Args[0].ToLower())
  1102. {
  1103. case "true":
  1104. case "1":
  1105. overrideDisabled = false;
  1106. SendReply(arg, "Remove is now allowed depending on your settings.");
  1107. break;
  1108. case "false":
  1109. case "0":
  1110. overrideDisabled = true;
  1111. SendReply(arg, "Remove is now restricted for all players (exept admins)");
  1112. foreach (ToolRemover toolremover in Resources.FindObjectsOfTypeAll<ToolRemover>())
  1113. {
  1114. if (toolremover.removeType == RemoveType.Normal)
  1115. {
  1116. SendReply(toolremover.player, "The Remover Tool has been disabled by the admin");
  1117. timer.Once(0.01f, () => GameObject.Destroy(toolremover));
  1118. }
  1119. }
  1120. break;
  1121. default:
  1122. SendReply(arg, "This is not a valid argument");
  1123. break;
  1124. }
  1125. }
  1126.  
  1127. [ConsoleCommand("removertool.remove")]
  1128. void ccmdRemovertoolRemove(ConsoleSystem.Arg arg)
  1129. {
  1130. //
  1131. }
  1132.  
  1133. [ConsoleCommand("remove.give")]
  1134. void ccmdRemoveGive(ConsoleSystem.Arg arg)
  1135. {
  1136. if (arg.Args == null || arg.Args.Length == 0)
  1137. {
  1138. SendReply(arg, "remove.give PLAYER/STEAMID optional:Time");
  1139. return;
  1140. }
  1141. if (arg.connection != null)
  1142. {
  1143. if (!hasAccess(arg.connection.player as BasePlayer, targetPermission, adminAuthLevel)) return;
  1144. }
  1145. BasePlayer targetPlayer;
  1146. var success = FindOnlinePlayer(arg.Args[0], out targetPlayer);
  1147. if (success is string)
  1148. {
  1149. SendReply(arg, (string)success);
  1150. return;
  1151. }
  1152. int removeTime = RemoveTimeDefault;
  1153. if (arg.Args.Length > 1)
  1154. int.TryParse(arg.Args[1], out removeTime);
  1155. if (removeTime > MaxRemoveTime)
  1156. removeTime = MaxRemoveTime;
  1157. ToolRemover toolremover = targetPlayer.GetComponent<ToolRemover>();
  1158. if (toolremover == null)
  1159. toolremover = targetPlayer.gameObject.AddComponent<ToolRemover>();
  1160. toolremover.endTime = removeTime;
  1161. toolremover.removeType = RemoveType.Normal;
  1162. toolremover.playerActivator = targetPlayer;
  1163. toolremover.distance = playerDistanceRemove;
  1164. toolremover.RefreshDestroy();
  1165.  
  1166. SendReply(arg, string.Format("Remover tool was given for {1}s to {0}", targetPlayer.displayName, removeTime.ToString()));
  1167. }
  1168.  
  1169. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1170. /// Chat Command
  1171. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1172.  
  1173. [ChatCommand("remove")]
  1174. void cmdChatRemove(BasePlayer player, string command, string[] args)
  1175. {
  1176. int removeTime = RemoveTimeDefault;
  1177. BasePlayer target = player;
  1178. RemoveType removetype = RemoveType.Normal;
  1179. int distanceRemove = playerDistanceRemove;
  1180.  
  1181. if (args.Length != 0)
  1182. {
  1183. switch (args[0])
  1184. {
  1185. case "admin":
  1186. if (!hasAccess(player, adminPermission, adminAuthLevel)) return;
  1187. removetype = RemoveType.Admin;
  1188. distanceRemove = adminDistanceRemove;
  1189. if (args.Length > 1) int.TryParse(args[1], out removeTime);
  1190. break;
  1191. case "all":
  1192. if (!hasAccess(player, allPermission, adminAuthLevel)) return;
  1193. removetype = RemoveType.All;
  1194. distanceRemove = allDistanceRemove;
  1195. if (args.Length > 1) int.TryParse(args[1], out removeTime);
  1196. break;
  1197. case "target":
  1198. if (!hasAccess(player, targetPermission, adminAuthLevel)) return;
  1199. if (args.Length == 1)
  1200. {
  1201. SendReply(player, "/remove target PLAYERNAME/STEAMID optional:Time");
  1202. return;
  1203. }
  1204. BasePlayer tempTarget = null;
  1205. var success = FindOnlinePlayer(args[1], out tempTarget);
  1206. if (success is string)
  1207. {
  1208. SendReply(player, (string)success);
  1209. return;
  1210. }
  1211. target = tempTarget;
  1212. if (args.Length > 2) int.TryParse(args[2], out removeTime);
  1213.  
  1214. break;
  1215. default:
  1216. if (!hasAccess(player, normalPermission, playerAuthLevel)) return;
  1217. int.TryParse(args[0], out removeTime);
  1218. break;
  1219. }
  1220. }
  1221.  
  1222. if (removeTime > MaxRemoveTime) removeTime = MaxRemoveTime;
  1223.  
  1224. if (overrideDisabled && removetype == RemoveType.Normal)
  1225. {
  1226. SendReply(player, MessageOverrideDisabled);
  1227. return;
  1228. }
  1229.  
  1230. ToolRemover toolremover = target.GetComponent<ToolRemover>();
  1231. if (toolremover != null && args.Length == 0)
  1232. {
  1233. EndRemoverTool(target);
  1234. SendReply(player, string.Format(MessageToolDeactivated, target.displayName));
  1235. return;
  1236. }
  1237.  
  1238. if (toolremover == null)
  1239. toolremover = target.gameObject.AddComponent<ToolRemover>();
  1240.  
  1241. toolremover.endTime = removeTime;
  1242. toolremover.removeType = removetype;
  1243. toolremover.playerActivator = player;
  1244. toolremover.distance = (int)distanceRemove;
  1245. toolremover.RefreshDestroy();
  1246. }
  1247. [HookMethod("SendHelpText")]
  1248. private void SendHelpText(BasePlayer player)
  1249. {
  1250. SendReply(player, "<size=18>Remover Tool</size> by <color=#ce422b>Reneb</color>\n<color=\"#ffd479\">/remove optional:TimerInSeconds</color> - Activate/Deactivate the Remover Tool, You will need to have no highlighted items in your belt bar.");
  1251. }
  1252. }
  1253. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement