[224] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using UnityEngine;
|
---|
| 4 |
|
---|
| 5 | namespace AllocsFixes.CustomCommands
|
---|
| 6 | {
|
---|
[250] | 7 | public class Give : ConsoleCmdAbstract {
|
---|
| 8 | public override string GetDescription () {
|
---|
[224] | 9 | return "give an item to a player (entity id or name)";
|
---|
| 10 | }
|
---|
| 11 |
|
---|
[238] | 12 | public override string GetHelp () {
|
---|
| 13 | return "Give an item to a player by dropping it in front of that player\n" +
|
---|
[250] | 14 | "Usage:\n" +
|
---|
| 15 | " give <name / entity id> <item name> <amount>\n" +
|
---|
| 16 | " give <name / entity id> <item name> <amount> <quality>\n" +
|
---|
| 17 | "Either pass the full name of a player or his entity id (given by e.g. \"lpi\").\n" +
|
---|
| 18 | "Item name has to be the exact name of an item as listed by \"listitems\".\n" +
|
---|
| 19 | "Amount is the number of instances of this item to drop (as a single stack).\n" +
|
---|
| 20 | "Quality is the quality of the dropped items for items that have a quality.";
|
---|
[238] | 21 | }
|
---|
| 22 |
|
---|
[250] | 23 | public override string[] GetCommands () {
|
---|
[224] | 24 | return new string[] { "give", string.Empty };
|
---|
| 25 | }
|
---|
| 26 |
|
---|
[250] | 27 | public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
|
---|
[224] | 28 | try {
|
---|
[250] | 29 | if (_params.Count != 3 && _params.Count != 4) {
|
---|
| 30 | SdtdConsole.Instance.Output ("Wrong number of arguments, expected 3 or 4, found " + _params.Count + ".");
|
---|
[224] | 31 | return;
|
---|
| 32 | }
|
---|
| 33 |
|
---|
[230] | 34 | ClientInfo ci = ConsoleHelper.ParseParamIdOrName (_params [0]);
|
---|
[224] | 35 |
|
---|
| 36 | if (ci == null) {
|
---|
[230] | 37 | SdtdConsole.Instance.Output ("Playername or entity id not found.");
|
---|
[224] | 38 | return;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
[306] | 41 | ItemValue iv = ItemClass.GetItem (_params [1], true);
|
---|
| 42 | if (iv.type == ItemValue.None.type) {
|
---|
[230] | 43 | SdtdConsole.Instance.Output ("Item not found.");
|
---|
[224] | 44 | return;
|
---|
| 45 | }
|
---|
| 46 |
|
---|
[306] | 47 | iv = new ItemValue (iv.type, true);
|
---|
| 48 |
|
---|
[224] | 49 | int n = int.MinValue;
|
---|
| 50 | if (!int.TryParse (_params [2], out n) || n <= 0) {
|
---|
[230] | 51 | SdtdConsole.Instance.Output ("Amount is not an integer or not greater than zero.");
|
---|
[224] | 52 | return;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
[250] | 55 | if (_params.Count == 4) {
|
---|
[290] | 56 | if (!iv.HasQuality && iv.Attachments == null && iv.Parts == null) {
|
---|
[250] | 57 | SdtdConsole.Instance.Output ("Item " + _params [1] + " does not support quality.");
|
---|
| 58 | return;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | int quality = int.MinValue;
|
---|
| 62 | if (!int.TryParse (_params [3], out quality) || quality <= 0) {
|
---|
| 63 | SdtdConsole.Instance.Output ("Quality is not an integer or not greater than zero.");
|
---|
| 64 | return;
|
---|
| 65 | }
|
---|
| 66 | iv.Quality = quality;
|
---|
[290] | 67 |
|
---|
| 68 | // Specific code for weapons with parts and attachmetns
|
---|
| 69 | if (iv.Attachments != null && iv.Attachments.Length != 0) {
|
---|
| 70 | for (int i = 0; i < iv.Attachments.Length; i++) {
|
---|
| 71 | ItemValue att = iv.Attachments[i];
|
---|
[299] | 72 | if (att != null && att.HasQuality) {
|
---|
[290] | 73 | att.Quality = quality;
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | if (iv.Parts != null && iv.Parts.Length != 0) {
|
---|
| 79 | for (int i = 0; i < iv.Parts.Length; i++) {
|
---|
| 80 | ItemValue part = iv.Parts[i];
|
---|
[299] | 81 | if (part != null && part.HasQuality) {
|
---|
[290] | 82 | part.Quality = quality;
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
[250] | 86 | }
|
---|
| 87 |
|
---|
[230] | 88 | EntityPlayer p = GameManager.Instance.World.Players.dict [ci.entityId];
|
---|
[224] | 89 |
|
---|
[238] | 90 | ItemStack invField = new ItemStack (iv, n);
|
---|
[224] | 91 |
|
---|
[306] | 92 | GameManager.Instance.ItemDropServer (invField, p.GetPosition (), Vector3.zero);
|
---|
[224] | 93 |
|
---|
[230] | 94 | SdtdConsole.Instance.Output ("Dropped item");
|
---|
[224] | 95 | } catch (Exception e) {
|
---|
| 96 | Log.Out ("Error in Give.Run: " + e);
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
| 100 | }
|
---|