source: binary-improvements2/AllocsCommands/Commands/Give.cs@ 383

Last change on this file since 383 was 383, checked in by alloc, 2 years ago

Fixed a bunch of warnings

File size: 2.6 KB
RevLine 
[224]1using System.Collections.Generic;
2using UnityEngine;
3
[325]4namespace AllocsFixes.CustomCommands {
[250]5 public class Give : ConsoleCmdAbstract {
6 public override string GetDescription () {
[224]7 return "give an item to a player (entity id or name)";
8 }
9
[238]10 public override string GetHelp () {
11 return "Give an item to a player by dropping it in front of that player\n" +
[325]12 "Usage:\n" +
13 " give <name / entity id> <item name> <amount>\n" +
14 " give <name / entity id> <item name> <amount> <quality>\n" +
15 "Either pass the full name of a player or his entity id (given by e.g. \"lpi\").\n" +
16 "Item name has to be the exact name of an item as listed by \"listitems\".\n" +
17 "Amount is the number of instances of this item to drop (as a single stack).\n" +
18 "Quality is the quality of the dropped items for items that have a quality.";
[238]19 }
20
[250]21 public override string[] GetCommands () {
[325]22 return new[] {"give", string.Empty};
[224]23 }
24
[250]25 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
[359]26 if (_params.Count != 3 && _params.Count != 4) {
27 SdtdConsole.Instance.Output ("Wrong number of arguments, expected 3 or 4, found " + _params.Count +
28 ".");
29 return;
30 }
[224]31
[359]32 ClientInfo ci = ConsoleHelper.ParseParamIdOrName (_params [0]);
[224]33
[359]34 if (ci == null) {
35 SdtdConsole.Instance.Output ("Playername or entity id not found.");
36 return;
37 }
[224]38
[359]39 ItemValue iv = ItemClass.GetItem (_params [1], true);
40 if (iv.type == ItemValue.None.type) {
41 SdtdConsole.Instance.Output ("Item not found.");
42 return;
43 }
[224]44
[359]45 iv = new ItemValue (iv.type, true);
[306]46
[359]47 int n;
48 if (!int.TryParse (_params [2], out n) || n <= 0) {
49 SdtdConsole.Instance.Output ("Amount is not an integer or not greater than zero.");
50 return;
51 }
[224]52
[359]53 int quality = Constants.cItemMaxQuality;
[324]54
[359]55 if (_params.Count == 4) {
56 if (!int.TryParse (_params [3], out quality) || quality <= 0) {
57 SdtdConsole.Instance.Output ("Quality is not an integer or not greater than zero.");
58 return;
[324]59 }
[359]60 }
[250]61
[359]62 if (ItemClass.list [iv.type].HasSubItems) {
63 for (int i = 0; i < iv.Modifications.Length; i++) {
64 ItemValue tmp = iv.Modifications [i];
65 tmp.Quality = quality;
66 iv.Modifications [i] = tmp;
[250]67 }
[359]68 } else if (ItemClass.list [iv.type].HasQuality) {
69 iv.Quality = quality;
70 }
[250]71
[359]72 EntityPlayer p = GameManager.Instance.World.Players.dict [ci.entityId];
[224]73
[359]74 ItemStack invField = new ItemStack (iv, n);
[224]75
[359]76 GameManager.Instance.ItemDropServer (invField, p.GetPosition (), Vector3.zero);
[224]77
[359]78 SdtdConsole.Instance.Output ("Dropped item");
[224]79 }
80 }
[325]81}
Note: See TracBrowser for help on using the repository browser.