예제 #1
0
        public void OnPlayerPickupItem(PlayerPickupItemEvent ev)
        {
            plugin.Info(ev.Player.Name + " picked up item " + ev.Item.ItemType);
            //Checks the itemtype of the picked up item
            if (ev.Item.ItemType == Smod2.API.ItemType.COIN)
            {
                double luckyValue = random.NextDouble();

                // Chance of instantly dying
                if (luckyValue < plugin.killChance)
                {
                    ev.Player.Kill();
                }
                else
                {
                    // An array lets other plugins set the values of it in events.
                    Smod2.API.ItemType[] itemPtr = { Smod2.API.ItemType.MICROHID };
                    plugin.InvokeEvent("courtney.example.plugin", itemPtr);

                    // Get the singular item from the array since indexing it every time is annoying.
                    Smod2.API.ItemType item = itemPtr[0];

                    // lottoItemCount is automatically read and converted to an int. This gives the item lottoItemCount times to the player.
                    int count = plugin.lottoItemCount;
                    plugin.Info($"{nameof(plugin.lottoItemCount)} is {count}");
                    for (int i = 0; i < count; i++)
                    {
                        ev.Player.GiveItem(item);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Safely getting a <see cref="Smod2.API.ItemType"/> from a <see cref="string"/>.
        /// <returns>Returns <see cref="bool"/> based on success</returns>
        /// <para>Tries to cast to <see cref="int"/> first, then compares names</para>
        /// </summary>
        public static bool TryParseItem(string item, out SMItemType itemType)
        {
            itemType = SMItemType.NONE;

            try
            {
                if (int.TryParse(item, out int x))
                {
                    return(TryParseItem(x, out itemType));
                }

                foreach (SMItemType i in Enum.GetValues(typeof(SMItemType)))
                {
                    if (i.ToString().ToUpper().Contains(item.ToUpper()))
                    {
                        itemType = i;
                        return(true);
                    }
                }
                return(true);
            }
            catch
            {
                itemType = SMItemType.NONE;
                return(false);
            }
        }
예제 #3
0
 /// <summary>
 /// Safely getting a <see cref="Smod2.API.ItemType"/> from an <see cref="int"/>.
 /// <returns>Returns <see cref="bool"/> based on success</returns>
 /// <para>Invalid <see cref="int"/> parameters returns <see cref="Smod2.API.ItemType.NONE"/></para>
 /// </summary>
 public static bool TryParseItem(int itemID, out SMItemType itemType)
 {
     try
     {
         itemType = (SMItemType)itemID;
     }
     catch
     {
         itemType = SMItemType.NONE;
         return(false);
     }
     return(true);
 }
예제 #4
0
        public override void EventStart(RoundStartEvent ev)
        {
            List <Smod2.API.Door> doors = ev.Server.Map.GetDoors();

            doors.Find(x => x.Name == "CHECKPOINT_LCZ_A").Locked = true;
            doors.Find(x => x.Name == "CHECKPOINT_LCZ_B").Locked = true;
            foreach (Smod2.API.Door door in doors)
            {
                Vector vec = door.Position;
                int    rng = random.Next(0, 6);
                for (int i = 0; i < rng; i++)
                {
                    int    x         = random.Next(Convert.ToInt32(vec.x - 15f), Convert.ToInt32(vec.x + 15f));
                    int    z         = random.Next(Convert.ToInt32(vec.z - 15f), Convert.ToInt32(vec.z + 15f));
                    int    y         = Convert.ToInt32(vec.y + 1);
                    Vector spanw_pos = new Vector(x, y, z);

                    Array values            = Enum.GetValues(typeof(Props));
                    Smod2.API.ItemType item = (Smod2.API.ItemType)values.GetValue(random.Next(values.Length));
                    ev.Server.Map.SpawnItem(item, spanw_pos, Vector.Zero);
                }
            }
            actualHunters = GetHunterId();
            foreach (Player player in ev.Server.GetPlayers())
            {
                if (!actualHunters.Contains(player.PlayerId))
                {
                    player.ChangeRole(Smod2.API.RoleType.CLASSD);
                    player.SetGhostMode(true, visibleWhenTalking: false);
                    player.SetHealth(50);
                    Array values = Enum.GetValues(typeof(Props));
                    Smod2.API.ItemType itemtype = (Smod2.API.ItemType)values.GetValue(random.Next(values.Length));
                    Smod2.API.Item     item     = ev.Server.Map.GetItems(itemtype, true)[0];
                    tasks.Add(Follow(player, item));
                }
            }
            tasks.ForEach(x => x.GetAwaiter());
            HuntersWait().GetAwaiter();
        }
예제 #5
0
        public override void EventStart(RoundStartEvent ev)
        {
            if (!isQueue)
            {
                return;
            }
            //Initializing
            alives.Clear();
            Player[] players = ev.Server.GetPlayers().ToArray();
            if (players.Length < 3)
            {
                ev.Server.Map.Broadcast(10, Translation["not_enought_players"], false);
                return;
            }
            ev.Server.GetPlayers().Clear();
            List <int> terrorists = new List <int>();
            List <int> detectives = new List <int>();

            players.ToList().ForEach(x => x.SetRank(text: ""));
            //Setting players
            for (int i = -1; i < players.Length / 10; i++)
            {
                while (true)
                {
                    int temp = random.Next(0, players.Length - 1);
                    if (!terrorists.Contains(temp))
                    {
                        terrorists.Add(temp);
                        break;
                    }
                }
            }
            for (int i = 0; i <= players.Length / 20; i++)
            {
                while (true)
                {
                    int temp = random.Next(0, players.Length - 1);
                    if (!terrorists.Contains(temp))
                    {
                        detectives.Add(temp);
                        break;
                    }
                }
            }
            List <Smod2.API.Door> doors = ev.Server.Map.GetDoors();

            doors.Find(x => x.Name == "CHECKPOINT_LCZ_A").Locked = true;
            doors.Find(x => x.Name == "CHECKPOINT_LCZ_B").Locked = true;
            //Spawning Weapons
            foreach (Smod2.API.Door door in doors)
            {
                Vector vec = door.Position;
                int    rng = random.Next(0, 4);
                for (int i = 0; i < rng; i++)
                {
                    int    x         = random.Next(Convert.ToInt32(vec.x - 15f), Convert.ToInt32(vec.x + 15f));
                    int    z         = random.Next(Convert.ToInt32(vec.z - 15f), Convert.ToInt32(vec.z + 15f));
                    int    y         = Convert.ToInt32(vec.y + 1);
                    Vector spanw_pos = new Vector(x, y, z);

                    Array values            = Enum.GetValues(typeof(WeaponTypeGame));
                    Smod2.API.ItemType item = (Smod2.API.ItemType)values.GetValue(random.Next(values.Length));
                    ev.Server.Map.SpawnItem(item, spanw_pos, Vector.Zero);
                }
            }
            Smod2.API.Door[]      avalible_doors = doors.Where(door => !(door.Position.y > 20f || door.Name == "372" || door.Name == "CHECKPOINT_LCZ_A" || door.Name == "CHECKPOINT_LCZ_B")).OrderBy(x => random.Next()).ToArray();
            List <Smod2.API.Door> taked_doors    = new List <Smod2.API.Door>();
            //Setting players posisions
            int index = 0;

            foreach (Player player in players)
            {
                if (terrorists.Contains(index))
                {
                    alives.Add(new Alives(player, Klasy.ZDRAJCA, Translation));
                }
                else if (detectives.Contains(index))
                {
                    alives.Add(new Alives(player, Klasy.DETEKTYW, Translation));
                }
                else
                {
                    alives.Add(new Alives(player, Klasy.NIEWINNY, Translation));
                }
                index++;
            }
            //Addons
            List <Alives> terro = alives.FindAll(x => x.Rola == Klasy.ZDRAJCA);

            terro.ForEach(x => x.SetFriends(terro.Where(y => y != x)));
            //Disposing
            doors          = null;
            terro          = null;
            terrorists     = null;
            avalible_doors = null;
            taked_doors    = null;
        }
예제 #6
0
        /// <summary>
        /// Does a full 914 pass on the user's held item.
        /// </summary>
        /// <param name="collider">Player</param>
        /// <param name="OutputPos">Smod2 Vector on the output of 914</param>
        /// <param name="knobSetting">Current 914 knob setting</param>
        /// <param name="scp914">914</param>
        public void DoHand914(UnityEngine.Collider collider, Vector OutputPos, KnobSetting knobSetting, Scp914 scp914)
        {
            Smod2.API.Player play = new ServerMod2.API.SmodPlayer(collider.gameObject);

            if (play.GetCurrentItem() == null || play.GetCurrentItemIndex() == -1 || play.GetCurrentItem().ItemType == ItemType.USP || stackManager.ContainsWeapon((int)play.GetCurrentItem().ItemType) && knobSetting == KnobSetting.ONE_TO_ONE)
            {
                StackEventHandler.CheckSteamIDItemNum[play.SteamId].TransferItems(collider.gameObject);
                StackEventHandler.CheckSteamIDItemNum[play.SteamId].ApplyTransferedItems(collider.gameObject, true);
                return;
            }
            Smod2.API.ItemType currentItem = play.GetCurrentItem().ItemType;
            int itemIndex = -1;

            Dictionary <int, List <Inventory.SyncItemInfo> > TempGetItemsByItemType = new Dictionary <int, List <Inventory.SyncItemInfo> >();       //This is for seeing a item's index in inventory

            foreach (var item in collider.gameObject.GetComponent <Inventory>().items)
            {
                if (TempGetItemsByItemType.ContainsKey(item.id))
                {
                    TempGetItemsByItemType[item.id].Add(item);
                    if (item.uniq == collider.gameObject.GetComponent <Inventory>().GetItemInHand().uniq)
                    {
                        itemIndex = TempGetItemsByItemType[item.id].IndexOf(item) + 1;
                    }
                }
                else
                {
                    TempGetItemsByItemType.Add(item.id, new List <Inventory.SyncItemInfo> {
                        item
                    });
                    if (item.uniq == collider.gameObject.GetComponent <Inventory>().GetItemInHand().uniq)
                    {
                        itemIndex = TempGetItemsByItemType[item.id].IndexOf(item) + 1;
                    }
                }
            }
            play.GetCurrentItem().Remove();
            int AmountOfItems = -1;

            if (TempGetItemsByItemType[(int)currentItem].Count == itemIndex)
            {
                AmountOfItems = (int)Math.Ceiling(StackEventHandler.CheckSteamIDItemNum[play.SteamId].GetItemAmount((int)currentItem) % (float)stackManager.GetStackSize((int)currentItem));
                if (AmountOfItems == 0)
                {
                    AmountOfItems = stackManager.GetStackSize((int)currentItem);
                }
            }
            else
            {
                AmountOfItems = stackManager.GetStackSize((int)currentItem);
            }

            if (stackManager.GetStackSize((int)currentItem) == 1)
            {
                AmountOfItems = 1;
            }

            StackEventHandler.CheckSteamIDItemNum[play.SteamId].AddItemAmount((int)currentItem, AmountOfItems * -1);

            for (int i = 0; i < AmountOfItems; i++)
            {
                int newitem = GetRandom914ItemByKnob(scp914, (int)currentItem, (int)knobSetting);
                if (newitem != -1 || ConfigOptions.si_914itemstosave.Contains(newitem))
                {
                    if (play.GetInventory().Count == 8)
                    {
                        Smod2.PluginManager.Manager.Server.Map.SpawnItem((ItemType)newitem, OutputPos, new Vector(0, 0, 0));
                    }
                    else
                    {
                        StackEventHandler.CheckSteamIDItemNum[play.SteamId].AddItemAmount(newitem, 1);
                    }
                }
            }

            StackEventHandler.CheckSteamIDItemNum[play.SteamId].TransferItems(collider.gameObject);
            StackEventHandler.CheckSteamIDItemNum[play.SteamId].ApplyTransferedItems(collider.gameObject, true);
        }