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