예제 #1
0
        public void OnExecute(IPlayer caller, params string[] args)
        {
            var player = (BasePlayer)caller;

            switch (args.Length)
            {
            case 1:
                VehicleAsset asset;
                if (ushort.TryParse(args[0], out var vehicle))
                {
                    asset = ItemUtil.FindAsset <VehicleAsset>(vehicle, EAssetType.VEHICLE);

                    if (ItemUtil.IsBlocked(vehicle, EAssetType.VEHICLE) && !caller.HasPermission("*"))
                    {
                        UnturnedChatManager.Puts(caller, CoreManager.Translations.Instance.Translate("item_blocked"), Color.red);
                        return;
                    }

                    if (!player.GiveVehicle(vehicle))
                    {
                        UnturnedChatManager.Puts(caller, CoreManager.Translations.Instance.Translate("vehicle_null"), Color.red);
                        return;
                    }

                    UnturnedChatManager.Puts(caller, CoreManager.Translations.Instance.Translate("vehicle_give", $"{asset.id}({asset.vehicleName})"), Color.cyan);
                    return;
                }

                asset = ItemUtil.FindAsset <VehicleAsset>(args[0], EAssetType.VEHICLE);

                if (asset == null)
                {
                    UnturnedChatManager.Puts(caller, CoreManager.Translations.Instance.Translate("vehicle_null"), Color.red);
                    return;
                }

                if (ItemUtil.IsBlocked(asset.id, EAssetType.VEHICLE) && !caller.HasPermission("*"))
                {
                    UnturnedChatManager.Puts(caller, CoreManager.Translations.Instance.Translate("item_blocked"), Color.red);
                    return;
                }

                player.GiveVehicle(asset.id);
                UnturnedChatManager.Puts(caller, CoreManager.Translations.Instance.Translate("vehicle_give", $"{asset.id}({asset.vehicleName})"), Color.cyan);
                break;

            default:
                UnturnedChatManager.Puts(caller, "Команда введена неверно, используйте /V [ID]", Color.red);
                break;
            }
        }
예제 #2
0
        public void OnExecute(IPlayer caller, params string[] args)
        {
            var player = (BasePlayer)caller;

            if (!args.IsValid(1, false))
            {
                UnturnedChatManager.Puts(caller, "Команда введена неверно, используйте /i [ID] [Amount]", Color.red);
                return;
            }

            var asset = ushort.TryParse(args[0], out var item) ? ItemUtil.FindAsset <ItemAsset>(item, EAssetType.ITEM) : ItemUtil.FindAsset <ItemAsset>(args[0], EAssetType.ITEM);

            if (asset == null)
            {
                UnturnedChatManager.Puts(caller, CoreManager.Translations.Instance.Translate("item_null"), Color.red);
                return;
            }

            if (ItemUtil.IsBlocked(asset.id, EAssetType.ITEM) && !caller.HasPermission("*"))
            {
                UnturnedChatManager.Puts(caller, CoreManager.Translations.Instance.Translate("item_blocked"), Color.red);
                return;
            }

            switch (args.Length)
            {
            case 1:
                player.Give(asset.id, 1);
                UnturnedChatManager.Puts(caller, CoreManager.Translations.Instance.Translate("item_give", 1, $"{asset.id}({asset.itemName})"), Color.cyan);
                break;

            case 2:
                if (!byte.TryParse(args[1], out var amount))
                {
                    UnturnedChatManager.Puts(caller, "Команда введена неверно, используйте /i [ID] [Amount]", Color.red);
                    return;
                }

                player.Give(asset.id, amount);
                UnturnedChatManager.Puts(caller, CoreManager.Translations.Instance.Translate("item_give", amount, $"{asset.id}({asset.itemName})"), Color.cyan);
                break;
            }
        }