Advertisement
Guest User

aimTrain.cs

a guest
Jan 22nd, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 12.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System.Reflection;
  5. using Oxide.Core;
  6.  
  7. namespace Oxide.Plugins
  8. {
  9.     #region zone
  10.     public class Zone
  11.     {
  12.         public List<int> Bots;
  13.         //public List<Bot> BotsObj;
  14.        
  15.  
  16.         public virtual void Start()
  17.         {
  18.  
  19.         }
  20.     }
  21.     #endregion
  22.  
  23.     #region bot
  24.     public class Bot
  25.     {
  26.         public ulong Id;
  27.         public int ZoneId;
  28.  
  29.         public float PosX;
  30.         public float PosY;
  31.         public float PosZ;
  32.  
  33.         private BasePlayer BasePlayer;
  34.  
  35.         public Bot(int zone, ulong id, Vector3 position)
  36.         {
  37.             Id = id;
  38.  
  39.             PosX = position.x;
  40.             PosY = position.y;
  41.             PosZ = position.z;
  42.         }
  43.  
  44.         #region main methods
  45.         public /*BasePlayer*/void Spawn()
  46.         {
  47.             AimTrain.Instance.Chat("Spawning!");
  48.  
  49.             var newPlayer = GameManager.server.CreateEntity("assets/prefabs/player/player.prefab", GetPos(), Quaternion.identity);
  50.             newPlayer.Spawn();
  51.  
  52.             newPlayer.SetFlag(BaseEntity.Flags.Reserved1, true);
  53.             FieldInfo modelStateField = typeof(BasePlayer).GetField("modelState", BindingFlags.Instance | BindingFlags.NonPublic);
  54.             object modelState = modelStateField.GetValue(newPlayer);
  55.             modelState.GetType().GetProperty("onground").SetValue(modelState, true, null);
  56.  
  57.             newPlayer.SendNetworkUpdate();
  58.  
  59.             BasePlayer = newPlayer.GetComponent<BasePlayer>();
  60.             BasePlayer.userID = Id;
  61.            
  62.             //BotsObj.add(newPlayer);
  63.  
  64.             AimTrain.Instance.Chat("Spawned!");
  65.             //return BasePlayer;
  66.         }
  67.  
  68.         public void Kill()
  69.         {
  70.             if(BasePlayer != null)
  71.             {
  72.                 BasePlayer.Kill();
  73.                 BasePlayer.SendNetworkUpdate();
  74.             }
  75.         }
  76.         #endregion
  77.  
  78.         #region utility methods
  79.         Vector3 GetPos()
  80.         {
  81.             return new Vector3(PosX, PosY, PosZ);
  82.         }
  83.         #endregion
  84.     }
  85.     #endregion
  86.  
  87.     #region plugin
  88.     [Info("AimTrain", "Ardivaba", 0.1)]
  89.     [Description("Mkes you Trauzillz")]
  90.     public class AimTrain : RustPlugin
  91.     {
  92.         #region data
  93.         public static AimTrain Instance;
  94.         public static HashSet<Bot> Bots;
  95.         public static bool Moving = true;
  96.         public int i = 0;
  97.         //public static List<BasePlayer> botObjects = new List<BasePlayer>();
  98.        
  99.         StashContainer[] stashes = GameObject.FindObjectsOfType<StashContainer>();
  100.         BasePlayer[] players = GameObject.FindObjectsOfType<BasePlayer>();
  101.         #endregion
  102.  
  103.         #region public static main methods
  104.         public static void CreateBot(Vector3 position)
  105.         {
  106.             Bot bot = new Bot(0, (ulong) Bots.Count, position);
  107.  
  108.             //botObjects.Add(bot.Spawn());
  109.             bot.Spawn();
  110.             Bots.Add(bot);
  111.  
  112.             AimTrain.SaveBots();
  113.         }
  114.  
  115.         public static void LoadBots()
  116.         {
  117.             Bots = Interface.Oxide.DataFileSystem.ReadObject<HashSet<Bot>>("Bots");
  118.         }
  119.  
  120.         public static void SaveBots()
  121.         {
  122.             Interface.Oxide.DataFileSystem.WriteObject<HashSet<Bot>>("Bots", Bots, true);
  123.         }
  124.         #endregion
  125.  
  126.         #region main methods
  127.         public void Chat(string chat)
  128.         {
  129.             PrintToChat(chat);
  130.         }
  131.  
  132.         void UnlimitedAmmo(BaseProjectile projectile, BasePlayer player)
  133.         {
  134.             projectile.GetItem().condition = projectile.GetItem().info.condition.max;
  135.             projectile.primaryMagazine.contents = projectile.primaryMagazine.capacity;
  136.             projectile.SendNetworkUpdateImmediate();
  137.         }
  138.         #endregion
  139.  
  140.         #region oxide hooks
  141.         void OnFrame()
  142.         {
  143.             if(i<=20){
  144.                 i++;
  145.                 return;
  146.             }
  147.             else{
  148.                 i = 0;
  149.                 stashes = GameObject.FindObjectsOfType<StashContainer>();
  150.                 players = GameObject.FindObjectsOfType<BasePlayer>();//botObjects.ToArray();//
  151.             }
  152.            
  153.            
  154.             int botCount = 0;
  155.             foreach(BasePlayer player in players)
  156.             {
  157.                 if (player.IsWounded() && player.HasFlag(BaseEntity.Flags.Reserved1))
  158.                 {
  159.                     player.Kill();
  160.                     //botObjects.Remove(player);
  161.                     player.SendNetworkUpdate();
  162.                     headShots++;
  163.                 }
  164.                 if (player.HasFlag(BaseEntity.Flags.Reserved1))
  165.                 {
  166.                     botCount++;
  167.                 }
  168.             }
  169.  
  170.             if(botCount < botCounts && stashes.Length > 0)
  171.             {
  172.                 StashContainer randomStash = stashes[UnityEngine.Random.Range(0, stashes.Length - 1)];
  173.                 SpawnBot(randomStash.transform.position);
  174.             }
  175.         }
  176.  
  177.         void Loaded()
  178.         {
  179.             AimTrain.Instance = this;
  180.             AimTrain.LoadBots();
  181.         }
  182.  
  183.         void OnWeaponFired(BaseProjectile projectile, BasePlayer player)
  184.         {
  185.                 //UnlimitedAmmo(projectile, player);
  186.         }
  187.  
  188.         int headShots = 0;
  189.         void OnPlayerAttack(BasePlayer attacker, HitInfo info)
  190.         {
  191.             return;
  192.             BasePlayer victim = info.HitEntity.GetComponent<BasePlayer>();
  193.             if(victim != null)
  194.             {
  195.                 if(victim.HasFlag(BaseEntity.Flags.Reserved1))
  196.                 {
  197.                     if (info.isHeadshot)
  198.                     {
  199.                         //headShots++;
  200.                     }
  201.                 }
  202.             }
  203.  
  204.             if(headShots == 20)
  205.             {
  206.                 PrintToChat("Headshot benchmark time: " + (DateTime.Now - startTime).TotalSeconds);
  207.                 headShots = 0;
  208.                 foreach (Bot bot in Bots)
  209.                 {
  210.                     bot.Kill();
  211.                 }
  212.             }
  213.         }
  214.         #endregion
  215.  
  216.         int botCounts = 3;
  217.         #region commands
  218.         [ConsoleCommand("botCount")]
  219.         void CmdBotCount(ConsoleSystem.Arg arg)
  220.         {
  221.             botCounts = int.Parse(arg.Args[0]);
  222.             PrintToChat("Bot count is now: " + botCounts);
  223.         }
  224.  
  225.         [ConsoleCommand("createBot")]
  226.         void CmdCreateBot(ConsoleSystem.Arg arg)
  227.         {
  228.             CreateBot(arg.Player().transform.position);
  229.             PrintToChat("Where them bots at?");
  230.         }
  231.  
  232.         [ConsoleCommand("killBots")]
  233.         void CmdKillBots(ConsoleSystem.Arg arg)
  234.         {
  235.             foreach(Bot bot in Bots)
  236.             {
  237.                 bot.Kill();
  238.             }
  239.         }
  240.  
  241.  
  242.         [ConsoleCommand("stashes")]
  243.         void CmdStashes(ConsoleSystem.Arg arg)
  244.         {
  245.             StashContainer[] stashes = GameObject.FindObjectsOfType<StashContainer>();
  246.             foreach (StashContainer stash in stashes)
  247.             {
  248.                 stash.Kill();
  249.                 stash.SendNetworkUpdate();
  250.             }
  251.         }
  252.  
  253.         [ConsoleCommand("moving")]
  254.         void CmdMoving(ConsoleSystem.Arg arg)
  255.         {
  256.             AimTrain.Moving = !AimTrain.Moving;
  257.         }
  258.  
  259.         DateTime startTime;
  260.  
  261.         [ConsoleCommand("kcmo")]
  262.         void CmdKcmo(ConsoleSystem.Arg arg)
  263.         {
  264.             headShots = 0;
  265.             startTime = DateTime.Now;
  266.  
  267.             BasePlayer[] players = GameObject.FindObjectsOfType<BasePlayer>();
  268.             foreach(BasePlayer player in players)
  269.             {
  270.                 if (player.HasFlag(BaseEntity.Flags.Reserved1))
  271.                 {
  272.                     player.Kill();
  273.                     player.SendNetworkUpdate();
  274.                 }
  275.             }
  276.  
  277.             BaseCorpse[] corpses = GameObject.FindObjectsOfType<BaseCorpse>();
  278.             foreach(BaseCorpse corpse in corpses)
  279.             {
  280.                 corpse.Kill();
  281.                 corpse.SendNetworkUpdate();
  282.             }
  283.         }
  284.  
  285.         void SpawnBot(Vector3 position)
  286.         {
  287.             //AimTrain.Instance.Chat("Spawning!");
  288.  
  289.             var newPlayer = GameManager.server.CreateEntity("assets/prefabs/player/player.prefab", position, Quaternion.identity);
  290.             newPlayer.Spawn();
  291.             newPlayer.gameObject.AddComponent<BotMover>();
  292.  
  293.             newPlayer.SetFlag(BaseEntity.Flags.Reserved1, true);
  294.             FieldInfo modelStateField = typeof(BasePlayer).GetField("modelState", BindingFlags.Instance | BindingFlags.NonPublic);
  295.             object modelState = modelStateField.GetValue(newPlayer);
  296.             modelState.GetType().GetProperty("onground").SetValue(modelState, true, null);
  297.  
  298.             newPlayer.SendNetworkUpdate();
  299.  
  300.             //AimTrain.Instance.Chat("Spawned!");
  301.         }
  302.         #endregion
  303.     }
  304.     #endregion
  305.  
  306.     #region
  307.     public class BotMover : MonoBehaviour
  308.     {
  309.         StashContainer[] stashes = GameObject.FindObjectsOfType<StashContainer>();
  310.         BasePlayer basePlayer;
  311.         Vector3 startPosition;
  312.         Vector3 targetPosition;
  313.         float moveSpeed = 1.0f;
  314.         void Start()
  315.         {
  316.             basePlayer = GetComponent<BasePlayer>();
  317.             startPosition = transform.position;
  318.             targetPosition = startPosition;
  319.             moveSpeed = UnityEngine.Random.Range(0.1f, 0.3f);
  320.             basePlayer.ChangeHealth(100.0f);
  321.             basePlayer.SendNetworkUpdate();
  322.  
  323.             int random = UnityEngine.Random.Range(0, 3);
  324.             int clothes = UnityEngine.Random.Range(0, 2);
  325.  
  326.             if(random == 0)//Metal
  327.             {
  328.                 basePlayer.inventory.GiveItem(ItemManager.CreateByItemID(-46848560), basePlayer.inventory.containerWear);
  329.                 basePlayer.inventory.GiveItem(ItemManager.CreateByItemID(1265861812), basePlayer.inventory.containerWear);
  330.                 basePlayer.inventory.GiveItem(ItemManager.CreateByItemID(-1595790889), basePlayer.inventory.containerWear);
  331.             }
  332.             else if( random == 1 )
  333.             {
  334.                 int random2 = UnityEngine.Random.Range(0, 2);
  335.                 if(random2 == 0)
  336.                 {
  337.                     basePlayer.inventory.GiveItem(ItemManager.CreateByItemID(1260209393), basePlayer.inventory.containerWear);
  338.                 }
  339.                 else if( random2 == 1)
  340.                 {
  341.                     basePlayer.inventory.GiveItem(ItemManager.CreateByItemID(-2128719593), basePlayer.inventory.containerWear);
  342.                 }
  343.  
  344.                 basePlayer.inventory.GiveItem(ItemManager.CreateByItemID(-288010497), basePlayer.inventory.containerWear);
  345.                 basePlayer.inventory.GiveItem(ItemManager.CreateByItemID(-1595790889), basePlayer.inventory.containerWear);
  346.             }
  347.  
  348.             if(clothes == 0)
  349.             {
  350.                 basePlayer.inventory.GiveItem(ItemManager.CreateByItemID(115739308), basePlayer.inventory.containerWear);
  351.                 basePlayer.inventory.GiveItem(ItemManager.CreateByItemID(707427396), basePlayer.inventory.containerWear);
  352.                 basePlayer.inventory.GiveItem(ItemManager.CreateByItemID(1767561705), basePlayer.inventory.containerWear);
  353.             }
  354.             if (clothes == 1)
  355.             {
  356.                 basePlayer.inventory.GiveItem(ItemManager.CreateByItemID(106433500), basePlayer.inventory.containerWear);
  357.                 basePlayer.inventory.GiveItem(ItemManager.CreateByItemID(-1211618504), basePlayer.inventory.containerWear);
  358.                 basePlayer.inventory.GiveItem(ItemManager.CreateByItemID(115739308), basePlayer.inventory.containerWear);
  359.             }
  360.         }
  361.  
  362.         void FixedUpdate()
  363.         {
  364.             if (!AimTrain.Moving)
  365.             {
  366.                 return;
  367.             }
  368.  
  369.             if(Vector3.Distance(transform.position, targetPosition) < 1.0f)
  370.             {
  371.                 //targetPosition = startPosition + transform.right * UnityEngine.Random.Range(-15, 15);
  372.                 //StashContainer[] stashes = GameObject.FindObjectsOfType<StashContainer>();
  373.                 StashContainer randomStash = stashes[UnityEngine.Random.Range(0, stashes.Length - 1)];
  374.                 targetPosition = randomStash.transform.position;
  375.             }
  376.  
  377.             Vector3 newPos = Vector3.Lerp(transform.position, targetPosition, Time.fixedDeltaTime * moveSpeed);
  378.             newPos = Vector3.MoveTowards(transform.position, targetPosition, moveSpeed);
  379.             basePlayer.transform.position = newPos;
  380.             basePlayer.Teleport(basePlayer);
  381.             basePlayer.SendNetworkUpdate();
  382.         }
  383.     }
  384.     #endregion
  385. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement