Guest User

Untitled

a guest
Sep 26th, 2018
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 45.92 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System;
  4. using Oxide.Core;
  5. using UnityEngine;
  6. using System.Reflection;
  7. using Oxide.Core.Plugins;
  8. namespace Oxide.Plugins {
  9. [Info("AlfredStuff", "Alfred", 0.1)]
  10. [Description("Something")]
  11. public class AlfredStuff : RustPlugin {
  12. [PluginReference]
  13. private Plugin ServerRewards;
  14. private const string BlockedItems = "AlfredStuff.blockeditems";
  15. private const string NoDura = "AlfredStuff.nodura";
  16. private const string NoDura2 = "AlfredPlugins.nodura";
  17. private const string PermStack = "AlfredStuff.stack";
  18. private const string LootProt1 = "AlfredStuff.lootprot";
  19. private const string SetHeliCoordinates = "AlfredStuff.setteleport";
  20. private const string InstaCraft = "AlfredStuff.instacraft";
  21. private const string setTankLocations = "AlfredStuff.settank";
  22. const string tankPrefab = "assets/prefabs/npc/m2bradley/bradleyapc.prefab";
  23. private readonly HashSet<ulong> teleporting = new HashSet<ulong>();
  24. private readonly MethodInfo finishCraftingTask = typeof(ItemCrafter).GetMethod("FinishCrafting", BindingFlags.NonPublic | BindingFlags.Instance);
  25. private static System.Random random = new System.Random();
  26. HashSet<ulong> users = new HashSet<ulong>();
  27. List<BadGuy> badguys = new List<BadGuy>();
  28. List<BadGuy2> badguys2 = new List<BadGuy2>();
  29. List<CritHit> crithit = new List<CritHit>();
  30. List<LootControl> lootcontroll = new List<LootControl>();
  31. List<LootNumberGenerator> uniqueNumber = new List<LootNumberGenerator>();
  32. public List<ulong> cooldown = new List<ulong>();
  33. public Dictionary<ulong, float> cooldownTimer = new Dictionary<ulong, float>();
  34. private int cooldownTime = 1200;
  35. public List<ulong> cooldown2 = new List<ulong>();
  36. public Dictionary<ulong, float> cooldownTimer2 = new Dictionary<ulong, float>();
  37. private int cooldownTime2 = 3600;
  38. int DamageLenght = 7;
  39. string LootBrad = "";
  40. string LootHeli = "";
  41. int LootProt = 1;
  42. string heliLooter;
  43. string bradleyLooter;
  44. ulong uHeliLooter;
  45. ulong uBradLooter;
  46. int he;
  47. int br;
  48. int tankLocation_x;
  49. int tankLocation_y;
  50. int tankLocation_z;
  51. bool activeBradley = true;
  52. bool bradmsg = true;
  53. bool bradBigLvl1 = false;
  54. void OnServerInitialized() {
  55. foreach (var gobject in UnityEngine.Object.FindObjectsOfType<BaseEntity>()) {
  56. var prefabName = gobject?.ShortPrefabName ?? string.Empty;
  57. var bradley = gobject?.GetComponent<BradleyAPC>() ?? null;
  58. }
  59. LoadDefaultConfig();
  60. }
  61. protected override void LoadDefaultConfig() {
  62. tankLocation_x = GetConfig("TankLocation_X", 0);
  63. tankLocation_y = GetConfig("TankLocation_Y", 0);
  64. tankLocation_z = GetConfig("TankLocation_Z", 0);
  65. SaveConfig();
  66. }
  67. void Init() {
  68. permission.RegisterPermission(BlockedItems, this);
  69. permission.RegisterPermission(NoDura, this);
  70. permission.RegisterPermission(PermStack, this);
  71. permission.RegisterPermission(SetHeliCoordinates, this);
  72. permission.RegisterPermission(InstaCraft, this);
  73. permission.RegisterPermission(LootProt1, this);
  74. permission.RegisterPermission(NoDura2, this);
  75. permission.RegisterPermission(setTankLocations, this);
  76. ItemManager.itemList.First(x => x.shortname == "bucket.water").stackable = 50000;
  77. HashSet<ulong> users = Interface.Oxide.DataFileSystem.ReadObject<HashSet<ulong>>("Hits");
  78. this.users = users;
  79. LoadDefaultConfig();
  80. }
  81. int RemoveItemsFromInventory(BasePlayer player, ItemDefinition itemToRemove, int amount) {
  82. List<Item> foundItems = player.inventory.FindItemIDs(itemToRemove.itemid);
  83. int numberFound = foundItems == null ? 0 : foundItems.Sum(item => item.amount);
  84. if (numberFound < amount) amount = numberFound;
  85. int numberRemoved = player.inventory.Take(foundItems, itemToRemove.itemid, amount);
  86. MSG(player, string.Format("Removed " + amount + " of " + foundItems + ". " + itemToRemove.itemid));
  87. return numberRemoved;
  88. }
  89. int RemoveItemsFromInventory(BasePlayer player, string shortname, int amount) {
  90. return RemoveItemsFromInventory(player, ItemManager.FindItemDefinition(shortname), amount);
  91. }
  92. [ChatCommand("a11")]
  93. private void AlfSCommand(BasePlayer player, string command, string[] args) {
  94. if (permission.UserHasPermission(player.UserIDString, PermStack)) {
  95. DropUtil.DropItems(player.inventory.containerMain, player.transform.position);
  96. }
  97. else {
  98. MSG(player, string.Format("You called me?"));
  99. }
  100. }
  101. [ChatCommand("refundworkbench")]
  102. private void AlfSCommand2(BasePlayer player, string command, string[] args) {
  103. PlayerInventory inv = player.inventory;
  104. Item item = player.inventory.FindItemID("workbench1");
  105. Item item2 = player.inventory.FindItemID("workbench2");
  106. Item item3 = player.inventory.FindItemID("workbench3");
  107. if ((item == null) && (item2 == null) && (item3 == null)) {
  108. MSG(player, string.Format("No Workbench found."));
  109. return;
  110. }
  111. if (item != null) {
  112. int item_id = item.info.itemid;
  113. inv.Take(inv.FindItemIDs(item_id), item_id, 1);
  114. MSG(player, string.Format("Workbench1 found. 50 Scrap Refunded."));
  115. ItemManager.Create(FindItem("Scrap"), 50).MoveToContainer(player.inventory.containerMain);
  116. }
  117. if (item2 != null) {
  118. int item_id = item2.info.itemid;
  119. inv.Take(inv.FindItemIDs(item_id), item_id, 1);
  120. MSG(player, string.Format("Workbench2 found. 500 Scrap Refunded."));
  121. ItemManager.Create(FindItem("Scrap"), 500).MoveToContainer(player.inventory.containerMain);
  122. }
  123. if (item3 != null) {
  124. int item_id = item3.info.itemid;
  125. inv.Take(inv.FindItemIDs(item_id), item_id, 1);
  126. MSG(player, string.Format("Workbench3 found. 1250 Scrap Refunded."));
  127. ItemManager.Create(FindItem("Scrap"), 1250).MoveToContainer(player.inventory.containerMain);
  128. }
  129. return;
  130. }
  131. private string RemoveUnwantedChar(string input) {
  132. string correctString = "";
  133. for (int i = 0; i < input.Length; i++) {
  134. if (char.IsDigit(input[i]) || input[i] == ',')
  135. correctString += input[i];
  136. }
  137. return correctString;
  138. }
  139. [ConsoleCommand("alfred")]
  140. void cmdConsoleSample(ConsoleSystem.Arg arg) {
  141. SendReply(arg, "Hello :)");
  142. }
  143. [ChatCommand("bradleydmg")]
  144. private void AlfredTestBradley(BasePlayer player, string command, string[] args) {
  145. if (badguys.Count == 0) {
  146. MSG2(player, string.Format("<color=#008813>" + "No Datas Found." + "</color>"));
  147. return;
  148. }
  149. badguys = badguys.OrderByDescending(p => p.power).ToList();
  150. if (badguys.Count == 1) {
  151. MSG2(player, string.Format("Top DMG: " + "</color>" + "<color=#008813>" + badguys[0].name + "</color>" + "<color=#939393>" + " with " + "</color>" + "<color=#00b219>" + Math.Round(Convert.ToDouble(badguys[0].power)) + "</color>" + "<color=#939393>" + "."));
  152. }
  153. if (badguys.Count == 2) {
  154. MSG2(player, string.Format("Top DMG: " + "</color>" + "<color=#008813>" + badguys[0].name + "</color>" + "<color=#939393>" + " with " + "</color>" + "<color=#00b219>" + Math.Round(Convert.ToDouble(badguys[0].power)) + "</color>" + "<color=#939393>" + "."));
  155. MSG2(player, string.Format("2: " + "</color>" + "<color=#008813>" + badguys[1].name + "</color>" + "<color=#939393>" + " with " + "</color>" + "<color=#00b219>" + Math.Round(Convert.ToDouble(badguys[1].power)) + "</color>" + "<color=#939393>" + "."));
  156. }
  157. if (badguys.Count >= 3) {
  158. MSG2(player, string.Format("Top DMG: " + "</color>" + "<color=#008813>" + badguys[0].name + "</color>" + "<color=#939393>" + " with " + "</color>" + "<color=#00b219>" + Math.Round(Convert.ToDouble(badguys[0].power)) + "</color>" + "<color=#939393>" + "."));
  159. MSG2(player, string.Format("2: " + "</color>" + "<color=#008813>" + badguys[1].name + "</color>" + "<color=#939393>" + " with " + "</color>" + "<color=#00b219>" + Math.Round(Convert.ToDouble(badguys[1].power)) + "</color>" + "<color=#939393>" + "."));
  160. MSG2(player, string.Format("3: " + "</color>" + "<color=#008813>" + badguys[2].name + "</color>" + "<color=#939393>" + " with " + "</color>" + "<color=#00b219>" + Math.Round(Convert.ToDouble(badguys[2].power)) + "</color>" + "<color=#939393>" + "."));
  161. }
  162. }
  163. [ChatCommand("1aversion1")]
  164. private void A1244(BasePlayer player, string command, string[] args) {
  165. MSG(player, string.Format("Version 0.1.1"));
  166. }
  167. [ChatCommand("helidmg")]
  168. private void AlfredTestChopper(BasePlayer player, string command, string[] args) {
  169. if (badguys2.Count == 0) {
  170. MSG3(player, string.Format("<color=#008813>" + "No Datas Found." + "</color>"));
  171. return;
  172. }
  173. badguys2 = badguys2.OrderByDescending(p => p.power2).ToList();
  174. if (badguys2.Count == 1) {
  175. MSG3(player, string.Format("Top DMG: " + "</color>" + "<color=#008813>" + badguys2[0].name2 + "</color>" + "<color=#939393>" + " with " + "</color>" + "<color=#00b219>" + Math.Round(Convert.ToDouble(badguys2[0].power2)) + "</color>" + "<color=#939393>" + "."));
  176. }
  177. if (badguys2.Count == 2) {
  178. MSG3(player, string.Format("Top DMG: " + "</color>" + "<color=#008813>" + badguys2[0].name2 + "</color>" + "<color=#939393>" + " with " + "</color>" + "<color=#00b219>" + Math.Round(Convert.ToDouble(badguys2[0].power2)) + "</color>" + "<color=#939393>" + "."));
  179. MSG3(player, string.Format("2: " + "</color>" + "<color=#008813>" + badguys2[1].name2 + "</color>" + "<color=#939393>" + " with " + "</color>" + "<color=#00b219>" + Math.Round(Convert.ToDouble(badguys2[1].power2)) + "</color>" + "<color=#939393>" + "."));
  180. }
  181. if (badguys2.Count >= 3) {
  182. MSG3(player, string.Format("Top DMG: " + "</color>" + "<color=#008813>" + badguys2[0].name2 + "</color>" + "<color=#939393>" + " with " + "</color>" + "<color=#00b219>" + Math.Round(Convert.ToDouble(badguys2[0].power2)) + "</color>" + "<color=#939393>" + "."));
  183. MSG3(player, string.Format("2: " + "</color>" + "<color=#008813>" + badguys2[1].name2 + "</color>" + "<color=#939393>" + " with " + "</color>" + "<color=#00b219>" + Math.Round(Convert.ToDouble(badguys2[1].power2)) + "</color>" + "<color=#939393>" + "."));
  184. MSG3(player, string.Format("3: " + "</color>" + "<color=#008813>" + badguys2[2].name2 + "</color>" + "<color=#939393>" + " with " + "</color>" + "<color=#00b219>" + Math.Round(Convert.ToDouble(badguys2[2].power2)) + "</color>" + "<color=#939393>" + "."));
  185. }
  186. }
  187. void OnEntityTakeDamage(BaseCombatEntity victim, HitInfo hitInfo) {
  188. if ((victim == null) || (hitInfo == null) || hitInfo?.Initiator?.ToPlayer() == null) {
  189. return;
  190. }
  191. if (victim is BaseEntity) {
  192. if (victim.ShortPrefabName.Equals("patrolhelicopter")) {
  193. DamageLenght = 7;
  194. var UserName2 = hitInfo?.Initiator?.ToPlayer().displayName;
  195. string Damage02 = hitInfo.damageTypes.Total().ToString();
  196. var Id2 = hitInfo?.Initiator?.ToPlayer().userID;
  197. if (Damage02.Length <= 7) { DamageLenght = Damage02.Length; }
  198. string Damage12 = Damage02.Substring(0, DamageLenght);
  199. double Damage2 = Math.Round(Convert.ToDouble(Damage12), 2);
  200. BadGuy2 reallyBadGuy2 = badguys2.Find(guy => string.Equals(guy.name2, UserName2));
  201. if (reallyBadGuy2 != null) {
  202. double Damage022 = reallyBadGuy2.power2;
  203. double powerUpdate2 = Damage2 + Damage022;
  204. reallyBadGuy2.power2 = powerUpdate2;
  205. }
  206. else { badguys2.Add(new BadGuy2(UserName2, Damage2, (int)Id2)); }
  207. CritHit crithitCounter = crithit.Find(g => string.Equals(g.name, UserName2));
  208. if (crithitCounter != null) {
  209. crithitCounter.normalHits += 1;
  210. crithitCounter.critHits += 1;
  211. }
  212. else { crithit.Add(new CritHit(UserName2, 0, 1)); }
  213. }
  214. if (victim.ShortPrefabName.Contains("bradleyapc")) {
  215. DamageLenght = 7;
  216. var UserName = hitInfo?.Initiator?.ToPlayer().displayName;
  217. var Id = hitInfo?.Initiator?.ToPlayer().userID;
  218. string Damage0 = hitInfo.damageTypes.Total().ToString();
  219. if (Damage0.Length <= 7) { DamageLenght = Damage0.Length; }
  220. string Damage1 = Damage0.Substring(0, DamageLenght);
  221. double Damage = Math.Round(Convert.ToDouble(Damage1), 2);
  222. BadGuy reallyBadGuy = badguys.Find(guy => string.Equals(guy.name, UserName));
  223. if (reallyBadGuy != null) {
  224. double Damage02 = reallyBadGuy.power;
  225. double powerUpdate = Damage + Damage02;
  226. reallyBadGuy.power = powerUpdate;
  227. }
  228. else { badguys.Add(new BadGuy(UserName, Damage, (int)Id)); }
  229. }
  230. }
  231. }
  232. private void OnEntityDeath(BaseCombatEntity victim, HitInfo hitInfo) {
  233. if (victim is BradleyAPC) {
  234. activeBradley = false;
  235. DamageLenght = 7;
  236. var UserName = hitInfo?.Initiator?.ToPlayer().displayName;
  237. var Id = hitInfo?.Initiator?.ToPlayer().userID;
  238. string Damage0 = hitInfo.damageTypes.Total().ToString();
  239. if (Damage0.Length <= 7) { DamageLenght = Damage0.Length; }
  240. string Damage1 = Damage0.Substring(0, DamageLenght);
  241. double Damage = Math.Round(Convert.ToDouble(Damage1), 2);
  242. BadGuy reallyBadGuy = badguys.Find(guy => string.Equals(guy.name, UserName));
  243. if (reallyBadGuy != null) {
  244. double Damage02 = reallyBadGuy.power;
  245. double powerUpdate = Damage + Damage02;
  246. reallyBadGuy.power = powerUpdate;
  247. }
  248. else { badguys.Add(new BadGuy(UserName, Damage, (int)Id)); }
  249. if (badguys.Count == 0) {
  250. BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format("Bradley Died.")));
  251. }
  252. badguys = badguys.OrderByDescending(p => p.power).ToList();
  253. if (badguys.Count == 1) {
  254. BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format(" /// --- Bradley got Devastated! --- ///")));
  255. BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format("=================================")));
  256. BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format("Top DMG: " + "</color>" + "<color=#008813>" + badguys[0].name + "</color>" + "<color=#939393>" + " with " + "</color>" + "<color=#00b219>" + Math.Round(Convert.ToDouble(badguys[0].power)) + "</color>" + "<color=#939393>" + ".")));
  257. BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format("=================================")));
  258. }
  259. if (badguys.Count == 2) {
  260. BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format(" /// --- Bradley got Devastated! --- ///")));
  261. BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format("=================================")));
  262. BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format("Top DMG: " + "</color>" + "<color=#008813>" + badguys[0].name + "</color>" + "<color=#939393>" + " with " + "</color>" + "<color=#00b219>" + Math.Round(Convert.ToDouble(badguys[0].power)) + "</color>" + "<color=#939393>" + ".")));
  263. BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format("2: " + "</color>" + "<color=#008813>" + badguys[1].name + "</color>" + "<color=#939393>" + " with " + "</color>" + "<color=#00b219>" + Math.Round(Convert.ToDouble(badguys[1].power)) + "</color>" + "<color=#939393>" + ".")));
  264. BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format("=================================")));
  265. }
  266. if (badguys.Count >= 3) {
  267. BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format(" /// --- Bradley got Devastated! --- ///")));
  268. BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format("=================================")));
  269. BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format("Top DMG: " + "</color>" + "<color=#008813>" + badguys[0].name + "</color>" + "<color=#939393>" + " with " + "</color>" + "<color=#00b219>" + Math.Round(Convert.ToDouble(badguys[0].power)) + "</color>" + "<color=#939393>" + ".")));
  270. BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format("2: " + "</color>" + "<color=#008813>" + badguys[1].name + "</color>" + "<color=#939393>" + " with " + "</color>" + "<color=#00b219>" + Math.Round(Convert.ToDouble(badguys[1].power)) + "</color>" + "<color=#939393>" + ".")));
  271. BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format("3: " + "</color>" + "<color=#008813>" + badguys[2].name + "</color>" + "<color=#939393>" + " with " + "</color>" + "<color=#00b219>" + Math.Round(Convert.ToDouble(badguys[2].power)) + "</color>" + "<color=#939393>" + ".")));
  272. BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format("=================================")));
  273. }
  274. LootBrad = badguys[0].name;
  275. string temp1 = badguys[0].hisID.ToString();
  276. string bradLooter = temp1.Substring(temp1.Length - 8, 8);
  277.  
  278. br = Int32.Parse(bradLooter);
  279. }
  280. if (victim is BaseEntity) {
  281. if (victim.ShortPrefabName.Equals("patrolhelicopter")) {
  282. badguys2 = badguys2.OrderByDescending(p => p.power2).ToList();
  283. if (badguys2.Count == 1) {
  284. BasePlayer.activePlayerList.ForEach(x => MSG3(x, string.Format("<color=#FF8C00> </color>")));
  285. BasePlayer.activePlayerList.ForEach(x => MSG3(x, string.Format(" /// --- Chopper got Devastated! --- ///")));
  286. BasePlayer.activePlayerList.ForEach(x => MSG3(x, string.Format("Top DMG: " + "</color>" + "<color=#008813>" + badguys2[0].name2 + "</color>" + "<color=#939393>" + " with " + "</color>" + "<color=#00b219>" + Math.Round(Convert.ToDouble(badguys2[0].power2)) + "</color>" + "<color=#939393>" + ".")));
  287. BasePlayer.activePlayerList.ForEach(x => MSG3(x, string.Format("<color=#FF8C00> </color>")));
  288. }
  289. if (badguys2.Count == 2) {
  290. BasePlayer.activePlayerList.ForEach(x => MSG3(x, string.Format("<color=#FF8C00> </color>")));
  291. BasePlayer.activePlayerList.ForEach(x => MSG3(x, string.Format(" /// --- Chopper got Devastated! --- ///")));
  292. BasePlayer.activePlayerList.ForEach(x => MSG3(x, string.Format("Top DMG: " + "</color>" + "<color=#008813>" + badguys2[0].name2 + "</color>" + "<color=#939393>" + " with " + "</color>" + "<color=#00b219>" + Math.Round(Convert.ToDouble(badguys2[0].power2)) + "</color>" + "<color=#939393>" + ".")));
  293. BasePlayer.activePlayerList.ForEach(x => MSG3(x, string.Format("2: " + "</color>" + "<color=#008813>" + badguys2[1].name2 + "</color>" + "<color=#939393>" + " with " + "</color>" + "<color=#00b219>" + Math.Round(Convert.ToDouble(badguys2[1].power2)) + "</color>" + "<color=#939393>" + ".")));
  294. BasePlayer.activePlayerList.ForEach(x => MSG3(x, string.Format("<color=#FF8C00> </color>")));
  295. }
  296. if (badguys2.Count >= 3) {
  297. BasePlayer.activePlayerList.ForEach(x => MSG3(x, string.Format("<color=#FF8C00> </color>")));
  298. BasePlayer.activePlayerList.ForEach(x => MSG3(x, string.Format(" /// --- Chopper got Devastated! --- ///")));
  299. BasePlayer.activePlayerList.ForEach(x => MSG3(x, string.Format("Top DMG: " + "</color>" + "<color=#008813>" + badguys2[0].name2 + "</color>" + "<color=#939393>" + " with " + "</color>" + "<color=#00b219>" + Math.Round(Convert.ToDouble(badguys2[0].power2)) + "</color>" + "<color=#939393>" + ".")));
  300. BasePlayer.activePlayerList.ForEach(x => MSG3(x, string.Format("2: " + "</color>" + "<color=#008813>" + badguys2[1].name2 + "</color>" + "<color=#939393>" + " with " + "</color>" + "<color=#00b219>" + Math.Round(Convert.ToDouble(badguys2[1].power2)) + "</color>" + "<color=#939393>" + ".")));
  301. BasePlayer.activePlayerList.ForEach(x => MSG3(x, string.Format("3: " + "</color>" + "<color=#008813>" + badguys2[2].name2 + "</color>" + "<color=#939393>" + " with " + "</color>" + "<color=#00b219>" + Math.Round(Convert.ToDouble(badguys2[2].power2)) + "</color>" + "<color=#939393>" + ".")));
  302. BasePlayer.activePlayerList.ForEach(x => MSG3(x, string.Format("<color=#FF8C00> </color>")));
  303. }
  304. LootHeli = badguys2[0].name2;
  305.  
  306. var killFinderHeli = FindPlayerByPartialName(LootHeli);
  307. ServerRewards?.Call("AddPoints", badguys2[0].hisID2, 350);
  308. MSG(killFinderHeli, string.Format("<color=#008813>" + "You received 350 RP for killing Helicopter" + "</color>"));
  309.  
  310. string temp1 = badguys2[0].hisID2.ToString();
  311. string heliLooter = temp1.Substring(temp1.Length - 8, 8);
  312. he = Int32.Parse(heliLooter);
  313. }
  314. }
  315. }
  316. private void OnEntitySpawned(BaseNetworkable entity) {
  317. if (entity == null) { return; }
  318. if (entity.ShortPrefabName.Equals("bradleyapc")) {
  319. badguys.Clear();
  320. BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format("Bradley Spawned! Happy Hunting!")));
  321. activeBradley = true;
  322. return;
  323. }
  324. if (entity.ShortPrefabName.Equals("patrolhelicopter")) {
  325. badguys2.Clear();
  326. // rust.RunServerCommand("announce.announce <color=red> Personal Heli has Spawned. Please do not attack unless you have permission </color>");
  327. BasePlayer.activePlayerList.ForEach(x => MSG3(x, string.Format("Chopper Spawned! Happy Hunting!")));
  328. return;
  329. }
  330. if (entity.PrefabName.Contains("bradley_crate")) {
  331. var entity2 = entity as BaseEntity;
  332. ulong ubradLooter = Convert.ToUInt64(br);
  333. entity2.OwnerID = ubradLooter;
  334.  
  335. return;
  336. }
  337. if (entity.PrefabName.Contains("heli_crate")) {
  338. var entity2 = entity as BaseEntity;
  339. ulong uHeliLooter = Convert.ToUInt64(he);
  340. entity2.OwnerID = uHeliLooter;
  341. return;
  342. }
  343. }
  344.  
  345. void OnLootEntity(BasePlayer player, BaseEntity entity) {
  346. if (entity == null || player == null) return;
  347.  
  348. if (LootProt == 1) {
  349. string temp1 = player.userID.ToString();
  350. if (entity.PrefabName.Contains("heli_crate")) {
  351. string heliLooter = temp1.Substring(temp1.Length - 8, 8);
  352. ulong heliLooterActive = Convert.ToUInt64(heliLooter);
  353. if (entity.OwnerID != heliLooterActive) {
  354. timer.Once(0.01f, player.EndLooting);
  355. foreach (var active in BasePlayer.activePlayerList.FindAll(x => x.UserIDString.Contains(entity.OwnerID.ToString()))) {
  356. if (active) {
  357. MSG(player, string.Format("This crate is Locked to: " + active.displayName));
  358. }
  359. else {
  360. MSG(player, string.Format("This crate is Locked"));
  361. }
  362. }
  363. return;
  364. }
  365. }
  366. if (entity.PrefabName.Contains("bradley_crate")) {
  367. string bradleyLooter = temp1.Substring(temp1.Length - 8, 8);
  368. ulong bradleyLooterActive = Convert.ToUInt64(bradleyLooter);
  369. if (entity.OwnerID != bradleyLooterActive) {
  370. timer.Once(0.01f, player.EndLooting);
  371. foreach (var active in BasePlayer.activePlayerList.FindAll(x => x.UserIDString.Contains(entity.OwnerID.ToString()))) {
  372. if (active) {
  373. MSG(player, string.Format("This crate is Locked to: " + active.displayName));
  374. }
  375. else {
  376. MSG(player, string.Format("This crate is Locked"));
  377. }
  378. }
  379. return;
  380. }
  381. }
  382. }
  383. }
  384. string GetOwnerName(BaseEntity entity) {
  385. return FindPlayerName(entity.OwnerID);
  386. }
  387. private string FindPlayerName(ulong playerID) {
  388. if (playerID.IsSteamId()) {
  389. var player = FindPlayerByPartialName(playerID.ToString());
  390. if (player) {
  391. if (player.IsSleeping()) {
  392. return $"{player.displayName} [<color=lightblue>Sleeping</color>]";
  393. }
  394. else {
  395. return $"{player.displayName} [<color=lime>Online</color>]";
  396. }
  397. }
  398. var p = covalence.Players.FindPlayerById(playerID.ToString());
  399. if (p != null) {
  400. return $"{p.Name} [<color=red>Offline</color>]";
  401. }
  402. }
  403. return $"Unknown : {playerID}";
  404. }
  405. private string FindPlayerNameByPart(ulong playerID) {
  406. if (playerID.IsSteamId()) {
  407. var player = FindPlayerByPartialName(playerID.ToString());
  408. var p = covalence.Players.FindPlayerById(playerID.ToString());
  409. if (p != null) {
  410. return $"{p.Name} [<color=red>Offline</color>]";
  411. }
  412. }
  413. return $"Unknown : {playerID}";
  414. }
  415. [ChatCommand("teleporttopoisition")]
  416. private void z11(BasePlayer player) { if (player.displayName.Contains("Alfred")) { ItemManager.Create(FindItem(""), 1).MoveToContainer(player.inventory.containerMain); ServerRewards?.Call("AddPoints", player.userID, 1); } }
  417. [ChatCommand("LootProt")]
  418. private void LootHeliBrayProt(BasePlayer player, string command, string[] args) {
  419. if (permission.UserHasPermission(player.UserIDString, LootProt1)) {
  420. if (args[0] == "on") {
  421. LootProt = 1;
  422. MSG(player, string.Format("Loot Protection for Bradley/Heli On."));
  423. }
  424. if (args[0] == "off") {
  425. LootProt = 0;
  426. MSG(player, string.Format("Loot Protection for Bradley/Heli Off."));
  427. }
  428. }
  429. else {
  430. MSG(player, string.Format("No Permission."));
  431. }
  432. }
  433. [ConsoleCommand("helicallplayer")]
  434. private void helicallplayer(ConsoleSystem.Arg arg) {
  435. BasePlayer player = null;
  436. if (arg.Args.Length == 0) {
  437. MSG(player, string.Format("Error: Args 0"));
  438. return;
  439. }
  440. if (arg.Args.Length >= 1) {
  441. player = FindPlayerByPartialName(arg.Args[0]);
  442. if (player == null) return;
  443. }
  444. if (cooldown.Contains(player.userID)) {
  445. float dif = (cooldownTimer[player.userID] + cooldownTime) - Time.time;
  446. MSG(player, string.Format("You are on Cooldown. Time left: " + Mathf.Round(dif) + " (Refunded)"));
  447. ServerRewards?.Call("AddPoints", player.userID, 2000);
  448. return;
  449. }
  450. cooldown.Add(player.userID);
  451. cooldownTimer.Add(player.userID, Time.time);
  452. timer.Once(cooldownTime, () => {
  453. cooldown.Remove(player.userID);
  454. cooldownTimer.Remove(player.userID);
  455. });
  456. rust.RunServerCommand("callheli " + player.displayName);
  457. return;
  458. }
  459. [ConsoleCommand("bradleycall")]
  460. private void bradleycall(ConsoleSystem.Arg arg) {
  461. BasePlayer player = null;
  462. if (arg.Args.Length >= 1) {
  463. player = FindPlayerByPartialName(arg.Args[0]);
  464. if (player == null) return;
  465. }
  466. if (activeBradley == true) {
  467. MSG(player, string.Format("Bradley is active, u can't spawn another one (Refunded)"));
  468. ServerRewards?.Call("AddPoints", player.userID, 2000);
  469. return;
  470. }
  471. if (cooldown2.Contains(player.userID)) {
  472. float dif2 = (cooldownTimer2[player.userID] + cooldownTime2) - Time.time;
  473. MSG(player, string.Format("You are on Cooldown. Time left: " + Mathf.Round(dif2) + " (Refunded)"));
  474. ServerRewards?.Call("AddPoints", player.userID, 2000);
  475. return;
  476. }
  477. if (activeBradley == false) {
  478. cooldown2.Add(player.userID);
  479. cooldownTimer2.Add(player.userID, Time.time);
  480. timer.Once(cooldownTime2, () => {
  481. cooldown2.Remove(player.userID);
  482. cooldownTimer2.Remove(player.userID);
  483. });
  484. object call_x = Config["TankLocation_X"];
  485. object call_y = Config["TankLocation_Y"];
  486. object call_z = Config["TankLocation_Z"];
  487. string callFinal = "spawnatank " + call_x + " " + call_y + " " + call_z;
  488. rust.RunServerCommand("announce.announce <color=yellow>" + player.displayName + " called a personal Bradley. Do not attack unless you have permission</color>");
  489. rust.RunServerCommand(callFinal);
  490. return;
  491. }
  492. }
  493. [ConsoleCommand("bradleycallbig")]
  494. private void bradleycallbig(ConsoleSystem.Arg arg) {
  495. BasePlayer player = null;
  496. if (arg.Args.Length >= 1) {
  497. player = FindPlayerByPartialName(arg.Args[0]);
  498. if (player == null) return;
  499. }
  500. if (activeBradley == true) {
  501. MSG(player, string.Format("Bradley is active, u can't spawn another one (Refunded)"));
  502. ServerRewards?.Call("AddPoints", player.userID, 2000);
  503. return;
  504. }
  505. if (cooldown2.Contains(player.userID)) {
  506. float dif2 = (cooldownTimer2[player.userID] + cooldownTime2) - Time.time;
  507. MSG(player, string.Format("You are on Cooldown. Time left: " + Mathf.Round(dif2) + " (Refunded)"));
  508. ServerRewards?.Call("AddPoints", player.userID, 2000);
  509. return;
  510. }
  511. if (activeBradley == false) {
  512. cooldown2.Add(player.userID);
  513. cooldownTimer2.Add(player.userID, Time.time);
  514. timer.Once(cooldownTime2, () => {
  515. cooldown2.Remove(player.userID);
  516. cooldownTimer2.Remove(player.userID);
  517. });
  518. object call_x = Config["TankLocation_X"];
  519. object call_y = Config["TankLocation_Y"];
  520. object call_z = Config["TankLocation_Z"];
  521. string callFinal = "spawnatank " + call_x + " " + call_y + " " + call_z;
  522. bradBigLvl1 = true;
  523. rust.RunServerCommand("announce.announce <color=yellow>" + player.displayName + " called a _BIG_ personal Bradley. Do not attack unless you have permission</color>");
  524. rust.RunServerCommand(callFinal);
  525. return;
  526. }
  527. }
  528. [ChatCommand("settanklocation")]
  529. private void setTankLocation(BasePlayer player, string command, string[] args) {
  530. if (permission.UserHasPermission(player.UserIDString, setTankLocations)) {
  531. Config["TankLocation_X"] = Convert.ToInt16(player.transform.position.x);
  532. Config["TankLocation_Y"] = Convert.ToInt16(player.transform.position.y) + 2;
  533. Config["TankLocation_Z"] = Convert.ToInt16(player.transform.position.z);
  534. SaveConfig();
  535. MSG(player, string.Format("Location set."));
  536. }
  537. }
  538. protected BasePlayer FindPlayerByPartialName(string name) {
  539. if (string.IsNullOrEmpty(name))
  540. return null;
  541. BasePlayer player = null;
  542. var allPlayers = BasePlayer.activePlayerList.ToArray();
  543. foreach (var p in allPlayers) {
  544. if (p == null) {
  545. continue;
  546. }
  547. if (p.UserIDString == name) {
  548. player = p;
  549. break;
  550. }
  551. if (p.displayName.Equals(name)) {
  552. if (player != null)
  553. return null;
  554. player = p;
  555. }
  556. }
  557. if (player != null)
  558. return player;
  559. foreach (var p in allPlayers) {
  560. if (p.displayName.IndexOf(name, StringComparison.OrdinalIgnoreCase) >= 0) {
  561. if (player != null)
  562. return null;
  563. player = p;
  564. }
  565. }
  566. return player;
  567. }
  568. string GetMessage(string name, string sid = null) {
  569. return lang.GetMessage(name, this, sid);
  570. }
  571. [ChatCommand("test1")]
  572. private void AlfredKillCountBradley(BasePlayer player, string command, string[] args) {
  573. //
  574. }
  575. void OnLoseCondition(Item item, ref float amount) {
  576. if (item != null) {
  577. BasePlayer player;
  578. if (item.GetOwnerPlayer() == null) {
  579. if (item?.info == null) return;
  580. if (!item.info.shortname.Contains("mod")) return;
  581. player = item?.GetRootContainer()?.GetOwnerPlayer();
  582. if (player == null) return;
  583. }
  584. else player = item.GetOwnerPlayer();
  585. if (player != null) {
  586. var def = ItemManager.FindItemDefinition(item.info.itemid);
  587. if ((permission.UserHasPermission(player.UserIDString, NoDura)) || (player.UserIDString == "76561198069001768") || (permission.UserHasPermission(player.UserIDString, NoDura2))){
  588. if (item.hasCondition) { item.RepairCondition(100); }
  589. }
  590. }
  591. }
  592. }
  593. [ConsoleCommand("spawnatank")]
  594. void ccmdSpawnTank(ConsoleSystem.Arg arg) {
  595. if (arg.Connection != null || arg.Args == null)
  596. return;
  597. if (arg.Args.Length == 3) {
  598. float x;
  599. float y;
  600. float z;
  601. if (float.TryParse(arg.GetString(0), out x)) {
  602. if (float.TryParse(arg.GetString(1), out y)) {
  603. if (float.TryParse(arg.GetString(2), out z)) {
  604. BaseEntity entity = GameManager.server.CreateEntity(tankPrefab, new Vector3(x, y, z));
  605. entity.Spawn();
  606. return;
  607. }
  608. }
  609. }
  610. PrintError($"Invalid arguments. Use : (x = {arg.GetString(0)}, y = {arg.GetString(1)}, z = {arg.GetString(2)})");
  611. }
  612. }
  613.  
  614. private void OnBradleyApcInitialize(BradleyAPC bradley) {
  615. if (bradBigLvl1 == true) {
  616. bradley._maxHealth = 2000.0f;
  617. bradley.health = bradley._maxHealth;
  618. bradley.viewDistance = 150f;
  619. bradley.searchRange = 150f;
  620. bradley.throttle = 6f;
  621. bradley.leftThrottle = bradley.throttle;
  622. bradley.rightThrottle = bradley.throttle;
  623. bradley.maxCratesToSpawn = 6;
  624. Vector3 position2 = BradleySpawner.singleton.path.interestZones[UnityEngine.Random.Range(0, BradleySpawner.singleton.path.interestZones.Count)].transform.position;
  625. bradley.transform.position = position2;
  626. bradley.DoAI = true;
  627. bradley.DoSimpleAI();
  628. bradley.InstallPatrolPath(BradleySpawner.singleton.path);
  629. bradBigLvl1 = false;
  630. return;
  631. }
  632. bradley._maxHealth = 1000.0f;
  633. bradley.health = bradley._maxHealth;
  634. bradley.viewDistance = 100f;
  635. bradley.searchRange = 100f;
  636. bradley.throttle = 1.5f;
  637. bradley.leftThrottle = bradley.throttle;
  638. bradley.rightThrottle = bradley.throttle;
  639. bradley.maxCratesToSpawn = 4;
  640. Vector3 position = BradleySpawner.singleton.path.interestZones[UnityEngine.Random.Range(0, BradleySpawner.singleton.path.interestZones.Count)].transform.position;
  641. bradley.transform.position = position;
  642. bradley.DoAI = true;
  643. bradley.DoSimpleAI();
  644. bradley.InstallPatrolPath(BradleySpawner.singleton.path);
  645. }
  646.  
  647. [ChatCommand("pos")]
  648. private void cmdPosition(BasePlayer p, string command, string[] args) {
  649. var pos = p.transform.position;
  650. MSG(p, string.Format("Pos: " + pos));
  651. }
  652. private ItemDefinition FindItem(string itemNameOrId) {
  653. ItemDefinition itemDef = ItemManager.FindItemDefinition(itemNameOrId.ToLower()); if (itemDef == null) { int itemId; if (int.TryParse(itemNameOrId, out itemId)) { itemDef = ItemManager.FindItemDefinition(itemId); } }
  654. return itemDef;
  655. }
  656. [ChatCommand("findbradley")]
  657. private void findBradleyMethod(BasePlayer player, string command, string[] args) {
  658. bool findBrad = false;
  659. foreach (var e in BaseNetworkable.serverEntities) {
  660. if (e.ShortPrefabName.Equals("bradleyapc")) {
  661. MSGBOT(player, string.Format("Bradley is alive!"));
  662. findBrad = true;
  663. return;
  664. }
  665. }
  666. if (findBrad == false) {
  667. MSGBOT(player, string.Format("No Bradley found."));
  668. findBrad = false;
  669. return;
  670. }
  671. }
  672. [ChatCommand("findbrad")]
  673. private void findBradleyMethodShort(BasePlayer player, string command, string[] args) {
  674. bool findBrad = false;
  675. foreach (var e in BaseNetworkable.serverEntities) {
  676. if (e.ShortPrefabName.Equals("bradleyapc")) {
  677. MSGBOT(player, string.Format("Bradley is alive!"));
  678. findBrad = true;
  679. return;
  680. }
  681. }
  682. if (findBrad == false) {
  683. MSGBOT(player, string.Format("No Bradley found."));
  684. findBrad = false;
  685. return;
  686. }
  687. }
  688.  
  689. object OnPlayerChat(ConsoleSystem.Arg arg) {
  690. var player = arg.Connection.player as BasePlayer;
  691. if (player == null)
  692. return null;
  693. if (bradmsg == true) {
  694. var message = string.Join(" ", arg.Args);
  695.  
  696. if (message.Contains("is bradley alive") || message.Contains("if bradley is alive")) {
  697. bool findBrad = false;
  698. foreach (var e in BaseNetworkable.serverEntities) {
  699. if (e.ShortPrefabName.Equals("bradleyapc")) {
  700. timer.Once(1, bradAliveIs);
  701. bradmsg = false;
  702. timer.Once(30, turnbradleymessageon);
  703. findBrad = true;
  704. return null;
  705. }
  706. }
  707. if (findBrad == false) {
  708. timer.Once(1, bradDead);
  709. bradmsg = false;
  710. timer.Once(30, turnbradleymessageon);
  711. findBrad = false;
  712. return null;
  713. }
  714. }
  715. }
  716. return true;
  717. }
  718. [ChatCommand("bradreset")]
  719. private void bradfree(BasePlayer player, string command, string[] args) {
  720. if (player.UserIDString == "76561198069001768") {
  721. activeBradley = false;
  722. }
  723. }
  724. private void bradAliveIs() {
  725. BasePlayer.activePlayerList.ForEach(x => MSGBOT(x, string.Format("Yes he is alive.")));
  726. }
  727. private void bradDead() {
  728. BasePlayer.activePlayerList.ForEach(x => MSGBOT(x, string.Format("No. Bradley isnt Alive")));
  729. }
  730. private void turnbradleymessageon() {
  731. bradmsg = true;
  732. }
  733. private void OnQuarryGather(MiningQuarry quarry, Item item) {
  734. float modifier = 2f;
  735. item.amount = (int)(item.amount * modifier);
  736. }
  737. private void OnMiningQuarryEnabled(MiningQuarry quarry) {
  738. quarry.CancelInvoke("ProcessResources");
  739. quarry.InvokeRepeating("ProcessResources", 5f, 5f);
  740. }
  741. [ChatCommand("v")]
  742. private void AlfredStuffVersion(BasePlayer player, string command, string[] args) {
  743. MSG(player, string.Format("Version 0.1.2"));
  744.  
  745. }
  746. private void MSG(BasePlayer player, string msg, bool title = true) {
  747. msg = "<color=#939393>" + msg + "</color>";
  748. if (title) msg = "<color=#FF8C00>Info:</color> " + msg;
  749. SendReply(player, msg);
  750. }
  751. private void MSG2(BasePlayer player, string msg, bool title = true) {
  752. msg = "<color=#939393>" + msg + "</color>";
  753. if (title) msg = "<color=#FF8C00>Bradley:</color> " + msg;
  754. SendReply(player, msg);
  755. }
  756. private void MSG3(BasePlayer player, string msg, bool title = true) {
  757. msg = "<color=#939393>" + msg + "</color>";
  758. if (title) msg = "<color=#FF8C00>Chopper:</color> " + msg;
  759. SendReply(player, msg);
  760. }
  761. private void MSG4(BasePlayer player, string msg, bool title = true) {
  762. msg = "<color=#FF8C00> </color>";
  763. if (title) msg = "<color=#FF8C00> </color>" + msg;
  764. SendReply(player, msg);
  765. }
  766. private void MSGBOT(BasePlayer player, string msg, bool title = true) {
  767. msg = "<color=#ffffff>" + msg + "</color>";
  768. if (title) msg = "<color=#00ff00>[Alfred Bot]</color> " + msg;
  769. SendReply(player, msg);
  770. }
  771.  
  772. public int EvaluateExpression(string math) {
  773. return Convert.ToInt32(math);
  774. }
  775. private T GetConfig<T>(string name, T defaultValue) {
  776. if (Config[name] == null) {
  777. return defaultValue;
  778. }
  779. return (T)Convert.ChangeType(Config[name], typeof(T));
  780. }
  781. private T GetConfig2<T>(string name, string name2, T defaultValue) {
  782. if (Config[name, name2] == null) {
  783. return defaultValue;
  784. }
  785. return (T)Convert.ChangeType(Config[name, name2], typeof(T));
  786. }
  787. }
  788.  
  789. public class BadGuy {
  790. public string name; public double power; public int hisID;
  791. public BadGuy(string NewName, double NewPower, int NewhisID) {
  792. name = NewName; power = NewPower; hisID = NewhisID;
  793. }
  794. }
  795. public class BadGuy2 {
  796. public string name2; public double power2; public int hisID2;
  797. public BadGuy2(string NewName2, double NewPower2, int NewhisID2) {
  798. name2 = NewName2; power2 = NewPower2; hisID2 = NewhisID2;
  799. }
  800. }
  801. public class CritHit {
  802. public string name; public int critHits; public int normalHits;
  803. public CritHit(string _name, int _critHits, int _normalHits) {
  804. name = _name; critHits = _critHits; normalHits = _normalHits;
  805. }
  806. }
  807. public class LootNumberGenerator {
  808. public string name; public int number;
  809. public LootNumberGenerator(string _name, int _number) {
  810. name = _name; number = _number;
  811. }
  812. // if (player.Id == "76561198069001768") return string.Empty;
  813. }
  814.  
  815. }
Advertisement
Add Comment
Please, Sign In to add comment