1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using UnityEngine;
|
---|
4 |
|
---|
5 | namespace AllocsFixes.CustomCommands
|
---|
6 | {
|
---|
7 | public class Give : ConsoleCmdAbstract
|
---|
8 | {
|
---|
9 | public override string GetDescription ()
|
---|
10 | {
|
---|
11 | return "give an item to a player (entity id or name)";
|
---|
12 | }
|
---|
13 |
|
---|
14 | public override string[] GetCommands ()
|
---|
15 | {
|
---|
16 | return new string[] { "give", string.Empty };
|
---|
17 | }
|
---|
18 |
|
---|
19 | public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
|
---|
20 | {
|
---|
21 | try {
|
---|
22 | if (_params.Count != 3) {
|
---|
23 | SdtdConsole.Instance.Output ("Usage: give <playername|entityid> <itemname> <amount>");
|
---|
24 | return;
|
---|
25 | }
|
---|
26 |
|
---|
27 | ClientInfo ci = ConsoleHelper.ParseParamIdOrName (_params [0]);
|
---|
28 |
|
---|
29 | if (ci == null) {
|
---|
30 | SdtdConsole.Instance.Output ("Playername or entity id not found.");
|
---|
31 | return;
|
---|
32 | }
|
---|
33 |
|
---|
34 | ItemValue iv = ItemList.Instance.GetItemValue (_params[1]);
|
---|
35 | if (iv == null) {
|
---|
36 | SdtdConsole.Instance.Output ("Item not found.");
|
---|
37 | return;
|
---|
38 | }
|
---|
39 |
|
---|
40 | int n = int.MinValue;
|
---|
41 | if (!int.TryParse (_params [2], out n) || n <= 0) {
|
---|
42 | SdtdConsole.Instance.Output ("Amount is not an integer or not greater than zero.");
|
---|
43 | return;
|
---|
44 | }
|
---|
45 |
|
---|
46 | EntityPlayer p = GameManager.Instance.World.Players.dict [ci.entityId];
|
---|
47 |
|
---|
48 | InventoryField invField = new InventoryField (iv, n);
|
---|
49 |
|
---|
50 | GameManager.Instance.ItemDropServer (invField, p.GetPosition (), Vector3.zero, -1, 50);
|
---|
51 |
|
---|
52 | SdtdConsole.Instance.Output ("Dropped item");
|
---|
53 | } catch (Exception e) {
|
---|
54 | Log.Out ("Error in Give.Run: " + e);
|
---|
55 | }
|
---|
56 | }
|
---|
57 | }
|
---|
58 | }
|
---|