Example #1
0
        private void OnObjectDeploy(NetworkInstantiateEvent e)
        {
            Player player = Server.GetPlayerById(e.SenderId);

            if (!player.HasPermission("admin"))
            {
                return;
            }
            if (player == null)
            {
                return;
            }
            InvItemBlueprint bp = InvDefinitions.Instance.Blueprints.GetBlueprintForID(e.BlueprintId);

            PrintToChat(player, "You have placed a " + bp.Name + ".");
            if (bp.Name.Contains("Crest"))
            {
                MessWithTheCrest(e, player);
            }
        }
Example #2
0
        void SpawnSingleCreatureAroundEveryPlayer(Vector3 RandomToSurfacePosition, Player player, string zw)
        {
            NetworkInstantiationArgs newNetInstArgs = new NetworkInstantiationArgs();

            newNetInstArgs.Information   = InformationType.Prefab;
            newNetInstArgs.NetworkAware  = true;
            newNetInstArgs.OwnerId       = Server.GetPlayerByName("Server").Id;
            newNetInstArgs.SocialOwnerId = 0;
            InvItemBlueprint[] lala = new InvItemBlueprint[InvDefinitions.Instance.Blueprints.AllDefinedBlueprints.Count()];
            lala = InvDefinitions.Instance.Blueprints.AllDefinedBlueprints;
            InvItemBlueprint bptouse = new InvItemBlueprint();

            foreach (var blueprint in lala)
            {
                if (!blueprint.Name.ToLower().Contains(zw))
                {
                    continue;
                }
                bptouse = blueprint;
            }
            CustomNetworkInstantiate.Instantiate(bptouse, RandomToSurfacePosition, player.Entity.Rotation, newNetInstArgs);
        }
Example #3
0
        private object GiveItem(IPlayer target, string itemNameOrId, int amount = 1, string container = "main")
        {
            if (config.ItemBlacklist.Contains(itemNameOrId.ToLower()))
            {
                return(null);
            }

            string itemName = itemNameOrId;

#if HURTWORLDITEMV2
            PlayerSession      session   = target.Object as PlayerSession;
            PlayerInventory    inventory = session.WorldPlayerEntity.GetComponent <PlayerInventory>();
            ItemGeneratorAsset generator = FindItem(itemNameOrId);

            ItemObject itemObj;
            if (generator.IsStackable())
            {
                itemObj = GlobalItemManager.Instance.CreateItem(generator, amount);
                if (!inventory.GiveItemServer(itemObj))
                {
                    GlobalItemManager.SpawnWorldItem(itemObj, inventory);
                }
            }
            else
            {
                int amountGiven = 0;
                while (amountGiven < amount)
                {
                    itemObj = GlobalItemManager.Instance.CreateItem(generator);
                    if (!inventory.GiveItemServer(itemObj))
                    {
                        GlobalItemManager.SpawnWorldItem(itemObj, inventory);
                    }
                    amountGiven++;
                }
            }
#elif HURTWORLD
            PlayerSession   session   = target.Object as PlayerSession;
            PlayerInventory inventory = session.WorldPlayerEntity.GetComponent <PlayerInventory>();
            GlobalItemManager.Instance.GiveItem(session.Player, FindItem(itemNameOrId), amount);
#elif REIGNOFKINGS
            Player player = target.Object as Player;
            if (player == null)
            {
                return(false);
            }

            Container itemContainer = null;
            switch (container.ToLower())
            {
            case "belt":
                itemContainer = player.CurrentCharacter.Entity.GetContainerOfType(CollectionTypes.Hotbar);
                break;

            case "main":
                itemContainer = player.CurrentCharacter.Entity.GetContainerOfType(CollectionTypes.Inventory);
                break;
            }

            InvItemBlueprint blueprint = InvDefinitions.Instance.Blueprints.GetBlueprintForName(itemName, true, true);
            if (blueprint == null)
            {
                return(false);
            }

            ContainerManagement containerManagement = blueprint.TryGet <ContainerManagement>();
            int stackableAmount = containerManagement != null ? containerManagement.StackLimit : 0;
            int amountGiven     = 0;
            while (amountGiven < amount)
            {
                int amountToGive           = Mathf.Min(stackableAmount, amount - amountGiven);
                InvGameItemStack itemStack = new InvGameItemStack(blueprint, amountToGive, null);
                if (!ItemCollection.AutoMergeAdd(itemContainer.Contents, itemStack))
                {
                    int stackAmount = amountToGive - itemStack.StackAmount;
                    if (stackAmount != 0)
                    {
                        amountGiven += stackAmount;
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    amountGiven += amountToGive;
                }
                if (itemContainer.Contents.FreeSlotCount == 0)
                {
                    break;
                }
            }
#elif RUST
            Item item = ItemManager.Create(FindItem(itemNameOrId));
            if (item == null)
            {
                return(false);
            }

            item.amount = amount;

            BasePlayer basePlayer = target.Object as BasePlayer;
            if (basePlayer == null)
            {
                return(false);
            }

            ItemContainer itemContainer = null;
            switch (container.ToLower())
            {
            case "belt":
                itemContainer = basePlayer.inventory.containerBelt;
                break;

            case "main":
                itemContainer = basePlayer.inventory.containerMain;
                break;
            }

            if (!basePlayer.inventory.GiveItem(item, itemContainer))
            {
                item.Remove();
                return(false);
            }

            itemName = item.info.displayName.english;

            if (config.ShowPopupNotices)
            {
                target.Command("note.inv", item.info.itemid, amount);
                target.Command("gametip.showgametip", Lang("ItemReceived", target.Id, itemName, amount));
                timer.Once(2f, () => target.Command("gametip.hidegametip"));
            }
#endif
            if (config.ShowChatNotices)
            {
                Message(target, "ItemReceived", itemName, amount);
            }

            if (config.LogToConsole)
            {
                Log($"{target.Name} {amount} x {itemName}");
            }

            return(true);
        }