public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry) { PlayerTag player = PlayerTag.For(entry.GetArgument(queue, 0)); if (player == null) { queue.HandleError(entry, "Invalid player!"); return; } ItemAssetTag item = ItemAssetTag.For(entry.GetArgument(queue, 1)); if (item == null) { queue.HandleError(entry, "Invalid item!"); return; } byte amount = 1; if (entry.Arguments.Count > 2) { amount = (byte)Utilities.StringToUInt(entry.GetArgument(queue, 2)); } if (ItemTool.tryForceGiveItem(player.Internal.player, item.Internal.id, amount)) { if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully gave a " + TagParser.Escape(item.Internal.name) + "!"); } } else { queue.HandleError(entry, "Failed to give item (is the inventory full?)!"); } }
private void OnConsumePerformed(Player instigatingPlayer, ItemConsumeableAsset consumeableAsset) { foreach (var leftover in Configuration.Instance.Leftovers.Where(x => x.Id == consumeableAsset.id)) { ItemTool.tryForceGiveItem(instigatingPlayer, leftover.LeftoverId, 1); } }
public override void Execute(PointBlankPlayer executor, string[] args) { ItemAsset item; if (!ushort.TryParse(args[0], out ushort id)) { ItemAsset[] items = Assets.find(EAssetType.ITEM) as ItemAsset[]; item = items.Where(a => a != null).OrderBy(a => a.itemName.Length).FirstOrDefault(a => a.itemName.ToLower().Contains(args[0].ToLower())); } else { item = Assets.find(EAssetType.ITEM, id) as ItemAsset; } if (item == null) { UnturnedChat.SendMessage(executor, Translations["Item_Invalid"], ConsoleColor.Red); return; } if (args.Length < 2 || !byte.TryParse(args[1], out byte amount)) { amount = 1; } if (args.Length < 3 || UnturnedPlayer.TryGetPlayer(args[2], out UnturnedPlayer ply)) { if (executor == null) { UnturnedChat.SendMessage(executor, Translations["Base_InvalidPlayer"], ConsoleColor.Red); return; } ply = (UnturnedPlayer)executor; } if (!ItemTool.tryForceGiveItem(ply.Player, item.id, amount)) { UnturnedChat.SendMessage(executor, Translations["Item_Fail"], ConsoleColor.Red); return; } UnturnedChat.SendMessage(executor, string.Format(Translations["Item_Give"], item.itemName, ply.PlayerName), ConsoleColor.Green); }
protected override async Task OnExecuteAsync() { var amount = (byte)1; if (Context.Parameters.Length > 0) { amount = await Context.Parameters.GetAsync <byte>(0); } var unturnedUser = Context.Actor as UnturnedUser; // ReSharper disable once PossibleNullReferenceException var equipmentI = unturnedUser.Player.equipment; if (equipmentI.itemID == 0) { throw new UserFriendlyException(m_StringLocalizer["ldm_cmds:fail:not_equipped"]); } await UniTask.SwitchToMainThread(); ItemTool.tryForceGiveItem(unturnedUser.Player, equipmentI.itemID, amount); await PrintAsync(m_StringLocalizer["ldm_cmds:success:more", amount, equipmentI.asset.itemName]); }
public bool GiveItem(ushort itemId, byte amount) { return(ItemTool.tryForceGiveItem(player, itemId, amount)); }
public bool Give(ushort id, byte amount) { return(ItemTool.tryForceGiveItem(Player, id, amount)); }
public bool GiveItem(ushort itemId, byte amount) => ItemTool.tryForceGiveItem(NativePlayer, itemId, amount);