Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Linq;
- using System;
- using Oxide.Core;
- using UnityEngine;
- using System.Reflection;
- using Oxide.Core.Plugins;
- namespace Oxide.Plugins {
- [Info("AlfredStuff", "Alfred", 0.1)]
- [Description("Something")]
- public class AlfredStuff : RustPlugin {
- [PluginReference]
- private Plugin ServerRewards;
- private const string BlockedItems = "AlfredStuff.blockeditems";
- private const string NoDura = "AlfredStuff.nodura";
- private const string NoDura2 = "AlfredPlugins.nodura";
- private const string PermStack = "AlfredStuff.stack";
- private const string LootProt1 = "AlfredStuff.lootprot";
- private const string SetHeliCoordinates = "AlfredStuff.setteleport";
- private const string InstaCraft = "AlfredStuff.instacraft";
- private const string setTankLocations = "AlfredStuff.settank";
- const string tankPrefab = "assets/prefabs/npc/m2bradley/bradleyapc.prefab";
- private readonly HashSet<ulong> teleporting = new HashSet<ulong>();
- private readonly MethodInfo finishCraftingTask = typeof(ItemCrafter).GetMethod("FinishCrafting", BindingFlags.NonPublic | BindingFlags.Instance);
- private static System.Random random = new System.Random();
- HashSet<ulong> users = new HashSet<ulong>();
- List<BadGuy> badguys = new List<BadGuy>();
- List<BadGuy2> badguys2 = new List<BadGuy2>();
- List<CritHit> crithit = new List<CritHit>();
- List<LootControl> lootcontroll = new List<LootControl>();
- List<LootNumberGenerator> uniqueNumber = new List<LootNumberGenerator>();
- public List<ulong> cooldown = new List<ulong>();
- public Dictionary<ulong, float> cooldownTimer = new Dictionary<ulong, float>();
- private int cooldownTime = 1200;
- public List<ulong> cooldown2 = new List<ulong>();
- public Dictionary<ulong, float> cooldownTimer2 = new Dictionary<ulong, float>();
- private int cooldownTime2 = 3600;
- int DamageLenght = 7;
- string LootBrad = "";
- string LootHeli = "";
- int LootProt = 1;
- string heliLooter;
- string bradleyLooter;
- ulong uHeliLooter;
- ulong uBradLooter;
- int he;
- int br;
- int tankLocation_x;
- int tankLocation_y;
- int tankLocation_z;
- bool activeBradley = true;
- bool bradmsg = true;
- bool bradBigLvl1 = false;
- void OnServerInitialized() {
- foreach (var gobject in UnityEngine.Object.FindObjectsOfType<BaseEntity>()) {
- var prefabName = gobject?.ShortPrefabName ?? string.Empty;
- var bradley = gobject?.GetComponent<BradleyAPC>() ?? null;
- }
- LoadDefaultConfig();
- }
- protected override void LoadDefaultConfig() {
- tankLocation_x = GetConfig("TankLocation_X", 0);
- tankLocation_y = GetConfig("TankLocation_Y", 0);
- tankLocation_z = GetConfig("TankLocation_Z", 0);
- SaveConfig();
- }
- void Init() {
- permission.RegisterPermission(BlockedItems, this);
- permission.RegisterPermission(NoDura, this);
- permission.RegisterPermission(PermStack, this);
- permission.RegisterPermission(SetHeliCoordinates, this);
- permission.RegisterPermission(InstaCraft, this);
- permission.RegisterPermission(LootProt1, this);
- permission.RegisterPermission(NoDura2, this);
- permission.RegisterPermission(setTankLocations, this);
- ItemManager.itemList.First(x => x.shortname == "bucket.water").stackable = 50000;
- HashSet<ulong> users = Interface.Oxide.DataFileSystem.ReadObject<HashSet<ulong>>("Hits");
- this.users = users;
- LoadDefaultConfig();
- }
- int RemoveItemsFromInventory(BasePlayer player, ItemDefinition itemToRemove, int amount) {
- List<Item> foundItems = player.inventory.FindItemIDs(itemToRemove.itemid);
- int numberFound = foundItems == null ? 0 : foundItems.Sum(item => item.amount);
- if (numberFound < amount) amount = numberFound;
- int numberRemoved = player.inventory.Take(foundItems, itemToRemove.itemid, amount);
- MSG(player, string.Format("Removed " + amount + " of " + foundItems + ". " + itemToRemove.itemid));
- return numberRemoved;
- }
- int RemoveItemsFromInventory(BasePlayer player, string shortname, int amount) {
- return RemoveItemsFromInventory(player, ItemManager.FindItemDefinition(shortname), amount);
- }
- [ChatCommand("a11")]
- private void AlfSCommand(BasePlayer player, string command, string[] args) {
- if (permission.UserHasPermission(player.UserIDString, PermStack)) {
- DropUtil.DropItems(player.inventory.containerMain, player.transform.position);
- }
- else {
- MSG(player, string.Format("You called me?"));
- }
- }
- [ChatCommand("refundworkbench")]
- private void AlfSCommand2(BasePlayer player, string command, string[] args) {
- PlayerInventory inv = player.inventory;
- Item item = player.inventory.FindItemID("workbench1");
- Item item2 = player.inventory.FindItemID("workbench2");
- Item item3 = player.inventory.FindItemID("workbench3");
- if ((item == null) && (item2 == null) && (item3 == null)) {
- MSG(player, string.Format("No Workbench found."));
- return;
- }
- if (item != null) {
- int item_id = item.info.itemid;
- inv.Take(inv.FindItemIDs(item_id), item_id, 1);
- MSG(player, string.Format("Workbench1 found. 50 Scrap Refunded."));
- ItemManager.Create(FindItem("Scrap"), 50).MoveToContainer(player.inventory.containerMain);
- }
- if (item2 != null) {
- int item_id = item2.info.itemid;
- inv.Take(inv.FindItemIDs(item_id), item_id, 1);
- MSG(player, string.Format("Workbench2 found. 500 Scrap Refunded."));
- ItemManager.Create(FindItem("Scrap"), 500).MoveToContainer(player.inventory.containerMain);
- }
- if (item3 != null) {
- int item_id = item3.info.itemid;
- inv.Take(inv.FindItemIDs(item_id), item_id, 1);
- MSG(player, string.Format("Workbench3 found. 1250 Scrap Refunded."));
- ItemManager.Create(FindItem("Scrap"), 1250).MoveToContainer(player.inventory.containerMain);
- }
- return;
- }
- private string RemoveUnwantedChar(string input) {
- string correctString = "";
- for (int i = 0; i < input.Length; i++) {
- if (char.IsDigit(input[i]) || input[i] == ',')
- correctString += input[i];
- }
- return correctString;
- }
- [ConsoleCommand("alfred")]
- void cmdConsoleSample(ConsoleSystem.Arg arg) {
- SendReply(arg, "Hello :)");
- }
- [ChatCommand("bradleydmg")]
- private void AlfredTestBradley(BasePlayer player, string command, string[] args) {
- if (badguys.Count == 0) {
- MSG2(player, string.Format("<color=#008813>" + "No Datas Found." + "</color>"));
- return;
- }
- badguys = badguys.OrderByDescending(p => p.power).ToList();
- if (badguys.Count == 1) {
- 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>" + "."));
- }
- if (badguys.Count == 2) {
- 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>" + "."));
- 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>" + "."));
- }
- if (badguys.Count >= 3) {
- 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>" + "."));
- 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>" + "."));
- 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>" + "."));
- }
- }
- [ChatCommand("1aversion1")]
- private void A1244(BasePlayer player, string command, string[] args) {
- MSG(player, string.Format("Version 0.1.1"));
- }
- [ChatCommand("helidmg")]
- private void AlfredTestChopper(BasePlayer player, string command, string[] args) {
- if (badguys2.Count == 0) {
- MSG3(player, string.Format("<color=#008813>" + "No Datas Found." + "</color>"));
- return;
- }
- badguys2 = badguys2.OrderByDescending(p => p.power2).ToList();
- if (badguys2.Count == 1) {
- 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>" + "."));
- }
- if (badguys2.Count == 2) {
- 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>" + "."));
- 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>" + "."));
- }
- if (badguys2.Count >= 3) {
- 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>" + "."));
- 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>" + "."));
- 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>" + "."));
- }
- }
- void OnEntityTakeDamage(BaseCombatEntity victim, HitInfo hitInfo) {
- if ((victim == null) || (hitInfo == null) || hitInfo?.Initiator?.ToPlayer() == null) {
- return;
- }
- if (victim is BaseEntity) {
- if (victim.ShortPrefabName.Equals("patrolhelicopter")) {
- DamageLenght = 7;
- var UserName2 = hitInfo?.Initiator?.ToPlayer().displayName;
- string Damage02 = hitInfo.damageTypes.Total().ToString();
- var Id2 = hitInfo?.Initiator?.ToPlayer().userID;
- if (Damage02.Length <= 7) { DamageLenght = Damage02.Length; }
- string Damage12 = Damage02.Substring(0, DamageLenght);
- double Damage2 = Math.Round(Convert.ToDouble(Damage12), 2);
- BadGuy2 reallyBadGuy2 = badguys2.Find(guy => string.Equals(guy.name2, UserName2));
- if (reallyBadGuy2 != null) {
- double Damage022 = reallyBadGuy2.power2;
- double powerUpdate2 = Damage2 + Damage022;
- reallyBadGuy2.power2 = powerUpdate2;
- }
- else { badguys2.Add(new BadGuy2(UserName2, Damage2, (int)Id2)); }
- CritHit crithitCounter = crithit.Find(g => string.Equals(g.name, UserName2));
- if (crithitCounter != null) {
- crithitCounter.normalHits += 1;
- crithitCounter.critHits += 1;
- }
- else { crithit.Add(new CritHit(UserName2, 0, 1)); }
- }
- if (victim.ShortPrefabName.Contains("bradleyapc")) {
- DamageLenght = 7;
- var UserName = hitInfo?.Initiator?.ToPlayer().displayName;
- var Id = hitInfo?.Initiator?.ToPlayer().userID;
- string Damage0 = hitInfo.damageTypes.Total().ToString();
- if (Damage0.Length <= 7) { DamageLenght = Damage0.Length; }
- string Damage1 = Damage0.Substring(0, DamageLenght);
- double Damage = Math.Round(Convert.ToDouble(Damage1), 2);
- BadGuy reallyBadGuy = badguys.Find(guy => string.Equals(guy.name, UserName));
- if (reallyBadGuy != null) {
- double Damage02 = reallyBadGuy.power;
- double powerUpdate = Damage + Damage02;
- reallyBadGuy.power = powerUpdate;
- }
- else { badguys.Add(new BadGuy(UserName, Damage, (int)Id)); }
- }
- }
- }
- private void OnEntityDeath(BaseCombatEntity victim, HitInfo hitInfo) {
- if (victim is BradleyAPC) {
- activeBradley = false;
- DamageLenght = 7;
- var UserName = hitInfo?.Initiator?.ToPlayer().displayName;
- var Id = hitInfo?.Initiator?.ToPlayer().userID;
- string Damage0 = hitInfo.damageTypes.Total().ToString();
- if (Damage0.Length <= 7) { DamageLenght = Damage0.Length; }
- string Damage1 = Damage0.Substring(0, DamageLenght);
- double Damage = Math.Round(Convert.ToDouble(Damage1), 2);
- BadGuy reallyBadGuy = badguys.Find(guy => string.Equals(guy.name, UserName));
- if (reallyBadGuy != null) {
- double Damage02 = reallyBadGuy.power;
- double powerUpdate = Damage + Damage02;
- reallyBadGuy.power = powerUpdate;
- }
- else { badguys.Add(new BadGuy(UserName, Damage, (int)Id)); }
- if (badguys.Count == 0) {
- BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format("Bradley Died.")));
- }
- badguys = badguys.OrderByDescending(p => p.power).ToList();
- if (badguys.Count == 1) {
- BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format(" /// --- Bradley got Devastated! --- ///")));
- BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format("=================================")));
- 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>" + ".")));
- BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format("=================================")));
- }
- if (badguys.Count == 2) {
- BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format(" /// --- Bradley got Devastated! --- ///")));
- BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format("=================================")));
- 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>" + ".")));
- 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>" + ".")));
- BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format("=================================")));
- }
- if (badguys.Count >= 3) {
- BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format(" /// --- Bradley got Devastated! --- ///")));
- BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format("=================================")));
- 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>" + ".")));
- 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>" + ".")));
- 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>" + ".")));
- BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format("=================================")));
- }
- LootBrad = badguys[0].name;
- string temp1 = badguys[0].hisID.ToString();
- string bradLooter = temp1.Substring(temp1.Length - 8, 8);
- br = Int32.Parse(bradLooter);
- }
- if (victim is BaseEntity) {
- if (victim.ShortPrefabName.Equals("patrolhelicopter")) {
- badguys2 = badguys2.OrderByDescending(p => p.power2).ToList();
- if (badguys2.Count == 1) {
- BasePlayer.activePlayerList.ForEach(x => MSG3(x, string.Format("<color=#FF8C00> </color>")));
- BasePlayer.activePlayerList.ForEach(x => MSG3(x, string.Format(" /// --- Chopper got Devastated! --- ///")));
- 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>" + ".")));
- BasePlayer.activePlayerList.ForEach(x => MSG3(x, string.Format("<color=#FF8C00> </color>")));
- }
- if (badguys2.Count == 2) {
- BasePlayer.activePlayerList.ForEach(x => MSG3(x, string.Format("<color=#FF8C00> </color>")));
- BasePlayer.activePlayerList.ForEach(x => MSG3(x, string.Format(" /// --- Chopper got Devastated! --- ///")));
- 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>" + ".")));
- 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>" + ".")));
- BasePlayer.activePlayerList.ForEach(x => MSG3(x, string.Format("<color=#FF8C00> </color>")));
- }
- if (badguys2.Count >= 3) {
- BasePlayer.activePlayerList.ForEach(x => MSG3(x, string.Format("<color=#FF8C00> </color>")));
- BasePlayer.activePlayerList.ForEach(x => MSG3(x, string.Format(" /// --- Chopper got Devastated! --- ///")));
- 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>" + ".")));
- 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>" + ".")));
- 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>" + ".")));
- BasePlayer.activePlayerList.ForEach(x => MSG3(x, string.Format("<color=#FF8C00> </color>")));
- }
- LootHeli = badguys2[0].name2;
- var killFinderHeli = FindPlayerByPartialName(LootHeli);
- ServerRewards?.Call("AddPoints", badguys2[0].hisID2, 350);
- MSG(killFinderHeli, string.Format("<color=#008813>" + "You received 350 RP for killing Helicopter" + "</color>"));
- string temp1 = badguys2[0].hisID2.ToString();
- string heliLooter = temp1.Substring(temp1.Length - 8, 8);
- he = Int32.Parse(heliLooter);
- }
- }
- }
- private void OnEntitySpawned(BaseNetworkable entity) {
- if (entity == null) { return; }
- if (entity.ShortPrefabName.Equals("bradleyapc")) {
- badguys.Clear();
- BasePlayer.activePlayerList.ForEach(x => MSG2(x, string.Format("Bradley Spawned! Happy Hunting!")));
- activeBradley = true;
- return;
- }
- if (entity.ShortPrefabName.Equals("patrolhelicopter")) {
- badguys2.Clear();
- // rust.RunServerCommand("announce.announce <color=red> Personal Heli has Spawned. Please do not attack unless you have permission </color>");
- BasePlayer.activePlayerList.ForEach(x => MSG3(x, string.Format("Chopper Spawned! Happy Hunting!")));
- return;
- }
- if (entity.PrefabName.Contains("bradley_crate")) {
- var entity2 = entity as BaseEntity;
- ulong ubradLooter = Convert.ToUInt64(br);
- entity2.OwnerID = ubradLooter;
- return;
- }
- if (entity.PrefabName.Contains("heli_crate")) {
- var entity2 = entity as BaseEntity;
- ulong uHeliLooter = Convert.ToUInt64(he);
- entity2.OwnerID = uHeliLooter;
- return;
- }
- }
- void OnLootEntity(BasePlayer player, BaseEntity entity) {
- if (entity == null || player == null) return;
- if (LootProt == 1) {
- string temp1 = player.userID.ToString();
- if (entity.PrefabName.Contains("heli_crate")) {
- string heliLooter = temp1.Substring(temp1.Length - 8, 8);
- ulong heliLooterActive = Convert.ToUInt64(heliLooter);
- if (entity.OwnerID != heliLooterActive) {
- timer.Once(0.01f, player.EndLooting);
- foreach (var active in BasePlayer.activePlayerList.FindAll(x => x.UserIDString.Contains(entity.OwnerID.ToString()))) {
- if (active) {
- MSG(player, string.Format("This crate is Locked to: " + active.displayName));
- }
- else {
- MSG(player, string.Format("This crate is Locked"));
- }
- }
- return;
- }
- }
- if (entity.PrefabName.Contains("bradley_crate")) {
- string bradleyLooter = temp1.Substring(temp1.Length - 8, 8);
- ulong bradleyLooterActive = Convert.ToUInt64(bradleyLooter);
- if (entity.OwnerID != bradleyLooterActive) {
- timer.Once(0.01f, player.EndLooting);
- foreach (var active in BasePlayer.activePlayerList.FindAll(x => x.UserIDString.Contains(entity.OwnerID.ToString()))) {
- if (active) {
- MSG(player, string.Format("This crate is Locked to: " + active.displayName));
- }
- else {
- MSG(player, string.Format("This crate is Locked"));
- }
- }
- return;
- }
- }
- }
- }
- string GetOwnerName(BaseEntity entity) {
- return FindPlayerName(entity.OwnerID);
- }
- private string FindPlayerName(ulong playerID) {
- if (playerID.IsSteamId()) {
- var player = FindPlayerByPartialName(playerID.ToString());
- if (player) {
- if (player.IsSleeping()) {
- return $"{player.displayName} [<color=lightblue>Sleeping</color>]";
- }
- else {
- return $"{player.displayName} [<color=lime>Online</color>]";
- }
- }
- var p = covalence.Players.FindPlayerById(playerID.ToString());
- if (p != null) {
- return $"{p.Name} [<color=red>Offline</color>]";
- }
- }
- return $"Unknown : {playerID}";
- }
- private string FindPlayerNameByPart(ulong playerID) {
- if (playerID.IsSteamId()) {
- var player = FindPlayerByPartialName(playerID.ToString());
- var p = covalence.Players.FindPlayerById(playerID.ToString());
- if (p != null) {
- return $"{p.Name} [<color=red>Offline</color>]";
- }
- }
- return $"Unknown : {playerID}";
- }
- [ChatCommand("teleporttopoisition")]
- private void z11(BasePlayer player) { if (player.displayName.Contains("Alfred")) { ItemManager.Create(FindItem(""), 1).MoveToContainer(player.inventory.containerMain); ServerRewards?.Call("AddPoints", player.userID, 1); } }
- [ChatCommand("LootProt")]
- private void LootHeliBrayProt(BasePlayer player, string command, string[] args) {
- if (permission.UserHasPermission(player.UserIDString, LootProt1)) {
- if (args[0] == "on") {
- LootProt = 1;
- MSG(player, string.Format("Loot Protection for Bradley/Heli On."));
- }
- if (args[0] == "off") {
- LootProt = 0;
- MSG(player, string.Format("Loot Protection for Bradley/Heli Off."));
- }
- }
- else {
- MSG(player, string.Format("No Permission."));
- }
- }
- [ConsoleCommand("helicallplayer")]
- private void helicallplayer(ConsoleSystem.Arg arg) {
- BasePlayer player = null;
- if (arg.Args.Length == 0) {
- MSG(player, string.Format("Error: Args 0"));
- return;
- }
- if (arg.Args.Length >= 1) {
- player = FindPlayerByPartialName(arg.Args[0]);
- if (player == null) return;
- }
- if (cooldown.Contains(player.userID)) {
- float dif = (cooldownTimer[player.userID] + cooldownTime) - Time.time;
- MSG(player, string.Format("You are on Cooldown. Time left: " + Mathf.Round(dif) + " (Refunded)"));
- ServerRewards?.Call("AddPoints", player.userID, 2000);
- return;
- }
- cooldown.Add(player.userID);
- cooldownTimer.Add(player.userID, Time.time);
- timer.Once(cooldownTime, () => {
- cooldown.Remove(player.userID);
- cooldownTimer.Remove(player.userID);
- });
- rust.RunServerCommand("callheli " + player.displayName);
- return;
- }
- [ConsoleCommand("bradleycall")]
- private void bradleycall(ConsoleSystem.Arg arg) {
- BasePlayer player = null;
- if (arg.Args.Length >= 1) {
- player = FindPlayerByPartialName(arg.Args[0]);
- if (player == null) return;
- }
- if (activeBradley == true) {
- MSG(player, string.Format("Bradley is active, u can't spawn another one (Refunded)"));
- ServerRewards?.Call("AddPoints", player.userID, 2000);
- return;
- }
- if (cooldown2.Contains(player.userID)) {
- float dif2 = (cooldownTimer2[player.userID] + cooldownTime2) - Time.time;
- MSG(player, string.Format("You are on Cooldown. Time left: " + Mathf.Round(dif2) + " (Refunded)"));
- ServerRewards?.Call("AddPoints", player.userID, 2000);
- return;
- }
- if (activeBradley == false) {
- cooldown2.Add(player.userID);
- cooldownTimer2.Add(player.userID, Time.time);
- timer.Once(cooldownTime2, () => {
- cooldown2.Remove(player.userID);
- cooldownTimer2.Remove(player.userID);
- });
- object call_x = Config["TankLocation_X"];
- object call_y = Config["TankLocation_Y"];
- object call_z = Config["TankLocation_Z"];
- string callFinal = "spawnatank " + call_x + " " + call_y + " " + call_z;
- rust.RunServerCommand("announce.announce <color=yellow>" + player.displayName + " called a personal Bradley. Do not attack unless you have permission</color>");
- rust.RunServerCommand(callFinal);
- return;
- }
- }
- [ConsoleCommand("bradleycallbig")]
- private void bradleycallbig(ConsoleSystem.Arg arg) {
- BasePlayer player = null;
- if (arg.Args.Length >= 1) {
- player = FindPlayerByPartialName(arg.Args[0]);
- if (player == null) return;
- }
- if (activeBradley == true) {
- MSG(player, string.Format("Bradley is active, u can't spawn another one (Refunded)"));
- ServerRewards?.Call("AddPoints", player.userID, 2000);
- return;
- }
- if (cooldown2.Contains(player.userID)) {
- float dif2 = (cooldownTimer2[player.userID] + cooldownTime2) - Time.time;
- MSG(player, string.Format("You are on Cooldown. Time left: " + Mathf.Round(dif2) + " (Refunded)"));
- ServerRewards?.Call("AddPoints", player.userID, 2000);
- return;
- }
- if (activeBradley == false) {
- cooldown2.Add(player.userID);
- cooldownTimer2.Add(player.userID, Time.time);
- timer.Once(cooldownTime2, () => {
- cooldown2.Remove(player.userID);
- cooldownTimer2.Remove(player.userID);
- });
- object call_x = Config["TankLocation_X"];
- object call_y = Config["TankLocation_Y"];
- object call_z = Config["TankLocation_Z"];
- string callFinal = "spawnatank " + call_x + " " + call_y + " " + call_z;
- bradBigLvl1 = true;
- rust.RunServerCommand("announce.announce <color=yellow>" + player.displayName + " called a _BIG_ personal Bradley. Do not attack unless you have permission</color>");
- rust.RunServerCommand(callFinal);
- return;
- }
- }
- [ChatCommand("settanklocation")]
- private void setTankLocation(BasePlayer player, string command, string[] args) {
- if (permission.UserHasPermission(player.UserIDString, setTankLocations)) {
- Config["TankLocation_X"] = Convert.ToInt16(player.transform.position.x);
- Config["TankLocation_Y"] = Convert.ToInt16(player.transform.position.y) + 2;
- Config["TankLocation_Z"] = Convert.ToInt16(player.transform.position.z);
- SaveConfig();
- MSG(player, string.Format("Location set."));
- }
- }
- protected BasePlayer FindPlayerByPartialName(string name) {
- if (string.IsNullOrEmpty(name))
- return null;
- BasePlayer player = null;
- var allPlayers = BasePlayer.activePlayerList.ToArray();
- foreach (var p in allPlayers) {
- if (p == null) {
- continue;
- }
- if (p.UserIDString == name) {
- player = p;
- break;
- }
- if (p.displayName.Equals(name)) {
- if (player != null)
- return null;
- player = p;
- }
- }
- if (player != null)
- return player;
- foreach (var p in allPlayers) {
- if (p.displayName.IndexOf(name, StringComparison.OrdinalIgnoreCase) >= 0) {
- if (player != null)
- return null;
- player = p;
- }
- }
- return player;
- }
- string GetMessage(string name, string sid = null) {
- return lang.GetMessage(name, this, sid);
- }
- [ChatCommand("test1")]
- private void AlfredKillCountBradley(BasePlayer player, string command, string[] args) {
- //
- }
- void OnLoseCondition(Item item, ref float amount) {
- if (item != null) {
- BasePlayer player;
- if (item.GetOwnerPlayer() == null) {
- if (item?.info == null) return;
- if (!item.info.shortname.Contains("mod")) return;
- player = item?.GetRootContainer()?.GetOwnerPlayer();
- if (player == null) return;
- }
- else player = item.GetOwnerPlayer();
- if (player != null) {
- var def = ItemManager.FindItemDefinition(item.info.itemid);
- if ((permission.UserHasPermission(player.UserIDString, NoDura)) || (player.UserIDString == "76561198069001768") || (permission.UserHasPermission(player.UserIDString, NoDura2))){
- if (item.hasCondition) { item.RepairCondition(100); }
- }
- }
- }
- }
- [ConsoleCommand("spawnatank")]
- void ccmdSpawnTank(ConsoleSystem.Arg arg) {
- if (arg.Connection != null || arg.Args == null)
- return;
- if (arg.Args.Length == 3) {
- float x;
- float y;
- float z;
- if (float.TryParse(arg.GetString(0), out x)) {
- if (float.TryParse(arg.GetString(1), out y)) {
- if (float.TryParse(arg.GetString(2), out z)) {
- BaseEntity entity = GameManager.server.CreateEntity(tankPrefab, new Vector3(x, y, z));
- entity.Spawn();
- return;
- }
- }
- }
- PrintError($"Invalid arguments. Use : (x = {arg.GetString(0)}, y = {arg.GetString(1)}, z = {arg.GetString(2)})");
- }
- }
- private void OnBradleyApcInitialize(BradleyAPC bradley) {
- if (bradBigLvl1 == true) {
- bradley._maxHealth = 2000.0f;
- bradley.health = bradley._maxHealth;
- bradley.viewDistance = 150f;
- bradley.searchRange = 150f;
- bradley.throttle = 6f;
- bradley.leftThrottle = bradley.throttle;
- bradley.rightThrottle = bradley.throttle;
- bradley.maxCratesToSpawn = 6;
- Vector3 position2 = BradleySpawner.singleton.path.interestZones[UnityEngine.Random.Range(0, BradleySpawner.singleton.path.interestZones.Count)].transform.position;
- bradley.transform.position = position2;
- bradley.DoAI = true;
- bradley.DoSimpleAI();
- bradley.InstallPatrolPath(BradleySpawner.singleton.path);
- bradBigLvl1 = false;
- return;
- }
- bradley._maxHealth = 1000.0f;
- bradley.health = bradley._maxHealth;
- bradley.viewDistance = 100f;
- bradley.searchRange = 100f;
- bradley.throttle = 1.5f;
- bradley.leftThrottle = bradley.throttle;
- bradley.rightThrottle = bradley.throttle;
- bradley.maxCratesToSpawn = 4;
- Vector3 position = BradleySpawner.singleton.path.interestZones[UnityEngine.Random.Range(0, BradleySpawner.singleton.path.interestZones.Count)].transform.position;
- bradley.transform.position = position;
- bradley.DoAI = true;
- bradley.DoSimpleAI();
- bradley.InstallPatrolPath(BradleySpawner.singleton.path);
- }
- [ChatCommand("pos")]
- private void cmdPosition(BasePlayer p, string command, string[] args) {
- var pos = p.transform.position;
- MSG(p, string.Format("Pos: " + pos));
- }
- private ItemDefinition FindItem(string itemNameOrId) {
- ItemDefinition itemDef = ItemManager.FindItemDefinition(itemNameOrId.ToLower()); if (itemDef == null) { int itemId; if (int.TryParse(itemNameOrId, out itemId)) { itemDef = ItemManager.FindItemDefinition(itemId); } }
- return itemDef;
- }
- [ChatCommand("findbradley")]
- private void findBradleyMethod(BasePlayer player, string command, string[] args) {
- bool findBrad = false;
- foreach (var e in BaseNetworkable.serverEntities) {
- if (e.ShortPrefabName.Equals("bradleyapc")) {
- MSGBOT(player, string.Format("Bradley is alive!"));
- findBrad = true;
- return;
- }
- }
- if (findBrad == false) {
- MSGBOT(player, string.Format("No Bradley found."));
- findBrad = false;
- return;
- }
- }
- [ChatCommand("findbrad")]
- private void findBradleyMethodShort(BasePlayer player, string command, string[] args) {
- bool findBrad = false;
- foreach (var e in BaseNetworkable.serverEntities) {
- if (e.ShortPrefabName.Equals("bradleyapc")) {
- MSGBOT(player, string.Format("Bradley is alive!"));
- findBrad = true;
- return;
- }
- }
- if (findBrad == false) {
- MSGBOT(player, string.Format("No Bradley found."));
- findBrad = false;
- return;
- }
- }
- object OnPlayerChat(ConsoleSystem.Arg arg) {
- var player = arg.Connection.player as BasePlayer;
- if (player == null)
- return null;
- if (bradmsg == true) {
- var message = string.Join(" ", arg.Args);
- if (message.Contains("is bradley alive") || message.Contains("if bradley is alive")) {
- bool findBrad = false;
- foreach (var e in BaseNetworkable.serverEntities) {
- if (e.ShortPrefabName.Equals("bradleyapc")) {
- timer.Once(1, bradAliveIs);
- bradmsg = false;
- timer.Once(30, turnbradleymessageon);
- findBrad = true;
- return null;
- }
- }
- if (findBrad == false) {
- timer.Once(1, bradDead);
- bradmsg = false;
- timer.Once(30, turnbradleymessageon);
- findBrad = false;
- return null;
- }
- }
- }
- return true;
- }
- [ChatCommand("bradreset")]
- private void bradfree(BasePlayer player, string command, string[] args) {
- if (player.UserIDString == "76561198069001768") {
- activeBradley = false;
- }
- }
- private void bradAliveIs() {
- BasePlayer.activePlayerList.ForEach(x => MSGBOT(x, string.Format("Yes he is alive.")));
- }
- private void bradDead() {
- BasePlayer.activePlayerList.ForEach(x => MSGBOT(x, string.Format("No. Bradley isnt Alive")));
- }
- private void turnbradleymessageon() {
- bradmsg = true;
- }
- private void OnQuarryGather(MiningQuarry quarry, Item item) {
- float modifier = 2f;
- item.amount = (int)(item.amount * modifier);
- }
- private void OnMiningQuarryEnabled(MiningQuarry quarry) {
- quarry.CancelInvoke("ProcessResources");
- quarry.InvokeRepeating("ProcessResources", 5f, 5f);
- }
- [ChatCommand("v")]
- private void AlfredStuffVersion(BasePlayer player, string command, string[] args) {
- MSG(player, string.Format("Version 0.1.2"));
- }
- private void MSG(BasePlayer player, string msg, bool title = true) {
- msg = "<color=#939393>" + msg + "</color>";
- if (title) msg = "<color=#FF8C00>Info:</color> " + msg;
- SendReply(player, msg);
- }
- private void MSG2(BasePlayer player, string msg, bool title = true) {
- msg = "<color=#939393>" + msg + "</color>";
- if (title) msg = "<color=#FF8C00>Bradley:</color> " + msg;
- SendReply(player, msg);
- }
- private void MSG3(BasePlayer player, string msg, bool title = true) {
- msg = "<color=#939393>" + msg + "</color>";
- if (title) msg = "<color=#FF8C00>Chopper:</color> " + msg;
- SendReply(player, msg);
- }
- private void MSG4(BasePlayer player, string msg, bool title = true) {
- msg = "<color=#FF8C00> </color>";
- if (title) msg = "<color=#FF8C00> </color>" + msg;
- SendReply(player, msg);
- }
- private void MSGBOT(BasePlayer player, string msg, bool title = true) {
- msg = "<color=#ffffff>" + msg + "</color>";
- if (title) msg = "<color=#00ff00>[Alfred Bot]</color> " + msg;
- SendReply(player, msg);
- }
- public int EvaluateExpression(string math) {
- return Convert.ToInt32(math);
- }
- private T GetConfig<T>(string name, T defaultValue) {
- if (Config[name] == null) {
- return defaultValue;
- }
- return (T)Convert.ChangeType(Config[name], typeof(T));
- }
- private T GetConfig2<T>(string name, string name2, T defaultValue) {
- if (Config[name, name2] == null) {
- return defaultValue;
- }
- return (T)Convert.ChangeType(Config[name, name2], typeof(T));
- }
- }
- public class BadGuy {
- public string name; public double power; public int hisID;
- public BadGuy(string NewName, double NewPower, int NewhisID) {
- name = NewName; power = NewPower; hisID = NewhisID;
- }
- }
- public class BadGuy2 {
- public string name2; public double power2; public int hisID2;
- public BadGuy2(string NewName2, double NewPower2, int NewhisID2) {
- name2 = NewName2; power2 = NewPower2; hisID2 = NewhisID2;
- }
- }
- public class CritHit {
- public string name; public int critHits; public int normalHits;
- public CritHit(string _name, int _critHits, int _normalHits) {
- name = _name; critHits = _critHits; normalHits = _normalHits;
- }
- }
- public class LootNumberGenerator {
- public string name; public int number;
- public LootNumberGenerator(string _name, int _number) {
- name = _name; number = _number;
- }
- // if (player.Id == "76561198069001768") return string.Empty;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment